Skip to content
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

fix: ensure the machineset label value is valid per K8s convention #69

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

ihcsim
Copy link
Contributor

@ihcsim ihcsim commented Jan 30, 2025

When user defined custom affinity/anti-affinity rules for VMs, additional preferred affinity/anti-affinity rules are added to ensure the virt-launcher pods don't land on the same node (by keying the rules off the node's hostname). Currently, there are no checks to ensure the generated label value in these rules adhered to the Kubernetes' labeling convention.

This PR uses the same approach as CAPI to format and hash the label value. Since the machineset label value is only used to establish pod affinity, the actual (hashed or not) label value used is opaque.

EDIT: Issue at harvester/harvester#7467.

It uses fnv-1a to generate a non-zero, non-cryptographic hash to replace
any invalid characters in the label value.

Since the machineset label value is only used to establish pod affinity,
the actual label value is considered opaque.

Ref: https://github.com/kubernetes-sigs/cluster-api/blob/010af7f92f98ead971742d347d258a8786d5d57c/util/labels/format/helpers.go

Signed-off-by: Ivan Sim <[email protected]>
@ihcsim
Copy link
Contributor Author

ihcsim commented Jan 30, 2025

@ibrokethecloud Let me know what you think of this. My first thought is to delete those default affinity/anti-affinity rules, to make it easier to reason about and avoid unintended side effects. E.g., I am not sure why we append the affinity term to both the affinity and anti-affinity sets. Won't the affinity always take precedence, given the order they are evaluated? Or AIUI, it might make sense to keep the pod anti-affinity across nodes based on the original PR's intention.

Or if we need to keep them, this PR proposes a solution based on what CAPI has done to tackle the same issue. PTAL.

Copy link
Contributor

@ibrokethecloud ibrokethecloud left a comment

Choose a reason for hiding this comment

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

lgtm. thanks for the fix.

@ibrokethecloud
Copy link
Contributor

Related issue: harvester/harvester#7467

Copy link
Member

@FrankYang0529 FrankYang0529 left a comment

Choose a reason for hiding this comment

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

LGTM. With the test steps, I can get label like harvesterhci.io/machineSetName: hash_zRYvIw_z on the VM.

Copy link
Member

@votdev votdev left a comment

Choose a reason for hiding this comment

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

LGTM

@ihcsim ihcsim merged commit bdd9cc4 into harvester:master Feb 3, 2025
5 checks passed
@ihcsim ihcsim deleted the format-affinity-label-values branch February 3, 2025 17:12
@ihcsim
Copy link
Contributor Author

ihcsim commented Feb 3, 2025

@bk201 @ibrokethecloud let me know what the backport targets are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants