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

✨ Add classNamespace to topology #11352

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

Conversation

Danil-Grigorev
Copy link
Member

@Danil-Grigorev Danil-Grigorev commented Oct 30, 2024

What this PR does / why we need it:

Adding classNamespace variable to the cluster topology, which allows to point to a ClusterClass in a different namespace. This field is dormant, and is used for differentiation only.

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

/area clusterclass

@k8s-ci-robot k8s-ci-robot added area/clusterclass Issues or PRs related to clusterclass cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 30, 2024
@Danil-Grigorev Danil-Grigorev changed the title Add classNamespace to topology ✨ Add classNamespace to topology Oct 30, 2024
@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch 2 times, most recently from ae1cb19 to 43cb995 Compare October 30, 2024 11:59
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 30, 2024
@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch 2 times, most recently from 2bddeeb to 352fd66 Compare October 30, 2024 15:20
Copy link
Contributor

@salasberryfin salasberryfin left a comment

Choose a reason for hiding this comment

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

Thanks @Danil-Grigorev! I added a small suggestion but I think this looks good.

@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch from 352fd66 to bd8a56f Compare October 31, 2024 09:51
@salasberryfin
Copy link
Contributor

Thanks @Danil-Grigorev

/lgtm

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

LGTM label has been added.

Git tree hash: c4b418743a4683ae623b3264aae7636c41ad5675

@salasberryfin
Copy link
Contributor

/assign @chrischdi

@Danil-Grigorev Danil-Grigorev changed the title ✨ Add classNamespace to topology [WIP] ✨ Add classNamespace to topology Oct 31, 2024
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 31, 2024
@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch from bd8a56f to 4bbb218 Compare October 31, 2024 18:34
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 31, 2024
@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 Oct 31, 2024
@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch from 4bbb218 to d450768 Compare October 31, 2024 18:44
@Danil-Grigorev Danil-Grigorev changed the title [WIP] ✨ Add classNamespace to topology ✨ Add classNamespace to topology Oct 31, 2024
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch from bbbddcf to b4b6131 Compare November 27, 2024 21:25
api/v1beta1/cluster_types.go Outdated Show resolved Hide resolved
api/v1beta1/cluster_types.go Show resolved Hide resolved
api/v1beta1/cluster_types.go Outdated Show resolved Hide resolved
internal/webhooks/clusterclass.go Show resolved Hide resolved
@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch 4 times, most recently from c581444 to 3639364 Compare December 4, 2024 13:28
@Danil-Grigorev
Copy link
Member Author

@chrischdi @fabriziopandini Can I get another review? All comments are addressed here.

@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch from 902e582 to 2730042 Compare January 7, 2025 19:49
@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 ask for approval from chrischdi. 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

Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

Thank you for working on this and thx for the patience. Sorry for the delay

api/v1beta1/cluster_types.go Outdated Show resolved Hide resolved
api/v1beta1/cluster_types.go Outdated Show resolved Hide resolved
api/v1beta1/cluster_types.go Show resolved Hide resolved
api/v1beta1/cluster_types.go Show resolved Hide resolved
internal/webhooks/clusterclass.go Show resolved Hide resolved
@sbueringer sbueringer added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jan 13, 2025
@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch 3 times, most recently from 067fcc5 to 21ec29a Compare January 14, 2025 07:52
api/v1beta1/index/cluster.go Show resolved Hide resolved
api/v1beta1/index/cluster.go Outdated Show resolved Hide resolved
api/v1beta1/index/cluster.go Outdated Show resolved Hide resolved
internal/topology/check/compatibility_test.go Outdated Show resolved Hide resolved
api/v1beta1/index/cluster.go Outdated Show resolved Hide resolved
@sbueringer
Copy link
Member

@Danil-Grigorev Just a few minor comments

@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch from 8706ddc to 681bdbd Compare January 14, 2025 17:19
- Add documentation on securing cross-namespace access for CC
- Add ByClusterClassRef index
- Support cross-ns CC rebase

Signed-off-by: Danil-Grigorev <[email protected]>
@Danil-Grigorev Danil-Grigorev force-pushed the class-namespace-addition branch from 681bdbd to ebdc21d Compare January 15, 2025 16:02
// managers cache.
func ByClusterClassRef(ctx context.Context, mgr ctrl.Manager) error {
if err := mgr.GetCache().IndexField(ctx, &clusterv1.Cluster{},
ClusterClassNameField,
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
ClusterClassNameField,
ClusterClassRefPath,

(same for the Cluster List calls where we use the index)

Please also check all usages of ClusterClassNameField outside of this package (e.g. internal/webhooks/clusterclass_test.go)

return nil
}

// ClusterByClusterClassRef contains the logic to index Clusters by ClusterClass name.
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
// ClusterByClusterClassRef contains the logic to index Clusters by ClusterClass name.
// ClusterByClusterClassRef contains the logic to index Clusters by ClusterClass name and namespace.

nit

@@ -401,19 +401,19 @@ func TestClusterClassesAreCompatible(t *testing.T) {
APIVersion: "group.test.io/foo",
Copy link
Member

Choose a reason for hiding this comment

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

Didn't initially realize how broken this test is now :D

I think we should have defaultRef, incompatibleDefaultRef, compatibleRef, otherRef, ... (in the default & other namespace)

And then below we should make sure that each ClusterClass only has refs that match their own namespace (it's invalid to reference from a ClusterClass in one namespace to an external object in another namespace)

Let's also change l.476 to use "other" as namespace

Comment on lines +476 to 478
desired: builder.ClusterClass(metav1.NamespacePublic, "class1").
WithInfrastructureClusterTemplate(
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
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
desired: builder.ClusterClass(metav1.NamespacePublic, "class1").
WithInfrastructureClusterTemplate(
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
desired: builder.ClusterClass("other"", "class1").
WithInfrastructureClusterTemplate(
builder.InfrastructureClusterTemplate("other"", "infra1").Build()).

I meant we have to change these refs. All referenced templates of a CC should be in the same Namespaces as the CC itself (same for the rest of this builder)

@@ -706,19 +706,19 @@ func TestMachineDeploymentClassesAreCompatible(t *testing.T) {
APIVersion: "group.test.io/foo",
Kind: "barTemplate",
Name: "baz",
Namespace: "default",
Namespace: "other",
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep this at default as well (otherwise we don't verify that it's okay to change namespace)

Same in l.855

}

// ClusterClassRef returns ClusterClass index key to be used for search.
func ClusterClassRef(o client.Object) string {
Copy link
Member

@sbueringer sbueringer Jan 15, 2025

Choose a reason for hiding this comment

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

Suggested change
func ClusterClassRef(o client.Object) string {
func ClusterClassRef(cc *clusterv1.ClusterClass) string {

To make this slightly more typesafe

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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.