Skip to content

Commit eb427e9

Browse files
committed
organization
1 parent caa7140 commit eb427e9

6 files changed

Lines changed: 50 additions & 33 deletions

File tree

.github/workflows/validation-sfcompute.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
SFCOMPUTE_API_KEY: ${{ secrets.SFCOMPUTE_API_KEY }}
4646
TEST_PRIVATE_KEY_BASE64: ${{ secrets.TEST_PRIVATE_KEY_BASE64 }}
4747
TEST_PUBLIC_KEY_BASE64: ${{ secrets.TEST_PUBLIC_KEY_BASE64 }}
48+
SFCOMPUTE_ORGANIZATION: ${{ secrets.SFCOMPUTE_ORGANIZATION }}
4849
SFCOMPUTE_WORKSPACE: ${{ secrets.SFCOMPUTE_WORKSPACE }}
4950
VALIDATION_TEST: true
5051
run: |

v1/providers/sfcomputev2/brev_constants.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ const (
1111
// v1.Instance.Tags on read so they don't surface as user-facing tags.
1212
tagKeyCloudCredRefID = "brev-cloud-cred-ref-id" //nolint:gosec // not a secret
1313
tagKeyRefID = "brev-ref-id"
14-
)
1514

16-
// Brev environment config for SFCompute V2.
17-
const (
18-
brevDefaultImageID = "sfc:image:sfcompute:public:ubuntu-24.04.4-cuda-12.8"
15+
// Brev environment config for SFCompute V2.
16+
brevDefaultImageResourcePath = "sfc:image:sfcompute:public:ubuntu-24.04.4-cuda-12.8"
1917
)
2018

21-
func GetDefaultCapacityID(workspace string) string {
22-
return fmt.Sprintf("sfc:capacity:%s:default:brev-default-capacity", workspace)
19+
func (c *SFCClientV2) GetDefaultCapacityResourcePath() string {
20+
return fmt.Sprintf("sfc:capacity:%s:%s:brev-default-capacity", c.organization, c.workspace)
21+
}
22+
23+
func (c *SFCClientV2) GetWorkspaceResourcePath() string {
24+
return fmt.Sprintf("sfc:workspace:%s:%s", c.organization, c.workspace)
2325
}
2426

25-
func GetDefaultImageID() string {
26-
return brevDefaultImageID
27+
func (c *SFCClientV2) GetDefaultImageResourcePath() string {
28+
return brevDefaultImageResourcePath
2729
}

v1/providers/sfcomputev2/client.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ const CloudProviderID = "sfcompute"
1111

1212
// SFCCredentialV2 holds authentication details for a Brev-managed SFCompute V2 account.
1313
type SFCCredentialV2 struct {
14-
RefID string
15-
APIKey string `json:"api_key"`
16-
Workspace string `json:"workspace"`
14+
RefID string
15+
APIKey string `json:"api_key"`
16+
Organization string `json:"organization"`
17+
Workspace string `json:"workspace"`
1718
}
1819

1920
var _ v1.CloudCredential = &SFCCredentialV2{}
2021

21-
func NewSFCCredentialV2(refID string, apiKey string, workspace string) *SFCCredentialV2 {
22+
func NewSFCCredentialV2(refID string, apiKey string, organization string, workspace string) *SFCCredentialV2 {
2223
return &SFCCredentialV2{
23-
RefID: refID,
24-
APIKey: apiKey,
25-
Workspace: workspace,
24+
RefID: refID,
25+
APIKey: apiKey,
26+
Organization: organization,
27+
Workspace: workspace,
2628
}
2729
}
2830

@@ -44,11 +46,12 @@ func (c *SFCCredentialV2) GetTenantID() (string, error) {
4446

4547
type SFCClientV2 struct {
4648
v1.NotImplCloudClient
47-
refID string
48-
workspace string
49-
location string
50-
client *sfc.SDK
51-
logger v1.Logger
49+
refID string
50+
organization string
51+
workspace string
52+
location string
53+
client *sfc.SDK
54+
logger v1.Logger
5255
}
5356

5457
var _ v1.CloudClient = &SFCClientV2{}
@@ -63,11 +66,12 @@ func WithLogger(logger v1.Logger) SFCClientV2Option {
6366

6467
func (c *SFCCredentialV2) MakeClientWithOptions(_ context.Context, location string, opts ...SFCClientV2Option) (v1.CloudClient, error) {
6568
sfcClient := &SFCClientV2{
66-
refID: c.RefID,
67-
workspace: c.Workspace,
68-
location: location,
69-
client: sfc.New(sfc.WithSecurity(c.APIKey)),
70-
logger: &v1.NoopLogger{},
69+
refID: c.RefID,
70+
organization: c.Organization,
71+
workspace: c.Workspace,
72+
location: location,
73+
client: sfc.New(sfc.WithSecurity(c.APIKey)),
74+
logger: &v1.NoopLogger{},
7175
}
7276

7377
for _, opt := range opts {
@@ -89,6 +93,10 @@ func (c *SFCClientV2) GetCloudProviderID() v1.CloudProviderID {
8993
return CloudProviderID
9094
}
9195

96+
func (c *SFCClientV2) GetOrganization() string {
97+
return c.organization
98+
}
99+
92100
func (c *SFCClientV2) GetWorkspace() string {
93101
return c.workspace
94102
}

v1/providers/sfcomputev2/instance.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func (c *SFCClientV2) CreateInstance(ctx context.Context, attrs v1.CreateInstanc
2929

3030
cloudInit := sshKeyCloudInit(attrs.PublicKey)
3131
resp, err := c.client.Instances.Create(ctx, components.CreateInstanceRequest{
32-
Capacity: GetDefaultCapacityID(c.workspace),
33-
Image: GetDefaultImageID(),
32+
Capacity: c.GetDefaultCapacityResourcePath(),
33+
Image: c.GetDefaultImageResourcePath(),
3434
CloudInitUserData: &cloudInit,
3535
Tags: optionalnullable.From(&tags),
3636
Name: optionalnullable.From(&attrs.Name),
@@ -95,7 +95,7 @@ func (c *SFCClientV2) ListInstances(ctx context.Context, args v1.ListInstancesAr
9595
v1.LogField("location", c.location),
9696
)
9797

98-
capacityID := GetDefaultCapacityID(c.workspace)
98+
capacityID := c.GetDefaultCapacityResourcePath()
9999
resp, err := c.client.Instances.List(ctx, operations.ListInstancesRequest{
100100
Capacity: &capacityID,
101101
})

v1/providers/sfcomputev2/instancetype.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (c *SFCClientV2) availableSlots(ctx context.Context) (int, error) {
150150
// currentCapacityAllocation returns the NodeAllocation from the most recent schedule entry
151151
// in BrevProductionCapacityID that is currently in effect (EffectiveAt <= now).
152152
func (c *SFCClientV2) currentCapacityAllocation(ctx context.Context) (int, error) {
153-
resp, err := c.client.Capacities.Fetch(ctx, GetDefaultCapacityID(c.workspace), nil, nil)
153+
resp, err := c.client.Capacities.Fetch(ctx, c.GetDefaultCapacityResourcePath(), nil, nil)
154154
if err != nil {
155155
return 0, errors.WrapAndTrace(err)
156156
}
@@ -173,9 +173,10 @@ func (c *SFCClientV2) currentCapacityAllocation(ctx context.Context) (int, error
173173
// activeInstanceCount returns the number of non-terminated instances in BrevProductionCapacityID.
174174
// All non-terminated instances occupy a slot in the capacity, including failed ones.
175175
func (c *SFCClientV2) activeInstanceCount(ctx context.Context) (int, error) {
176-
capacityID := GetDefaultCapacityID(c.workspace)
176+
capacityID := c.GetDefaultCapacityResourcePath()
177177
resp, err := c.client.Instances.List(ctx, operations.ListInstancesRequest{
178-
Capacity: &capacityID,
178+
Workspace: c.GetWorkspaceResourcePath(),
179+
Capacity: &capacityID,
179180
})
180181
if err != nil {
181182
return 0, errors.WrapAndTrace(err)

v1/providers/sfcomputev2/validation_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v2
22

33
import (
4+
"context"
45
"os"
56
"testing"
67

@@ -13,7 +14,7 @@ func TestValidationFunctions(t *testing.T) {
1314
checkSkip(t)
1415

1516
config := validation.ProviderConfig{
16-
Credential: NewSFCCredentialV2("validation-test", getAPIKey(), getWorkspace()),
17+
Credential: NewSFCCredentialV2("validation-test", getAPIKey(), getOrganization(), getWorkspace()),
1718
StableIDs: []v1.InstanceTypeID{
1819
h100InstanceTypeMetadata.instanceTypeID,
1920
},
@@ -27,7 +28,7 @@ func TestInstanceLifecycleValidation(t *testing.T) {
2728
checkSkip(t)
2829

2930
config := validation.ProviderConfig{
30-
Credential: NewSFCCredentialV2("validation-test", getAPIKey(), getWorkspace()),
31+
Credential: NewSFCCredentialV2("validation-test", getAPIKey(), getOrganization(), getWorkspace()),
3132
Location: sfcLocation,
3233
}
3334

@@ -49,6 +50,10 @@ func getAPIKey() string {
4950
return os.Getenv("SFCOMPUTE_API_KEY")
5051
}
5152

53+
func getOrganization() string {
54+
return os.Getenv("SFCOMPUTE_ORGANIZATION")
55+
}
56+
5257
func getWorkspace() string {
5358
return os.Getenv("SFCOMPUTE_WORKSPACE")
5459
}

0 commit comments

Comments
 (0)