Skip to content

Commit 32804bb

Browse files
committed
feat(sdk/go)!: replace positional labels with functional Create options
Move labels and annotations from separate parameter positions into functional options (WithLabels, WithAnnotations) on Create() and CreateFromTemplate(). Before: Create(ctx, ws, name, spec, labels, CreateOptions{Annotations: ann}) After: Create(ctx, ws, name, spec, WithLabels(labels), WithAnnotations(ann)) This unifies two resource metadata fields that were inconsistently placed (labels as positional, annotations in a struct) into a single extensible options pattern matching the existing LogOption convention. BREAKING CHANGE: Create() and CreateFromTemplate() signatures changed. All callers must use WithLabels() and WithAnnotations() functional options instead of positional labels and CreateOptions struct. Closes NVIDIA#2807 Signed-off-by: Roland Huß <[email protected]>
1 parent b2069a2 commit 32804bb

25 files changed

Lines changed: 210 additions & 128 deletions

‎docs/how-it-works/sandboxes/overview.mdx‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,13 +539,11 @@ console.log(sandbox.serviceUrls[''])
539539
540540
```go
541541
sandbox, err := client.Sandboxes().Create(
542-
ctx, "default", "app-server", spec, nil,
543-
v1.CreateOptions{ServiceExposures: []v1.ServiceExposure{
544-
{
545-
TargetPort: 4500,
546-
AuthorizationMode: v1.ServiceAuthorizationModeBearerPassthrough,
547-
},
548-
}},
542+
ctx, "default", "app-server", spec,
543+
v1.WithServiceExposures(v1.ServiceExposure{
544+
TargetPort: 4500,
545+
AuthorizationMode: v1.ServiceAuthorizationModeBearerPassthrough,
546+
}),
549547
)
550548
fmt.Println(sandbox.ServiceURLs[""])
551549
```

‎sdk/go/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ defer client.Close()
5656
// Create a sandbox and wait until it's ready
5757
sandbox, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{
5858
Template: &v1.SandboxTemplate{Image: "python:3.12"},
59-
}, nil)
59+
})
6060
if err != nil {
6161
log.Fatal(err)
6262
}

‎sdk/go/docs/src/api/fake.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestSandboxLifecycle(t *testing.T) {
1919

2020
ctx := context.Background()
2121

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

‎sdk/go/docs/src/api/sandboxes.md‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ wait for readiness, watch state changes, and retrieve logs.
77

88
## Create
99

10-
Creates a new sandbox with the given name, spec, and labels.
10+
Creates a new sandbox with the given name and spec.
1111

1212
```go
1313
sb, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{
1414
Template: &v1.SandboxTemplate{
1515
Image: "nvcr.io/nvidia/openshell:latest",
1616
},
1717
Providers: []string{"openai"},
18-
}, map[string]string{
18+
}, v1.WithLabels(map[string]string{
1919
"team": "platform",
20-
}, v1.CreateOptions{ServiceExposures: []v1.ServiceExposure{
21-
{TargetPort: 8080},
22-
}})
20+
}), v1.WithServiceExposures(v1.ServiceExposure{TargetPort: 8080}))
2321
fmt.Println(sb.ServiceURLs[""])
2422
```
2523

‎sdk/go/docs/src/error-handling.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Handle missing resources gracefully:
6262
sb, err := client.Sandboxes().Get(ctx, "default", "my-sandbox")
6363
if v1.IsNotFound(err) {
6464
fmt.Println("Sandbox does not exist, creating...")
65-
sb, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
65+
sb, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
6666
}
6767
if err != nil {
6868
log.Fatal(err)

‎sdk/go/docs/src/getting-started.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Create a sandbox with a Python image:
6868
sandbox, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{
6969
Template: &v1.SandboxTemplate{Image: "python:3.12"},
7070
Environment: map[string]string{"LANG": "en_US.UTF-8"},
71-
}, nil)
71+
})
7272
if err != nil {
7373
log.Fatal(err)
7474
}

‎sdk/go/docs/src/testing.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestMyOperator(t *testing.T) {
1818
ctx := context.Background()
1919

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

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

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

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

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

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

134134
// Drain events — channel closes after the Ready event

‎sdk/go/openshell/v1/client.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Config = types.Config
2020
type ClientInterface interface {
2121
Sandboxes() SandboxInterface
2222
SandboxTemplates() SandboxTemplateInterface
23-
CreateSandboxFromTemplate(ctx context.Context, workspace, name, templateName string, spec *SandboxSpec, labels map[string]string, opts ...CreateOptions) (*Sandbox, error)
23+
CreateSandboxFromTemplate(ctx context.Context, workspace, name, templateName string, spec *SandboxSpec, opts ...CreateOption) (*Sandbox, error)
2424
Providers() ProviderInterface
2525
Services() ServiceInterface
2626
Exec() ExecInterface
@@ -122,8 +122,8 @@ func (c *Client) SandboxTemplates() SandboxTemplateInterface { return c.template
122122

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

129129
// Providers returns the provider sub-client.

‎sdk/go/openshell/v1/doc.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// sandbox, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{
2626
// Template: &v1.SandboxTemplate{Image: "python:3.12"},
2727
// Environment: map[string]string{"LANG": "en_US.UTF-8"},
28-
// }, nil)
28+
// })
2929
// if err != nil {
3030
// log.Fatal(err)
3131
// }
@@ -320,7 +320,7 @@
320320
// },
321321
// },
322322
// },
323-
// }, nil)
323+
// })
324324
//
325325
// Replace the full policy at runtime via configuration update:
326326
//

‎sdk/go/openshell/v1/example_fake_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func ExampleNewClient_watchEvents() {
104104
defer watcher.Stop()
105105

106106
// Create triggers an ADDED event
107-
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
107+
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
108108
if err != nil {
109109
log.Fatal(err)
110110
}
@@ -135,7 +135,7 @@ func ExampleNewClient_stopOnTerminal() {
135135
}
136136

137137
// Create and transition to Ready
138-
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
138+
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
139139
if err != nil {
140140
log.Fatal(err)
141141
}

0 commit comments

Comments
 (0)