Skip to content

Commit f4dd110

Browse files
committed
feat(sdk/typescript)!: align portable resource requirements
Use the shared generated ResourceRequirements shape for reusable workload templates and update the curated exports and tests. BREAKING CHANGE: SandboxResources is no longer exported, and reusable-template CPU and memory values use typed limit objects. Part of #2838 Signed-off-by: Evan Lezar <[email protected]>
1 parent 1ef36d0 commit f4dd110

3 files changed

Lines changed: 104 additions & 9 deletions

File tree

‎sdk/typescript/src/client.test.ts‎

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,61 @@ describe('create', () => {
300300
expect(created.spec?.tty).toBe(true);
301301
});
302302

303+
it('sends portable CPU, memory, and explicit GPU requirements', async () => {
304+
let created: {
305+
spec?: {
306+
resourceRequirements?: {
307+
cpu?: { limit?: string; request?: string };
308+
memory?: { limit?: string; request?: string };
309+
gpu?: { count?: number };
310+
};
311+
};
312+
} = {};
313+
const sandbox = client({
314+
createSandbox: (req) => {
315+
created = req;
316+
return readySandbox('sb', 'sb-id');
317+
},
318+
});
319+
320+
await sandbox.create({
321+
image: 'img',
322+
resourceRequirements: {
323+
cpu: { limit: '2', request: '500m' },
324+
memory: { limit: '4Gi', request: '1Gi' },
325+
gpu: { count: 2 },
326+
},
327+
});
328+
329+
expect(created.spec?.resourceRequirements).toMatchObject({
330+
cpu: { limit: '2', request: '500m' },
331+
memory: { limit: '4Gi', request: '1Gi' },
332+
gpu: { count: 2 },
333+
});
334+
});
335+
336+
it('sends an empty GPU requirement for the driver default assignment', async () => {
337+
let created: { spec?: { resourceRequirements?: { gpu?: { count?: number } } } } = {};
338+
const sandbox = client({
339+
createSandbox: (req) => {
340+
created = req;
341+
return readySandbox('sb', 'sb-id');
342+
},
343+
});
344+
345+
await sandbox.create({ image: 'img', resourceRequirements: { gpu: {} } });
346+
347+
expect(created.spec?.resourceRequirements?.gpu).toBeDefined();
348+
expect(created.spec?.resourceRequirements?.gpu?.count).toBeUndefined();
349+
});
350+
303351
it('rawSpec reaches an ungated field and overrides a curated one', async () => {
304352
let created: {
305353
spec?: {
306354
logLevel?: string;
307355
template?: { image?: string };
308356
providers?: string[];
357+
resourceRequirements?: { cpu?: { limit?: string } };
309358
};
310359
} = {};
311360
const sandbox = client({
@@ -317,14 +366,21 @@ describe('create', () => {
317366
await sandbox.create({
318367
image: 'curated-image',
319368
providers: ['claude'],
320-
rawSpec: { logLevel: 'debug', template: { image: 'raw-image' } },
369+
resourceRequirements: { cpu: { limit: '1' } },
370+
rawSpec: {
371+
logLevel: 'debug',
372+
template: { image: 'raw-image' },
373+
resourceRequirements: { cpu: { limit: '4' } },
374+
},
321375
});
322376
// Ungated field only reachable via rawSpec.
323377
expect(created.spec?.logLevel).toBe('debug');
324378
// rawSpec wins on a field the curated shape also sets.
325379
expect(created.spec?.template?.image).toBe('raw-image');
326380
// Curated fields rawSpec does not touch survive.
327381
expect(created.spec?.providers).toEqual(['claude']);
382+
// rawSpec also wins over the curated resource requirements object.
383+
expect(created.spec?.resourceRequirements?.cpu?.limit).toBe('4');
328384
});
329385

330386
it('createFromTemplate sends the workload template name with governance fields only', async () => {
@@ -632,7 +688,11 @@ describe('sandbox templates', () => {
632688
workload?: {
633689
image?: string;
634690
environment?: Record<string, string>;
635-
resources?: { cpu?: string; memory?: string; gpu?: { count?: number } };
691+
resources?: {
692+
cpu?: { limit?: string };
693+
memory?: { limit?: string };
694+
gpu?: { count?: number };
695+
};
636696
};
637697
driverConfig?: Record<string, unknown>;
638698
};
@@ -663,7 +723,7 @@ describe('sandbox templates', () => {
663723
workload: {
664724
image: 'ghcr.io/nvidia/openshell-community/sandboxes/python:latest',
665725
environment: { FEATURE_FLAG: 'on' },
666-
resources: { cpu: '1', memory: '512Mi', gpu: { count: 1 } },
726+
resources: { cpu: { limit: '1' }, memory: { limit: '512Mi' }, gpu: { count: 1 } },
667727
},
668728
driverConfig: { kubernetes: { runtime_class_name: 'kata-containers' } },
669729
},

‎sdk/typescript/src/client.ts‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ function timestampMillis(timestamp: { seconds: bigint; nanos: number } | undefin
4949
// Generated protobuf message shapes that callers need to populate or round-trip
5050
// directly. Re-export these rather than re-curating parallel surfaces.
5151
export type {
52-
SandboxResources,
5352
SandboxServiceLevel,
5453
SandboxStartup,
5554
SandboxWorkloadConfig,
@@ -126,6 +125,38 @@ function deletionResult(response: { outcome: number; sandboxId?: string }): Dele
126125
};
127126
}
128127

128+
/** Portable compute resource requirements for a sandbox workload. */
129+
export interface ResourceRequirements {
130+
/** Presence requests GPU resources. An empty object uses the driver's default assignment. */
131+
gpu?: GPUResourceRequirements;
132+
/** CPU requirements for the sandbox workload. */
133+
cpu?: CPUResourceRequirements;
134+
/** Memory requirements for the sandbox workload. */
135+
memory?: MemoryResourceRequirements;
136+
}
137+
138+
/** GPU resource requirements for a sandbox. */
139+
export interface GPUResourceRequirements {
140+
/** Number of GPUs requested. Omit to use the driver's default assignment. */
141+
count?: number;
142+
}
143+
144+
/** CPU resource requirements for a sandbox. */
145+
export interface CPUResourceRequirements {
146+
/** Optional CPU limit, as a Kubernetes-style quantity such as `500m`, `1`, or `2.5`. */
147+
limit?: string;
148+
/** Optional CPU request, independent of the limit. */
149+
request?: string;
150+
}
151+
152+
/** Memory resource requirements for a sandbox. */
153+
export interface MemoryResourceRequirements {
154+
/** Optional memory limit, as a byte quantity such as `512Mi`, `4Gi`, or `8G`. */
155+
limit?: string;
156+
/** Optional memory request, independent of the limit. */
157+
request?: string;
158+
}
159+
129160
export interface SandboxSpec {
130161
name?: string;
131162
/** Workspace name. Omit for `default`; empty strings are invalid. */
@@ -134,7 +165,8 @@ export interface SandboxSpec {
134165
labels?: Record<string, string>;
135166
environment?: Record<string, string>;
136167
providers?: string[];
137-
gpu?: boolean;
168+
/** Portable GPU, CPU, and memory requirements for the sandbox workload. */
169+
resourceRequirements?: ResourceRequirements;
138170
/** Exact canonical command. Empty selects the gateway scratch shell. */
139171
command?: string[];
140172
/** Allocate a retained pseudo-terminal for the canonical command. */
@@ -149,8 +181,8 @@ export interface SandboxSpec {
149181
* Advanced escape hatch: the full generated proto spec. Curated fields build
150182
* the base spec, then `rawSpec` shallow-overrides at the top spec level, so
151183
* any field it sets wins. Use it to reach proto spec fields the curated shape
152-
* does not surface (template runtime class, resource limits, log level, and
153-
* future additions) without an SDK change.
184+
* does not surface (template runtime class, log level, and future additions)
185+
* without an SDK change.
154186
*/
155187
rawSpec?: MessageInitShape<typeof SandboxSpecSchema>;
156188
}
@@ -857,7 +889,7 @@ export class SandboxClient {
857889
environment: spec.environment ?? {},
858890
providers: spec.providers ?? [],
859891
template: spec.image ? { image: spec.image } : undefined,
860-
resourceRequirements: spec.gpu ? { gpu: {} } : undefined,
892+
resourceRequirements: spec.resourceRequirements,
861893
policy: spec.policy,
862894
command: spec.command ?? [],
863895
tty: spec.tty ?? false,

‎sdk/typescript/src/index.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//
66
export type {
77
ConnectOptions,
8+
CPUResourceRequirements,
89
DeleteOptions,
910
DeletionOutcome,
1011
DeletionResult,
@@ -18,20 +19,22 @@ export type {
1819
ExecStreamEvent,
1920
ForwardHandle,
2021
ForwardOptions,
22+
GPUResourceRequirements,
2123
Health,
2224
HealthStatus,
2325
ListOptions,
26+
MemoryResourceRequirements,
2427
Page,
2528
PolicySourceName,
2629
ProviderChange,
2730
ProviderChangeOptions,
2831
ProviderRef,
32+
ResourceRequirements,
2933
SandboxConfig,
3034
SandboxFromTemplateSpec,
3135
SandboxPhaseName,
3236
SandboxPolicy,
3337
SandboxRef,
34-
SandboxResources,
3538
SandboxServiceLevel,
3639
SandboxSpec,
3740
SandboxStartup,

0 commit comments

Comments
 (0)