-
-
Notifications
You must be signed in to change notification settings - Fork 853
chore: move all placement tag helpers to core #2403
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { type PlacementTag } from "../schemas/index.js"; | ||
import { SimpleStructuredLogger } from "./structuredLogger.js"; | ||
|
||
export interface PlacementConfig { | ||
enabled: boolean; | ||
prefix: string; | ||
} | ||
|
||
export class PlacementTagProcessor { | ||
private readonly logger = new SimpleStructuredLogger("placement-tag-processor"); | ||
|
||
constructor(private readonly config: PlacementConfig) {} | ||
|
||
/** | ||
* Converts placement tags to Kubernetes nodeSelector labels | ||
*/ | ||
convertToNodeSelector( | ||
placementTags?: PlacementTag[], | ||
existingNodeSelector?: Record<string, string> | ||
): Record<string, string> { | ||
if (!this.config.enabled || !placementTags || placementTags.length === 0) { | ||
return existingNodeSelector ?? {}; | ||
} | ||
|
||
const nodeSelector: Record<string, string> = { ...existingNodeSelector }; | ||
|
||
// Convert placement tags to nodeSelector labels | ||
for (const tag of placementTags) { | ||
const labelKey = `${this.config.prefix}/${tag.key}`; | ||
|
||
// Print warnings (if any) | ||
this.printTagWarnings(tag); | ||
|
||
// For now we only support single values via nodeSelector | ||
nodeSelector[labelKey] = tag.values?.[0] ?? ""; | ||
} | ||
nicktrn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return nodeSelector; | ||
} | ||
|
||
private printTagWarnings(tag: PlacementTag) { | ||
if (!tag.values || tag.values.length === 0) { | ||
// No values provided | ||
this.logger.warn( | ||
"Placement tag has no values, using empty string", | ||
tag | ||
); | ||
} else if (tag.values.length > 1) { | ||
// Multiple values provided | ||
this.logger.warn( | ||
"Placement tag has multiple values, only using first one", | ||
tag | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Helper function to create a placement tag. In the future this will be able to support multiple values and operators. | ||
* For now it's just a single value. | ||
*/ | ||
export function placementTag(key: string, value: string): PlacementTag { | ||
return { key, values: [value] }; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Make the processor field readonly; ensure env prefix is set when enabled
To verify env wiring and defaults:
🏁 Script executed:
Length of output: 272
🏁 Script executed:
Length of output: 24031
Make placementTagProcessor readonly and normalize/validate PLACEMENT_TAGS_PREFIX
Quick summary: I verified that apps/supervisor/src/env.ts provides a default PLACEMENT_TAGS_PREFIX ("node.cluster.x-k8s.io") but PlacementTagProcessor uses the prefix directly and does not normalize or validate it. Also the field in KubernetesWorkloadManager is not readonly. Recommend making the field readonly and normalizing/validating the prefix centrally.
Files to change:
Suggested diffs:
Make field readonly in KubernetesWorkloadManager:
Normalize/validate prefix in PlacementTagProcessor (outline):
And replace label construction in convertToNodeSelector:
Note: apps/supervisor/src/env.ts currently defines:
Even with that default, normalizing/validating is recommended because the prefix can be overridden via environment and a trailing slash or empty value would produce malformed label keys.
📝 Committable suggestion