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

🌱 sync defined machine labels to node #11650

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ykakarap
Copy link
Contributor

@ykakarap ykakarap commented Jan 7, 2025

What this PR does / why we need it:

Add an flag to the CAPI manager to dictate the labels that should be synced form the Machine to the node. If the flag is not specified it defaults to:

Has node-role.kubernetes.io as prefix.
Belongs to node-restriction.kubernetes.io domain.
Belongs to node.cluster.x-k8s.io domain.

Any value specified by the flag would be additional to the list to default values.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #11657

/area machine

@k8s-ci-robot k8s-ci-robot added area/machine Issues or PRs related to machine lifecycle management do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 7, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign neolit123 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 7, 2025
@ykakarap ykakarap force-pushed the sync-machine-labels branch from df52d4f to cb79cc3 Compare January 7, 2025 22:29
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 7, 2025
@ykakarap ykakarap force-pushed the sync-machine-labels branch from cb79cc3 to 2d97f8a Compare January 7, 2025 22:52
main.go Outdated Show resolved Hide resolved
@ykakarap ykakarap force-pushed the sync-machine-labels branch from 2d97f8a to 5ff55f6 Compare January 7, 2025 23:06
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 7, 2025
@ykakarap ykakarap changed the title [WIP] 🌱 sync machine labels 🌱 sync machine labels Jan 7, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 7, 2025
@ykakarap ykakarap changed the title 🌱 sync machine labels 🌱 sync machine labels to node Jan 7, 2025
@ykakarap ykakarap changed the title 🌱 sync machine labels to node 🌱 sync defined machine labels to node Jan 7, 2025
main.go Outdated Show resolved Hide resolved
@enxebre
Copy link
Member

enxebre commented Jan 8, 2025

Thanks! let's please make sure to add a counter part issue and update the original proposal https://github.com/kubernetes-sigs/cluster-api/blob/12cd150d55330e04b2639396469786a6020a5b82/docs/proposals/20220927-label-sync-between-machine-and-nodes.md

@ykakarap
Copy link
Contributor Author

ykakarap commented Jan 8, 2025

TODO:

  • Update CAPI Book
  • Update the proposal
  • Create issue

@nrb
Copy link
Contributor

nrb commented Jan 9, 2025

Thanks for this!

Something that would be useful here is some sort of wildcard support, in case administrators would like all labels propagated.

@vincepri
Copy link
Member

vincepri commented Jan 9, 2025

Something that would be useful here is some sort of wildcard support, in case administrators would like all labels propagated.

This is supported by setting *

https://github.com/kubernetes-sigs/cluster-api/pull/11650/files#diff-d4d6212206abc46c562f8e0ede7e3c6aa9b87390648a7f25ad96699446b1c525R761-R766

@ykakarap ykakarap force-pushed the sync-machine-labels branch from 5ff55f6 to 804d45d Compare January 9, 2025 21:52
main.go Outdated Show resolved Hide resolved
@ykakarap ykakarap force-pushed the sync-machine-labels branch from 0c12e60 to 114bd3a Compare January 15, 2025 18:20
@k8s-ci-robot
Copy link
Contributor

@ykakarap: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-apidiff-main 114bd3a link false /test pull-cluster-api-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@nrb
Copy link
Contributor

nrb commented Jan 16, 2025

@enxebre An issue was created, #11657.

This PR looks good to me; the documentation is clear, and the use of file path globbing would support my intended use case.

@enxebre
Copy link
Member

enxebre commented Jan 16, 2025

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 16, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: ed1927bdc916768f2a953ecfe84b99405eab3a2d

Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

Nice improvement!
/lgtm
@sbueringer @chrischdi for a final pass

return managedLabels
}

func (r *Reconciler) allowedDomainSync(domain string) bool {
for _, v := range r.SyncMachineLabels {
matched, _ := filepath.Match(v, domain)
Copy link
Member

@sbueringer sbueringer Jan 17, 2025

Choose a reason for hiding this comment

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

What is the reason we're using filepath.Match that as per the documentation "matches shell file name patterns" to select labels to sync?

I would have expected something like regexp as it should be more intuitive to match regexp against the full labels keys instead of using file patc matching on a substring of the label key

@@ -254,11 +255,30 @@ func InitFlags(fs *pflag.FlagSet) {
"Use deprecated infrastructure machine naming")
_ = fs.MarkDeprecated("use-deprecated-infra-machine-naming", "This flag will be removed in v1.9.")

fs.StringArrayVar(&syncMachineLabels, "additional-sync-machine-labels", []string{}, `The list of additional domains used to sync labels from machines to nodes.
The flag also supports standard glob processing:
Copy link
Member

Choose a reason for hiding this comment

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

How sure are we that this definition from the filepath.Match godoc is identical to glob patterns?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/machine Issues or PRs related to machine lifecycle management cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide configuration to allow users to define their own prefixes to sync labels from Machines to Nodes
8 participants