-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add SFC V2 cloud provider integration (#116) #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
drewmalin
wants to merge
7
commits into
main
Choose a base branch
from
sfcv2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
109a19b
feat: add SFC V2 cloud provider integration (#116)
andreaanez 8fb2b63
use v2 sfc
drewmalin 02f1d50
use capacity ID
drewmalin 62c1b5d
update tests to use env var
drewmalin caa7140
add sfcompute_workspace envvar
drewmalin eb427e9
organization
drewmalin e250e16
lint
drewmalin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package v2 | ||
|
|
||
| import "fmt" | ||
|
|
||
| // Package-internal constants — SSH defaults and internal tag keys. | ||
| const ( | ||
| defaultPort = 22 | ||
| defaultSSHUsername = "ubuntu" | ||
|
|
||
| // Internal tag keys written to every SFCompute V2 instance. These are stripped from | ||
| // v1.Instance.Tags on read so they don't surface as user-facing tags. | ||
| tagKeyCloudCredRefID = "brev-cloud-cred-ref-id" //nolint:gosec // not a secret | ||
| tagKeyRefID = "brev-ref-id" | ||
|
|
||
| // Brev environment config for SFCompute V2. | ||
| brevDefaultImageResourcePath = "sfc:image:sfcompute:public:ubuntu-24.04.4-cuda-12.8" | ||
| ) | ||
|
|
||
| func (c *SFCClientV2) GetDefaultCapacityResourcePath() string { | ||
| return fmt.Sprintf("sfc:capacity:%s:%s:brev-default-capacity", c.organization, c.workspace) | ||
| } | ||
|
|
||
| func (c *SFCClientV2) GetWorkspaceResourcePath() string { | ||
| return fmt.Sprintf("sfc:workspace:%s:%s", c.organization, c.workspace) | ||
| } | ||
|
|
||
| func (c *SFCClientV2) GetDefaultImageResourcePath() string { | ||
| return brevDefaultImageResourcePath | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package v2 | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| v1 "github.com/brevdev/cloud/v1" | ||
| ) | ||
|
|
||
| func getSFCCapabilitiesV2() v1.Capabilities { | ||
| return v1.Capabilities{ | ||
| v1.CapabilityCreateInstance, | ||
| v1.CapabilityTerminateInstance, | ||
| v1.CapabilityCreateTerminateInstance, | ||
| v1.CapabilityTags, | ||
| } | ||
| } | ||
|
|
||
| func (c *SFCClientV2) GetCapabilities(_ context.Context) (v1.Capabilities, error) { | ||
| return getSFCCapabilitiesV2(), nil | ||
| } | ||
|
|
||
| func (c *SFCCredentialV2) GetCapabilities(_ context.Context) (v1.Capabilities, error) { | ||
| return getSFCCapabilitiesV2(), nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| package v2 | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| v1 "github.com/brevdev/cloud/v1" | ||
| sfc "github.com/sfcompute/sfc-go" | ||
| ) | ||
|
|
||
| const CloudProviderID = "sfcompute" | ||
|
|
||
| // SFCCredentialV2 holds authentication details for a Brev-managed SFCompute V2 account. | ||
| type SFCCredentialV2 struct { | ||
| RefID string | ||
| APIKey string `json:"api_key"` | ||
| Organization string `json:"organization"` | ||
| Workspace string `json:"workspace"` | ||
| } | ||
|
|
||
| var _ v1.CloudCredential = &SFCCredentialV2{} | ||
|
|
||
| func NewSFCCredentialV2(refID string, apiKey string, organization string, workspace string) *SFCCredentialV2 { | ||
| return &SFCCredentialV2{ | ||
| RefID: refID, | ||
| APIKey: apiKey, | ||
| Organization: organization, | ||
| Workspace: workspace, | ||
| } | ||
| } | ||
|
|
||
| func (c *SFCCredentialV2) GetReferenceID() string { | ||
| return c.RefID | ||
| } | ||
|
|
||
| func (c *SFCCredentialV2) GetAPIType() v1.APIType { | ||
| return v1.APITypeGlobal | ||
| } | ||
|
|
||
| func (c *SFCCredentialV2) GetCloudProviderID() v1.CloudProviderID { | ||
| return CloudProviderID | ||
| } | ||
|
|
||
| func (c *SFCCredentialV2) GetTenantID() (string, error) { | ||
| return "", nil | ||
| } | ||
|
|
||
| type SFCClientV2 struct { | ||
| v1.NotImplCloudClient | ||
| refID string | ||
| organization string | ||
| workspace string | ||
| location string | ||
| client *sfc.SDK | ||
| logger v1.Logger | ||
| } | ||
|
|
||
| var _ v1.CloudClient = &SFCClientV2{} | ||
|
|
||
| type SFCClientV2Option func(c *SFCClientV2) | ||
|
|
||
| func WithLogger(logger v1.Logger) SFCClientV2Option { | ||
| return func(c *SFCClientV2) { | ||
| c.logger = logger | ||
| } | ||
| } | ||
|
|
||
| func (c *SFCCredentialV2) MakeClientWithOptions(_ context.Context, location string, opts ...SFCClientV2Option) (v1.CloudClient, error) { | ||
| sfcClient := &SFCClientV2{ | ||
| refID: c.RefID, | ||
| organization: c.Organization, | ||
| workspace: c.Workspace, | ||
| location: location, | ||
| client: sfc.New(sfc.WithSecurity(c.APIKey)), | ||
| logger: &v1.NoopLogger{}, | ||
| } | ||
|
|
||
| for _, opt := range opts { | ||
| opt(sfcClient) | ||
| } | ||
|
|
||
| return sfcClient, nil | ||
| } | ||
|
|
||
| func (c *SFCCredentialV2) MakeClient(ctx context.Context, location string) (v1.CloudClient, error) { | ||
| return c.MakeClientWithOptions(ctx, location) | ||
| } | ||
|
|
||
| func (c *SFCClientV2) GetAPIType() v1.APIType { | ||
| return v1.APITypeGlobal | ||
| } | ||
|
|
||
| func (c *SFCClientV2) GetCloudProviderID() v1.CloudProviderID { | ||
| return CloudProviderID | ||
| } | ||
|
|
||
| func (c *SFCClientV2) GetOrganization() string { | ||
| return c.organization | ||
| } | ||
|
|
||
| func (c *SFCClientV2) GetWorkspace() string { | ||
| return c.workspace | ||
| } | ||
|
|
||
| func (c *SFCClientV2) GetReferenceID() string { | ||
| return c.refID | ||
| } | ||
|
|
||
| func (c *SFCClientV2) GetTenantID() (string, error) { | ||
| return "", nil | ||
| } | ||
|
|
||
| func (c *SFCClientV2) MakeClient(_ context.Context, location string) (v1.CloudClient, error) { | ||
| c.location = location | ||
| return c, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok if this collides with the existing cloudcred?