Skip to content

Commit 93532cd

Browse files
0skinicktrn
andauthored
feat(supervisor): forward per-run labels to the compute provider (#3821)
Add an optional network_labels field to the internal compute client's create and restore request schemas and forward per-VM endpoint labels on both paths, so a restored VM keeps the same labels as a freshly-booted one. Mirrors the label the Kubernetes workload manager already sets on the run pod. --------- Co-authored-by: nicktrn <55853254+nicktrn@users.noreply.github.com>
1 parent 8b85da1 commit 93532cd

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: supervisor
3+
type: feature
4+
---
5+
6+
Forward per-run identity labels to the compute provider on create and restore, letting network policy select runs (e.g. private link).

apps/supervisor/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ class ManagedSupervisor {
376376
envId: message.environment.id,
377377
orgId: message.organization.id,
378378
projectId: message.project.id,
379+
hasPrivateLink: message.organization.hasPrivateLink,
379380
dequeuedAt: message.dequeuedAt,
380381
});
381382
recordPhaseSince("restore", restoreStart, undefined);

apps/supervisor/src/workloadManager/compute.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ export class ComputeWorkloadManager implements WorkloadManager {
133133
// Strip image digest - resolve by tag, not digest
134134
const imageRef = stripImageDigest(opts.image);
135135

136+
// Labels forwarded to the compute provider for network-policy selection;
137+
// the provider promotes a configured subset to its network layer. Mirrors
138+
// the privatelink label the Kubernetes workload manager sets on the run pod.
139+
const labels: Record<string, string> = {};
140+
if (opts.hasPrivateLink) {
141+
labels.privatelink = opts.orgId;
142+
}
143+
136144
// Wide event: single canonical log line emitted in finally
137145
const event: Record<string, unknown> = {
138146
// High-cardinality identifiers
@@ -173,6 +181,7 @@ export class ComputeWorkloadManager implements WorkloadManager {
173181
deploymentVersion: opts.deploymentVersion,
174182
machine: opts.machine.name,
175183
},
184+
...(Object.keys(labels).length > 0 ? { labels } : {}),
176185
})
177186
);
178187

@@ -297,6 +306,7 @@ export class ComputeWorkloadManager implements WorkloadManager {
297306
envId?: string;
298307
orgId?: string;
299308
projectId?: string;
309+
hasPrivateLink?: boolean;
300310
dequeuedAt?: Date;
301311
}): Promise<boolean> {
302312
const metadata: Record<string, string> = {
@@ -309,6 +319,14 @@ export class ComputeWorkloadManager implements WorkloadManager {
309319
TRIGGER_WORKER_INSTANCE_NAME: this.opts.runner.instanceName,
310320
};
311321

322+
// Resupply the same labels on restore (mirror of the create path); the
323+
// provider doesn't persist them across a snapshot, so without this a
324+
// restored run would lose its policy-based network selection.
325+
const labels: Record<string, string> = {};
326+
if (opts.hasPrivateLink && opts.orgId) {
327+
labels.privatelink = opts.orgId;
328+
}
329+
312330
this.logger.verbose("restore request body", {
313331
snapshotId: opts.snapshotId,
314332
runnerId: opts.runnerId,
@@ -322,6 +340,7 @@ export class ComputeWorkloadManager implements WorkloadManager {
322340
metadata,
323341
cpu: opts.machine.cpu,
324342
memory_gb: opts.machine.memory,
343+
...(Object.keys(labels).length > 0 ? { labels } : {}),
325344
})
326345
);
327346

internal-packages/compute/src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export const InstanceCreateRequestSchema = z.object({
4242
cpu: z.number(),
4343
memory_gb: z.number(),
4444
metadata: z.record(z.unknown()).optional(),
45+
// Per-instance identity labels; the provider promotes a configured subset
46+
// to network-policy selection. Distinct from metadata, which is
47+
// observability-only and never selected on.
48+
labels: z.record(z.string()).optional(),
4549
});
4650
export type InstanceCreateRequest = z.infer<typeof InstanceCreateRequestSchema>;
4751

@@ -66,6 +70,10 @@ export const SnapshotRestoreRequestSchema = z.object({
6670
metadata: z.record(z.string()),
6771
cpu: z.number(),
6872
memory_gb: z.number(),
73+
// Per-instance identity labels; the caller must resupply the same set as on
74+
// create. The provider doesn't persist them across a snapshot, so omitting
75+
// them drops the restored run's policy-based network selection.
76+
labels: z.record(z.string()).optional(),
6977
});
7078
export type SnapshotRestoreRequest = z.infer<typeof SnapshotRestoreRequestSchema>;
7179

0 commit comments

Comments
 (0)