Skip to content

Make nodetype node selector label optional #2182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions apps/supervisor/src/workloadManager/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,13 @@ export class KubernetesWorkloadManager implements WorkloadManager {
restartPolicy: "Never",
automountServiceAccountToken: false,
imagePullSecrets: this.getImagePullSecrets(),
nodeSelector: {
nodetype: env.KUBERNETES_WORKER_NODETYPE_LABEL,
},
...(env.KUBERNETES_WORKER_NODETYPE_LABEL
? {
nodeSelector: {
nodetype: env.KUBERNETES_WORKER_NODETYPE_LABEL,
},
}
: {}),
};
Comment on lines +231 to 238
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Guard against whitespace-only env vars

The truthiness check will pass for any non-empty string, including a string that contains only whitespace.
That would result in a nodeSelector whose value is just spaces, yielding a pod that never schedules.

Consider trimming first:

- ...(env.KUBERNETES_WORKER_NODETYPE_LABEL
+ ...(env.KUBERNETES_WORKER_NODETYPE_LABEL?.trim()

If the trimmed string is empty, the selector is omitted – exactly the behaviour intended by this PR.
Optionally cache the trimmed value in a local const to avoid repeating the lookup.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
...(env.KUBERNETES_WORKER_NODETYPE_LABEL
? {
nodeSelector: {
nodetype: env.KUBERNETES_WORKER_NODETYPE_LABEL,
},
}
: {}),
};
...(env.KUBERNETES_WORKER_NODETYPE_LABEL?.trim()
? {
nodeSelector: {
nodetype: env.KUBERNETES_WORKER_NODETYPE_LABEL,
},
}
: {}),
};
🤖 Prompt for AI Agents
In apps/supervisor/src/workloadManager/kubernetes.ts around lines 231 to 238,
the code checks the environment variable KUBERNETES_WORKER_NODETYPE_LABEL for
truthiness but does not handle cases where it contains only whitespace. To fix
this, trim the environment variable value first and check if the trimmed string
is non-empty before setting the nodeSelector. Cache the trimmed value in a local
constant to avoid multiple lookups and ensure the nodeSelector is only set when
the trimmed value is valid.

}

Expand Down