Skip to content

Commit 46521c5

Browse files
committed
Do the parsing on startup instead of at run time
1 parent 2ed5794 commit 46521c5

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

apps/supervisor/src/env.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,51 @@ const Env = z
167167
// Schedule toleration settings - scheduled runs tolerate taints on the dedicated pool
168168
// Comma-separated list of tolerations in the format: key=value:effect
169169
// For Exists operator (no value): key:effect
170-
KUBERNETES_SCHEDULED_RUN_TOLERATIONS: z.string().optional(),
170+
KUBERNETES_SCHEDULED_RUN_TOLERATIONS: z
171+
.string()
172+
.transform((val, ctx) => {
173+
const tolerations = val
174+
.split(",")
175+
.map((entry) => entry.trim())
176+
.filter((entry) => entry.length > 0)
177+
.map((entry) => {
178+
const colonIdx = entry.lastIndexOf(":");
179+
if (colonIdx === -1) {
180+
ctx.addIssue({
181+
code: z.ZodIssueCode.custom,
182+
message: `Invalid toleration format (missing effect): "${entry}"`,
183+
});
184+
return z.NEVER;
185+
}
186+
187+
const effect = entry.slice(colonIdx + 1);
188+
const validEffects = ["NoSchedule", "NoExecute", "PreferNoSchedule"];
189+
if (!validEffects.includes(effect)) {
190+
ctx.addIssue({
191+
code: z.ZodIssueCode.custom,
192+
message: `Invalid toleration effect "${effect}" in "${entry}". Must be one of: ${validEffects.join(", ")}`,
193+
});
194+
return z.NEVER;
195+
}
196+
197+
const keyValue = entry.slice(0, colonIdx);
198+
const eqIdx = keyValue.indexOf("=");
199+
200+
if (eqIdx === -1) {
201+
return { key: keyValue, operator: "Exists" as const, effect };
202+
}
203+
204+
return {
205+
key: keyValue.slice(0, eqIdx),
206+
operator: "Equal" as const,
207+
value: keyValue.slice(eqIdx + 1),
208+
effect,
209+
};
210+
});
211+
212+
return tolerations;
213+
})
214+
.optional(),
171215

172216
// Placement tags settings
173217
PLACEMENT_TAGS_ENABLED: BoolEnv.default(false),

apps/supervisor/src/workloadManager/kubernetes.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -530,37 +530,11 @@ export class KubernetesWorkloadManager implements WorkloadManager {
530530
}
531531

532532
#getScheduleTolerations(isScheduledRun: boolean): k8s.V1Toleration[] | undefined {
533-
if (!isScheduledRun || !env.KUBERNETES_SCHEDULED_RUN_TOLERATIONS) {
533+
if (!isScheduledRun || !env.KUBERNETES_SCHEDULED_RUN_TOLERATIONS?.length) {
534534
return undefined;
535535
}
536536

537-
return env.KUBERNETES_SCHEDULED_RUN_TOLERATIONS.split(",")
538-
.map((entry) => entry.trim())
539-
.filter((entry) => entry.length > 0)
540-
.map((entry) => {
541-
// Format: key=value:effect or key:effect (Exists operator)
542-
const colonIdx = entry.lastIndexOf(":");
543-
if (colonIdx === -1) {
544-
throw new Error(`Invalid toleration format (missing effect): "${entry}"`);
545-
}
546-
547-
const effect = entry.slice(colonIdx + 1) as k8s.V1Toleration["effect"];
548-
const keyValue = entry.slice(0, colonIdx);
549-
const eqIdx = keyValue.indexOf("=");
550-
551-
if (eqIdx === -1) {
552-
// key:effect -> Exists operator
553-
return { key: keyValue, operator: "Exists" as const, effect };
554-
}
555-
556-
// key=value:effect -> Equal operator
557-
return {
558-
key: keyValue.slice(0, eqIdx),
559-
operator: "Equal" as const,
560-
value: keyValue.slice(eqIdx + 1),
561-
effect,
562-
};
563-
});
537+
return env.KUBERNETES_SCHEDULED_RUN_TOLERATIONS;
564538
}
565539

566540
#getProjectPodAffinity(projectId: string): k8s.V1PodAffinity | undefined {

0 commit comments

Comments
 (0)