Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defer client.Close()
// Create a sandbox and wait until it's ready
sandbox, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{
Template: &v1.SandboxTemplate{Image: "python:3.12"},
}, nil)
})
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/docs/src/api/fake.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestSandboxLifecycle(t *testing.T) {

ctx := context.Background()

sb, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
sb, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
require.NoError(t, err)
assert.Equal(t, types.SandboxProvisioning, sb.Status.Phase)

Expand Down
6 changes: 3 additions & 3 deletions sdk/go/docs/src/api/sandboxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ wait for readiness, watch state changes, and retrieve logs.

## Create

Creates a new sandbox with the given name, spec, and labels.
Creates a new sandbox with the given name and spec.

```go
sb, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{
Template: &v1.SandboxTemplate{
Image: "nvcr.io/nvidia/openshell:latest",
},
Providers: []string{"openai"},
}, map[string]string{
}, v1.WithLabels(map[string]string{
"team": "platform",
})
}))
```

Set `GPU: true` to request the active driver's default GPU assignment. Set
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/docs/src/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Handle missing resources gracefully:
sb, err := client.Sandboxes().Get(ctx, "default", "my-sandbox")
if v1.IsNotFound(err) {
fmt.Println("Sandbox does not exist, creating...")
sb, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
sb, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
}
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/docs/src/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Create a sandbox with a Python image:
sandbox, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{
Template: &v1.SandboxTemplate{Image: "python:3.12"},
Environment: map[string]string{"LANG": "en_US.UTF-8"},
}, nil)
})
if err != nil {
log.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions sdk/go/docs/src/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestMyOperator(t *testing.T) {
ctx := context.Background()

// Use client exactly like the real SDK
sb, err := client.Sandboxes().Create(ctx, "default", "test-sandbox", &v1.SandboxSpec{}, nil)
sb, err := client.Sandboxes().Create(ctx, "default", "test-sandbox", &v1.SandboxSpec{})
require.NoError(t, err)
assert.Equal(t, "Provisioning", string(sb.Status.Phase))
}
Expand Down Expand Up @@ -79,7 +79,7 @@ client := fake.NewClient()
ctx := context.Background()

// Create starts in Provisioning
sb, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
sb, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
assert.Equal(t, types.SandboxProvisioning, sb.Status.Phase)

// WaitReady transitions to Ready (synchronous in fake)
Expand Down Expand Up @@ -109,7 +109,7 @@ require.NoError(t, err)
defer watcher.Stop()

// Create a sandbox — triggers an ADDED event
client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})

