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

✨ clusterctl move support for a cross namespace ClusterClass reference #11649

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Danil-Grigorev
Copy link
Member

@Danil-Grigorev Danil-Grigorev commented Jan 7, 2025

What this PR does / why we need it:

A follow-up on #11395 functionality, which integrates classNamespace field with clusterctl move.

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

@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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 7, 2025
@k8s-ci-robot k8s-ci-robot requested review from elmiko and enxebre January 7, 2025 21:26
@k8s-ci-robot k8s-ci-robot added do-not-merge/needs-area PR is missing an area label size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 7, 2025
Copy link
Contributor

@elmiko elmiko left a comment

Choose a reason for hiding this comment

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

i think this generally makes sense, but i have a couple questions.

also, happy to see the docs update 🙏

// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern="^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?(?:\\.[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)*$"
ClassNamespace string `json:"classNamespace,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have consensus about adding this field to the API?

i mean, it seems necessary for this change, but i don't recall what we might have agreed upon in the office hours.

Copy link
Member Author

Choose a reason for hiding this comment

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

It’s actually a superset of #11352, I believe we have a consensus on the actual PR in the review #11352 (comment) (correct me if I’m wrong)

@@ -55,3 +69,12 @@ func ClusterByClusterClassClassName(o client.Object) []string {
}
return nil
}

// ClusterByClusterClassClassNamespace contains the logic to index Clusters by ClusterClass namespace.
func ClusterByClusterClassClassNamespace(o client.Object) []string {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need the stutter, could we just name it ClusterByClusterClassNamespace ?

or if we need the extra context could we name it something different like ClusterByClusterClassTopologyNamespace ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good catch, I’ll update it. I think ClusterByClusterClassNamespace follows the naming pattern here.

@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-move-support branch 2 times, most recently from bc1b8fc to 8f8f47b Compare January 9, 2025 21:08
@k8s-ci-robot k8s-ci-robot added area/clusterclass Issues or PRs related to clusterclass and removed do-not-merge/needs-area PR is missing an area label labels Jan 9, 2025
Copy link
Contributor

@elmiko elmiko left a comment

Choose a reason for hiding this comment

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

this is generally making sense to me, do we need to merge #11352 first?

@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-move-support branch from 8f8f47b to 2a98610 Compare January 22, 2025 11:02
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 22, 2025
@Danil-Grigorev
Copy link
Member Author

/test pull-cluster-api-e2e-main

@@ -109,6 +110,11 @@ func (f *FakeCluster) WithTopologyClass(class string) *FakeCluster {
return f
}

func (f *FakeCluster) WithTopologyClassWithin(namespace string) *FakeCluster {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (f *FakeCluster) WithTopologyClassWithin(namespace string) *FakeCluster {
func (f *FakeCluster) WithTopologyClassNamespace(namespace string) *FakeCluster {

@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-move-support branch from 2a98610 to ba93019 Compare January 22, 2025 12:29
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 22, 2025
@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-move-support branch 2 times, most recently from 866abc0 to 4e5295b Compare January 22, 2025 14:03
- Prevent duplicate CC creation in template processing
- Test runtimextension integration
- Add changes to CC rebase e2e test
- Add a note CLUSTER_CLASS_NAMESPACE to the clusterctl contract

Signed-off-by: Danil-Grigorev <[email protected]>
@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-move-support branch from 4e5295b to f14a2f0 Compare January 23, 2025 16:46
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 23, 2025
@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-move-support branch from f14a2f0 to 36b7d8a Compare January 23, 2025 17:14
@k8s-ci-robot
Copy link
Contributor

@Danil-Grigorev: 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-test-main 36b7d8a link true /test pull-cluster-api-test-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.

@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-sigs/prow 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 Jan 23, 2025
@fabriziopandini
Copy link
Member

@Danil-Grigorev I took a look at the PR, and I think we should improve it to ensure that we delete a ClusterClass a CC from the source cluster on if:

  • it is in the same namespace as the one we move &
  • if it is only referenced by Clusters in that namespace

In order to do so, I suggest to:

  • add two new attribute to node in the object graph, ShouldNotDelete, ShouldNotDeleteHierarchy
  • in objectGraph.Discovery, right after the call to o.setSoftOwnership, call a new func o.setShouldNotDelete
  • implemente objectGraph.setShouldNotDelete
    • loop through all cc
      • if cc.ns != ns we are moving, set cc.ShouldNotDelete = true
      • if cc.ns == ns, chechk if there are clusters outside ns referencind this CCC. If yes, set cc.ShouldNotDelete = true
  • in objectGraph.setTenants(), set ShouldNotDeleteHierarchy (~same as we do for isGlobalHierarchy)
  • In objectMover.deleteSourceObject return early if ShouldNotDelete, ShouldNotDeleteHierarchy


// Set isGlobalHierarchy on clusterClass if is referenced from a different namespace
if classNamespace != cluster.identity.Namespace {
clusterClass.isGlobalHierarchy = true
Copy link
Member

@fabriziopandini fabriziopandini Jan 23, 2025

Choose a reason for hiding this comment

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

While this probably achieve the goal, it seems a little bit hacky:

  • isGlobal and isGlobalHierarchy are meant to track if "object is a global resource (no namespace).", which this is not the case for cc
  • you are using isGlobalHierarchy without having an isGlobal object on top

Please take a look at the alternative solution I proposed above, happy to chat about it if you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clusterclass Issues or PRs related to clusterclass cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants