Skip to content

Commit 42cd14a

Browse files
committed
add tier scheduling support to supervisor
1 parent 6f29b7d commit 42cd14a

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

apps/supervisor/src/env.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ const Env = z.object({
7777
KUBERNETES_EPHEMERAL_STORAGE_SIZE_LIMIT: z.string().default("10Gi"),
7878
KUBERNETES_EPHEMERAL_STORAGE_SIZE_REQUEST: z.string().default("2Gi"),
7979

80+
// Tier scheduling settings
81+
ENABLE_TIER_SCHEDULING: BoolEnv.default(false),
82+
TIER_LABEL_KEY: z.string().default("node.cluster.x-k8s.io/paid"),
83+
TIER_LABEL_VALUE_FREE: z.string().default("false"),
84+
TIER_LABEL_VALUE_PAID: z.string().default("true"),
85+
8086
// Metrics
8187
METRICS_ENABLED: BoolEnv.default(true),
8288
METRICS_COLLECT_DEFAULTS: BoolEnv.default(true),

apps/supervisor/src/workloadManager/kubernetes.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ type ResourceQuantities = {
1313
[K in "cpu" | "memory" | "ephemeral-storage"]?: string;
1414
};
1515

16+
interface TierConfig {
17+
enabled: boolean;
18+
labelKey: string;
19+
freeValue: string;
20+
paidValue: string;
21+
}
22+
1623
export class KubernetesWorkloadManager implements WorkloadManager {
1724
private readonly logger = new SimpleStructuredLogger("kubernetes-workload-provider");
1825
private k8s: K8sApi;
1926
private namespace = env.KUBERNETES_NAMESPACE;
27+
private tierConfig: TierConfig;
2028

2129
constructor(private opts: WorkloadManagerOptions) {
2230
this.k8s = createK8sApi();
31+
this.tierConfig = this.tierSchedulingConfig;
2332

2433
if (opts.workloadApiDomain) {
2534
this.logger.warn("[KubernetesWorkloadManager] ⚠️ Custom workload API domain", {
@@ -28,6 +37,34 @@ export class KubernetesWorkloadManager implements WorkloadManager {
2837
}
2938
}
3039

40+
private get tierSchedulingConfig(): TierConfig {
41+
return {
42+
enabled: env.ENABLE_TIER_SCHEDULING,
43+
labelKey: env.TIER_LABEL_KEY,
44+
freeValue: env.TIER_LABEL_VALUE_FREE,
45+
paidValue: env.TIER_LABEL_VALUE_PAID,
46+
};
47+
}
48+
49+
private addTierScheduling(
50+
podSpec: Omit<k8s.V1PodSpec, "containers">,
51+
isPaidTier: boolean
52+
): Omit<k8s.V1PodSpec, "containers"> {
53+
if (!this.tierConfig.enabled) {
54+
return podSpec;
55+
}
56+
57+
const labelValue = isPaidTier ? this.tierConfig.paidValue : this.tierConfig.freeValue;
58+
59+
return {
60+
...podSpec,
61+
nodeSelector: {
62+
...podSpec.nodeSelector,
63+
[this.tierConfig.labelKey]: labelValue,
64+
},
65+
};
66+
}
67+
3168
async create(opts: WorkloadManagerCreateOptions) {
3269
this.logger.log("[KubernetesWorkloadManager] Creating container", { opts });
3370

@@ -48,7 +85,7 @@ export class KubernetesWorkloadManager implements WorkloadManager {
4885
},
4986
},
5087
spec: {
51-
...this.#defaultPodSpec,
88+
...this.addTierScheduling(this.#defaultPodSpec, opts.isPaidTier ?? false),
5289
terminationGracePeriodSeconds: 60 * 60,
5390
containers: [
5491
{

apps/supervisor/src/workloadManager/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ export interface WorkloadManagerCreateOptions {
3232
runFriendlyId: string;
3333
snapshotId: string;
3434
snapshotFriendlyId: string;
35+
// tier scheduling
36+
isPaidTier?: boolean;
3537
}

0 commit comments

Comments
 (0)