Skip to content

Commit 62c1b5d

Browse files
committed
update tests to use env var
1 parent 02f1d50 commit 62c1b5d

5 files changed

Lines changed: 43 additions & 27 deletions

File tree

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

3+
import "fmt"
4+
35
// Package-internal constants — SSH defaults and internal tag keys.
46
const (
57
defaultPort = 22
@@ -12,12 +14,14 @@ const (
1214
)
1315

1416
// Brev environment config for SFCompute V2.
15-
// TODO: source these from environment variables rather than hardcoding them here.
1617
const (
17-
// BrevDefaultCapacityID is the SFCompute V2 capacity ID for Brev production instances.
18-
BrevDefaultCapacityID = "brev-default-capacity"
19-
20-
// BrevDefaultImageID is the default SFCompute image for Brev instances
21-
// (ubuntu-24.04.4-cuda-12.8, vm_images.vm_image_id).
22-
BrevDefaultImageID = "vmi_4GwEvmclFURy7ztFQjOdr"
18+
brevDefaultImageID = "sfc:image:sfcompute:public:ubuntu-24.04.4-cuda-12.8"
2319
)
20+
21+
func GetDefaultCapacityID(workspace string) string {
22+
return fmt.Sprintf("sfc:capacity:%s:default:brev-default-capacity", workspace)
23+
}
24+
25+
func GetDefaultImageID() string {
26+
return brevDefaultImageID
27+
}

v1/providers/sfcomputev2/client.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ 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"`
14+
RefID string
15+
APIKey string `json:"api_key"`
16+
Workspace string `json:"workspace"`
1617
}
1718

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

20-
func NewSFCCredentialV2(refID, apiKey string) *SFCCredentialV2 {
21+
func NewSFCCredentialV2(refID string, apiKey string, workspace string) *SFCCredentialV2 {
2122
return &SFCCredentialV2{
22-
RefID: refID,
23-
APIKey: apiKey,
23+
RefID: refID,
24+
APIKey: apiKey,
25+
Workspace: workspace,
2426
}
2527
}
2628

@@ -42,10 +44,11 @@ func (c *SFCCredentialV2) GetTenantID() (string, error) {
4244

4345
type SFCClientV2 struct {
4446
v1.NotImplCloudClient
45-
refID string
46-
location string
47-
client *sfc.SDK
48-
logger v1.Logger
47+
refID string
48+
workspace string
49+
location string
50+
client *sfc.SDK
51+
logger v1.Logger
4952
}
5053

5154
var _ v1.CloudClient = &SFCClientV2{}
@@ -60,10 +63,11 @@ func WithLogger(logger v1.Logger) SFCClientV2Option {
6063

6164
func (c *SFCCredentialV2) MakeClientWithOptions(_ context.Context, location string, opts ...SFCClientV2Option) (v1.CloudClient, error) {
6265
sfcClient := &SFCClientV2{
63-
refID: c.RefID,
64-
location: location,
65-
client: sfc.New(sfc.WithSecurity(c.APIKey)),
66-
logger: &v1.NoopLogger{},
66+
refID: c.RefID,
67+
workspace: c.Workspace,
68+
location: location,
69+
client: sfc.New(sfc.WithSecurity(c.APIKey)),
70+
logger: &v1.NoopLogger{},
6771
}
6872

6973
for _, opt := range opts {
@@ -85,6 +89,10 @@ func (c *SFCClientV2) GetCloudProviderID() v1.CloudProviderID {
8589
return CloudProviderID
8690
}
8791

92+
func (c *SFCClientV2) GetWorkspace() string {
93+
return c.workspace
94+
}
95+
8896
func (c *SFCClientV2) GetReferenceID() string {
8997
return c.refID
9098
}

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: BrevDefaultCapacityID,
33-
Image: BrevDefaultImageID,
32+
Capacity: GetDefaultCapacityID(c.workspace),
33+
Image: GetDefaultImageID(),
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 := BrevDefaultCapacityID
98+
capacityID := GetDefaultCapacityID(c.workspace)
9999
resp, err := c.client.Instances.List(ctx, operations.ListInstancesRequest{
100100
Capacity: &capacityID,
101101
})

v1/providers/sfcomputev2/instancetype.go

Lines changed: 2 additions & 2 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, BrevDefaultCapacityID, nil, nil)
153+
resp, err := c.client.Capacities.Fetch(ctx, GetDefaultCapacityID(c.workspace), nil, nil)
154154
if err != nil {
155155
return 0, errors.WrapAndTrace(err)
156156
}
@@ -173,7 +173,7 @@ 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 := BrevDefaultCapacityID
176+
capacityID := GetDefaultCapacityID(c.workspace)
177177
resp, err := c.client.Instances.List(ctx, operations.ListInstancesRequest{
178178
Capacity: &capacityID,
179179
})

v1/providers/sfcomputev2/validation_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestValidationFunctions(t *testing.T) {
1313
checkSkip(t)
1414

1515
config := validation.ProviderConfig{
16-
Credential: NewSFCCredentialV2("validation-test", getAPIKey()),
16+
Credential: NewSFCCredentialV2("validation-test", getAPIKey(), getWorkspace()),
1717
StableIDs: []v1.InstanceTypeID{
1818
h100InstanceTypeMetadata.instanceTypeID,
1919
},
@@ -27,7 +27,7 @@ func TestInstanceLifecycleValidation(t *testing.T) {
2727
checkSkip(t)
2828

2929
config := validation.ProviderConfig{
30-
Credential: NewSFCCredentialV2("validation-test", getAPIKey()),
30+
Credential: NewSFCCredentialV2("validation-test", getAPIKey(), getWorkspace()),
3131
Location: sfcLocation,
3232
}
3333

@@ -48,3 +48,7 @@ func checkSkip(t *testing.T) {
4848
func getAPIKey() string {
4949
return os.Getenv("SFCOMPUTE_API_KEY")
5050
}
51+
52+
func getWorkspace() string {
53+
return os.Getenv("SFCOMPUTE_WORKSPACE")
54+
}

0 commit comments

Comments
 (0)