Skip to content

Commit e9e75bd

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 SandboxInterface.Create(). 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() signature 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 592df3e commit e9e75bd

21 files changed

Lines changed: 126 additions & 87 deletions

‎sdk/go/README.md‎

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

‎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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +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-
})
20+
}))
2121
```
2222

2323
Set `GPU: true` to request the active driver's default GPU assignment. Set

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Handle missing resources gracefully:
5555
sb, err := client.Sandboxes().Get(ctx, "default", "my-sandbox")
5656
if v1.IsNotFound(err) {
5757
fmt.Println("Sandbox does not exist, creating...")
58-
sb, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
58+
sb, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
5959
}
6060
if err != nil {
6161
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/doc.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// sandbox, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{
2525
// Template: &v1.SandboxTemplate{Image: "python:3.12"},
2626
// Environment: map[string]string{"LANG": "en_US.UTF-8"},
27-
// }, nil)
27+
// })
2828
// if err != nil {
2929
// log.Fatal(err)
3030
// }
@@ -298,7 +298,7 @@
298298
// },
299299
// },
300300
// },
301-
// }, nil)
301+
// })
302302
//
303303
// Replace the full policy at runtime via configuration update:
304304
//

‎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
}

‎sdk/go/openshell/v1/example_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func ExampleClient_Sandboxes() {
2121
ctx := context.Background()
2222

2323
// Create a sandbox
24-
sb, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
24+
sb, err := client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
2525
if err != nil {
2626
log.Fatal(err)
2727
}
@@ -154,13 +154,13 @@ func ExampleIsAlreadyExists() {
154154
ctx := context.Background()
155155

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

162162
// Try to create the same sandbox again
163-
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{}, nil)
163+
_, err = client.Sandboxes().Create(ctx, "default", "my-sandbox", &v1.SandboxSpec{})
164164
if v1.IsAlreadyExists(err) {
165165
fmt.Println("Sandbox already exists")
166166
}

‎sdk/go/openshell/v1/exec_client_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (r *stubSandboxResolver) Get(_ context.Context, _, name string) (*Sandbox,
3434
return &Sandbox{ID: "sb-" + name, Name: name}, nil
3535
}
3636

37-
func (r *stubSandboxResolver) Create(context.Context, string, string, *SandboxSpec, map[string]string, ...CreateOptions) (*Sandbox, error) {
37+
func (r *stubSandboxResolver) Create(context.Context, string, string, *SandboxSpec, ...CreateOption) (*Sandbox, error) {
3838
panic("not implemented")
3939
}
4040
func (r *stubSandboxResolver) List(context.Context, string, ...ListOptions) ([]*Sandbox, error) {

0 commit comments

Comments
 (0)