// Read the event from the channel
event := <-watcher.ResultChan()
Expand All @@ -128,7 +128,7 @@ watcher, err := client.Sandboxes().Watch(ctx, "default", "my-sandbox", v1.WatchO
require.NoError(t, err)

// Create and transition to Ready
client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
client.Sandboxes().WaitReady(ctx, "default", "my-sandbox")

// Drain events — channel closes after the Ready event
Expand Down
6 changes: 3 additions & 3 deletions sdk/go/openshell/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Config = types.Config
type ClientInterface interface {
Sandboxes() SandboxInterface
SandboxTemplates() SandboxTemplateInterface
CreateSandboxFromTemplate(ctx context.Context, workspace, name, templateName string, spec *SandboxSpec, labels map[string]string, opts ...CreateOptions) (*Sandbox, error)
CreateSandboxFromTemplate(ctx context.Context, workspace, name, templateName string, spec *SandboxSpec, opts ...CreateOption) (*Sandbox, error)
Providers() ProviderInterface
Services() ServiceInterface
Exec() ExecInterface
Expand Down Expand Up @@ -125,8 +125,8 @@ func (c *Client) SandboxTemplates() SandboxTemplateInterface { return c.template

// CreateSandboxFromTemplate creates a sandbox from a named workload template
// without changing the legacy Sandboxes() interface.
func (c *Client) CreateSandboxFromTemplate(ctx context.Context, workspace, name, templateName string, spec *SandboxSpec, labels map[string]string, opts ...CreateOptions) (*Sandbox, error) {
return c.templateCreate.CreateFromTemplate(ctx, workspace, name, templateName, spec, labels, opts...)
func (c *Client) CreateSandboxFromTemplate(ctx context.Context, workspace, name, templateName string, spec *SandboxSpec, opts ...CreateOption) (*Sandbox, error) {
return c.templateCreate.CreateFromTemplate(ctx, workspace, name, templateName, spec, opts...)
}

// Providers returns the provider sub-client.
Expand Down
4 changes: 2 additions & 2 deletions sdk/go/openshell/v1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// sandbox, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{
// Template: &v1.SandboxTemplate{Image: "python:3.12"},
// Environment: map[string]string{"LANG": "en_US.UTF-8"},
// }, nil)
// })
// if err != nil {
// log.Fatal(err)
// }
Expand Down Expand Up @@ -298,7 +298,7 @@
// },
// },
// },
// }, nil)
// })
//
// Replace the full policy at runtime via configuration update:
//
Expand Down
4 changes: 2 additions & 2 deletions sdk/go/openshell/v1/example_fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func ExampleNewClient_watchEvents() {
defer watcher.Stop()

// Create triggers an ADDED event
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func ExampleNewClient_stopOnTerminal() {
}

// Create and transition to Ready
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/go/openshell/v1/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ExampleClient_Sandboxes() {
ctx := context.Background()

// Create a sandbox
sb, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
sb, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -154,13 +154,13 @@ func ExampleIsAlreadyExists() {
ctx := context.Background()

// Create a sandbox
_, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
_, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
if err != nil {
log.Fatal(err)
}

// Try to create the same sandbox again
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
if v1.IsAlreadyExists(err) {
fmt.Println("Sandbox already exists")
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/openshell/v1/exec_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r *stubSandboxResolver) Get(_ context.Context, _, name string) (*Sandbox,
return &Sandbox{ID: "sb-" + name, Name: name}, nil
}

func (r *stubSandboxResolver) Create(context.Context, string, string, *SandboxSpec, map[string]string, ...CreateOptions) (*Sandbox, error) {
func (r *stubSandboxResolver) Create(context.Context, string, string, *SandboxSpec, ...CreateOption) (*Sandbox, error) {
panic("not implemented")
}
func (r *stubSandboxResolver) List(context.Context, string, ...ListOptions) ([]*Sandbox, error) {
Expand Down
4 changes: 2 additions & 2 deletions sdk/go/openshell/v1/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (fc *Client) SandboxTemplates() v1.SandboxTemplateInterface { return fc.tem

// CreateSandboxFromTemplate creates a sandbox from a named workload template
// without changing the legacy Sandboxes() interface.
func (fc *Client) CreateSandboxFromTemplate(ctx context.Context, workspace, name, templateName string, spec *types.SandboxSpec, labels map[string]string, opts ...types.CreateOptions) (*types.Sandbox, error) {
return fc.templateCreate.CreateFromTemplate(ctx, workspace, name, templateName, spec, labels, opts...)
func (fc *Client) CreateSandboxFromTemplate(ctx context.Context, workspace, name, templateName string, spec *types.SandboxSpec, opts ...types.CreateOption) (*types.Sandbox, error) {
return fc.templateCreate.CreateFromTemplate(ctx, workspace, name, templateName, spec, opts...)
}

// Providers returns the provider sub-client.
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/openshell/v1/fake/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestFakeClient_Sandboxes_AfterClose(t *testing.T) {

_ = fc.Close()

_, err := fc.Sandboxes().Create(ctx, "default", "test", &types.SandboxSpec{}, nil)
_, err := fc.Sandboxes().Create(ctx, "default", "test", &types.SandboxSpec{})
require.Error(t, err)
assert.True(t, types.IsUnavailable(err))
}
Expand Down
22 changes: 8 additions & 14 deletions sdk/go/openshell/v1/fake/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func newFakeSandboxClient(
}

// Create creates a new sandbox with Provisioning phase.
func (c *fakeSandboxClient) Create(_ context.Context, workspace, name string, spec *types.SandboxSpec, labels map[string]string, opts ...types.CreateOptions) (*types.Sandbox, error) {
func (c *fakeSandboxClient) Create(_ context.Context, workspace, name string, spec *types.SandboxSpec, opts ...types.CreateOption) (*types.Sandbox, error) {
if c.closedFunc() {
return nil, &types.StatusError{Code: types.ErrorUnavailable, Message: "client is closed"}
}
Expand All @@ -294,17 +294,14 @@ func (c *fakeSandboxClient) Create(_ context.Context, workspace, name string, sp
spec = &types.SandboxSpec{}
}

var annotations map[string]string
if len(opts) > 0 {
annotations = copyStringMap(opts[0].Annotations)
}
cfg := types.ApplyCreateOptions(opts)

sb := &types.Sandbox{
Name: name,
Workspace: workspace,
CreatedAt: time.Now(),
Labels: copyStringMap(labels),
Annotations: annotations,
Labels: copyStringMap(cfg.Labels()),
Annotations: copyStringMap(cfg.Annotations()),
ResourceVersion: 1,
Spec: copySandboxSpec(*spec),
Status: types.SandboxStatus{
Expand All @@ -327,7 +324,7 @@ func (c *fakeSandboxClient) Create(_ context.Context, workspace, name string, sp
}

// CreateFromTemplate creates a new sandbox from a named template with Provisioning phase.
func (c *fakeSandboxClient) CreateFromTemplate(_ context.Context, workspace, name, templateName string, spec *types.SandboxSpec, labels map[string]string, opts ...types.CreateOptions) (*types.Sandbox, error) {
func (c *fakeSandboxClient) CreateFromTemplate(_ context.Context, workspace, name, templateName string, spec *types.SandboxSpec, opts ...types.CreateOption) (*types.Sandbox, error) {
if c.closedFunc() {
return nil, &types.StatusError{Code: types.ErrorUnavailable, Message: "client is closed"}
}
Expand All @@ -345,10 +342,7 @@ func (c *fakeSandboxClient) CreateFromTemplate(_ context.Context, workspace, nam
spec = &types.SandboxSpec{}
}

var annotations map[string]string
if len(opts) > 0 {
annotations = copyStringMap(opts[0].Annotations)
}
cfg := types.ApplyCreateOptions(opts)

resolvedSpec := sandboxSpecFromWorkloadTemplate(template)
resolvedSpec.Providers = copyStringSlice(spec.Providers)
Expand All @@ -360,8 +354,8 @@ func (c *fakeSandboxClient) CreateFromTemplate(_ context.Context, workspace, nam
Name: name,
Workspace: workspace,
CreatedAt: time.Now(),
Labels: copyStringMap(labels),
Annotations: annotations,
Labels: copyStringMap(cfg.Labels()),
Annotations: copyStringMap(cfg.Annotations()),
ResourceVersion: 1,
Spec: resolvedSpec,
CreatedFromWorkloadTemplate: &types.SandboxWorkloadTemplateProvenance{
Expand Down
3 changes: 1 addition & 2 deletions sdk/go/openshell/v1/fake/sandbox_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestSandboxTemplate_CreateSandboxFromTemplateResolvesWorkloadAndGovernance(
Providers: []string{"github"},
Policy: policy,
},
map[string]string{"team": "runtime"},
types.WithLabels(map[string]string{"team": "runtime"}),
)

require.NoError(t, err)
Expand Down Expand Up @@ -358,7 +358,6 @@ func TestSandboxTemplate_CreateSandboxFromTemplatePreservesDefaultGPURequest(t *
"job-default-gpu",
"default-gpu",
nil,
nil,
)

require.NoError(t, err)
Expand Down
Loading
Loading