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

✨ Make sure IPAddressClaim has a cluster name label. #9883

Closed

Conversation

mcbenjemaa
Copy link
Member

What this PR does / why we need it:

The clusterctl move fails because the IPAddressClaim is not paused so the controller in the target cluster will create IPAddress resouces.

To pause the IPAddressClaim, we need to set the cluster label name.

This PR adds validation to the webhook of IPAddressClaim to ensure the cluster name label is always set.

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 #

Fixes #9478
/area ipam

@k8s-ci-robot k8s-ci-robot added area/ipam Issues or PRs related to ipam cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 14, 2023
@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 Kubernetes 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/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 14, 2023
@mcbenjemaa mcbenjemaa changed the title Make sure IPAddressClaim has a cluster name label. ✨ Make sure IPAddressClaim has a cluster name label. Dec 14, 2023
Comment on lines +58 to +65
// Ensures the IPAddressClaim has a cluster name label, to pause IPAddressClaim when the root cluster is paused
// and essentially prevent clusterctl move from failing.
if claim.GetObjectMeta().GetLabels()[clusterv1.ClusterNameLabel] == "" {
return nil, field.Invalid(
field.NewPath("metadata.labels"),
claim.GetObjectMeta().GetLabels(),
"the IPAddressClaim needs to have the cluster name label 'cluster.x-k8s.io/cluster-name'")
}
Copy link
Member

Choose a reason for hiding this comment

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

Who's responsible for adding this label? If users, I'd say this should be a field, like spec.Cluster like in other objects

Copy link
Member

Choose a reason for hiding this comment

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

Are we sure we want to enforce that an IPAddressClaim has to belong to a cluster?

Today it's perfectly fine to use this CRD independent of a Cluster, which I could imagine can be quite useful in some cases.

(One rare use case that we have in CAPV e2e tests is that we basically have a separate cluster running once that we can use for IPAM purposes. This is entirely separate of mgmt clusters and the "reserved" IP addresses are then used in e2e mgmt clusters)

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, it seems this should have been discussed in the related issue. I was more commenting on the implementation of this constraint rather than looking at the semantics of the CRD; I haven't used these CRDs much, so I'll leave it to the folks responsible for them.

cc @rvanderp3

Copy link
Member

Choose a reason for hiding this comment

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

Yup got it. Sorry just thought my point somewhat fits to yours :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe @fabriziopandini can add more thoughts in this regards

Copy link
Member

@schrej schrej Jan 12, 2024

Choose a reason for hiding this comment

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

I agree with Stefan, I don't think we should enforce this. Providers should set the label when creating claims that are part of a cluster, but we shouldn't make it mandatory for every actor.
We (I) still need to create a proper IPAM contract description, which should include this as a requirement.

Copy link
Member

Choose a reason for hiding this comment

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

If a label is required to link the claim to a cluster, the label should be a field, can be optional in this case; but we shouldn't rely on labels as a good API to expose to users in this context

Copy link
Member Author

Choose a reason for hiding this comment

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

if this is not needed, feel free to close it.

Copy link
Member

@schrej schrej Feb 20, 2024

Choose a reason for hiding this comment

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

I agree, and so do the k8s api guidelines I think, that labels (and annotations) shouldn't be used if a property can be used instead.
Since the label is set on a lot of resources, which makes sense for querying them with clusterctl, the immediate thought is to use the label instead of a property to avoid duplicating data.
#10182

Copy link
Member

@chrischdi chrischdi left a comment

Choose a reason for hiding this comment

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

Besides the ongoing discussion: the change seems good to me

/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 10, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: fa9ba2b9e7cc911c4eee6f46b7f487b02162c375

@sbueringer
Copy link
Member

/hold
given #9883 (comment) and #9883 (comment)

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 12, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 10, 2024
@sbueringer
Copy link
Member

/close

Given

I agree with Stefan, I don't think we should enforce this. Providers should set the label when creating claims that are part of a cluster, but we shouldn't make it mandatory for every actor.

@k8s-ci-robot
Copy link
Contributor

@sbueringer: Closed this PR.

In response to this:

/close

Given

I agree with Stefan, I don't think we should enforce this. Providers should set the label when creating claims that are part of a cluster, but we shouldn't make it mandatory for every actor.

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/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ipam Issues or PRs related to ipam cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail to move cluster with associated IPAddresses
6 participants