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 e2e tests & clusterctl changes for cross-ns CC ref #11395

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

Conversation

Danil-Grigorev
Copy link
Member

@Danil-Grigorev Danil-Grigorev commented Nov 11, 2024

What this PR does / why we need it:
This PR allows clusterctl to create a template with a reference to CC located in a different namespace.
This change allows to perform e2e tests in a multi-ns environment.

Added e2e tests to verify cluster-class quick-start scenario and runtime extension scenario in a cross-namespaced context.

The PR is built on top of:

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 #5673

@k8s-ci-robot k8s-ci-robot added 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. do-not-merge/needs-area PR is missing an area label labels Nov 11, 2024
@k8s-ci-robot k8s-ci-robot requested a review from elmiko November 11, 2024 10:19
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 11, 2024
@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references-full branch 5 times, most recently from d92a5c2 to 7560e66 Compare November 12, 2024 11:33
@Danil-Grigorev Danil-Grigorev changed the title [WIP] ✨ E2E test for the classNamespace usage [WIP] ✨ Add clusterctl changes for cross-ns CC ref Nov 12, 2024
@Danil-Grigorev Danil-Grigorev changed the title [WIP] ✨ Add clusterctl changes for cross-ns CC ref ✨ Add clusterctl changes for cross-ns CC ref Nov 12, 2024
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Nov 12, 2024
@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references-full branch from 7560e66 to 09ce978 Compare November 18, 2024 19:46
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed 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. labels Nov 18, 2024
@fabriziopandini fabriziopandini changed the title ✨ Add clusterctl changes for cross-ns CC ref [WIP] ✨ Add clusterctl changes for cross-ns CC ref Nov 25, 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 Nov 25, 2024
@fabriziopandini
Copy link
Member

Renamed wip since it builds on a PR not yet merged

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.

Made first pass, I will get back to this when the PR it builds on top are merged

Comment on lines 42 to 43
// This test is meant to provide a first, fast signal to detect regression; it is recommended to use it as a PR blocker test.
// NOTE: This test works with Clusters with and without ClusterClass.
Copy link
Member

Choose a reason for hiding this comment

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

Considering we are trying to keep PR-blocking duration as short as possible, and that the code paths touched by this change are limited and very specific to CC management, would it be possible to add this test on a PR only on demand + on periodic (once it is added to a PR, then it became blocking)

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently using this as a way to quickly test subset of scenarios without having to invoke full-test-suite. I’ll unmark it from pre-submits. Should all added test cases be on demand + perodic?

test/e2e/cross-ns-quick-start.go Outdated Show resolved Hide resolved
@@ -44,7 +46,7 @@ func addClusterClassIfMissing(ctx context.Context, template Template, clusterCla
return template, nil
}

clusterClassesTemplate, err := fetchMissingClusterClassTemplates(ctx, clusterClassClient, clusterClient, classes, targetNamespace, listVariablesOnly)
clusterClassesTemplate, err := fetchMissingClusterClassTemplates(ctx, clusterClassClient, clusterClient, classes, listVariablesOnly)
Copy link
Member

Choose a reason for hiding this comment

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

Just to check if I'm getting this right.
As of today, when we are deploying objects, clusterctl allows to override the namespace set into templates (use case: the user wants to deploy to namespace xyz instead of namespace original).

With this PR we are changing this behaviour, and always preserving the namespace from the template when we are adding the cluster class to the template being deployed (cc preserve: namespace original).

If this is correct, and if I'm not wrong, this change might break users that are deploying a Cluster with ClassNamespace empty, and are expecting that also the CC gets deployed in the target namespace xyz along side with the cluster.

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 shouldn’t break these users, since regular process of overriding the namespace of the templated resources is still performed. This new field was never a part of this logic, and the SoT here is the template initially.

This change avoids problems in discovering the existence of the CC in the specified namespace, allowing to template only a Cluster resource.

There is no support in clusterclt to distinguish that some of the resources should go into A namespace, and some other into B, so this multi-namespace setup is intended to happen in a multiple passes.

  1. ClusterClass and referenced templates
  2. A cluster resource in a different namespace
  3. repeat 2 for any namespace without failures on clusterctl side, or any existing template modifications.

Copy link
Member

@sbueringer sbueringer Jan 14, 2025

Choose a reason for hiding this comment

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

I'm not entirely sure, but I think this shouldn't break anything.

The namespace-thing for cluster-templates is only envsubst, right?

(while for provider installations it's a lot more)

EDIT: I'll take that one back

Copy link
Member

@sbueringer sbueringer Jan 14, 2025

Choose a reason for hiding this comment

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

My best guess is that it still works as good as before :)

Copy link
Member

Choose a reason for hiding this comment

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

Okay took another look, seems all good

clusterInitialized: false,
objs: []client.Object{},
targetNamespace: "ns1",
clusterClassNamespace: "ns2",
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a similar test when both namespaces are the same, and one where both are empty?

@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references-full branch from 09ce978 to 2d4a64e Compare December 4, 2024 14:34
@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 Dec 4, 2024
@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references-full branch from 2d4a64e to c181e3e Compare December 4, 2024 15:22
@k8s-ci-robot k8s-ci-robot removed the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Dec 4, 2024
@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references-full branch from 9b2cce5 to b2cbee3 Compare January 14, 2025 17:37
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.

Initial round of review.

But let's wait a bit with adjustments. I have to talk to @fabriziopandini a bit about the test coverage we want / need

test/e2e/cluster_upgrade_runtimesdk.go Outdated Show resolved Hide resolved
test/e2e/cluster_upgrade_runtimesdk.go Outdated Show resolved Hide resolved
test/e2e/quick_start.go Outdated Show resolved Hide resolved
@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references-full branch 7 times, most recently from bb6604e to 9c1fec9 Compare January 16, 2025 12:55
- Add documentation on securing cross-namespace access for CC
- Add ByClusterClassRef index
- Support cross-ns CC rebase

Signed-off-by: Danil-Grigorev <[email protected]>
Signed-off-by: Danil-Grigorev <[email protected]>
@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references-full branch from 9c1fec9 to ce94b11 Compare January 17, 2025 13:17
@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references-full branch from ce94b11 to 0a130d3 Compare January 17, 2025 13:26
@Danil-Grigorev Danil-Grigorev changed the title [WIP] ✨ Add clusterctl changes for cross-ns CC ref ✨ Add clusterctl changes for cross-ns CC ref Jan 17, 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 17, 2025
@sbueringer sbueringer changed the title ✨ Add clusterctl changes for cross-ns CC ref ✨ Add e2e tests & clusterctl changes for cross-ns CC ref Jan 17, 2025
@sbueringer sbueringer added the area/clusterclass Issues or PRs related to clusterclass label Jan 17, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-area PR is missing an area label label Jan 17, 2025
Comment on lines 337 to 341
Byf("Deleting namespace used for hosting the %q test spec", specName)
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
Deleter: input.BootstrapClusterProxy.GetClient(),
Name: clusterClassNamespace.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
Byf("Deleting namespace used for hosting the %q test spec", specName)
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
Deleter: input.BootstrapClusterProxy.GetClient(),
Name: clusterClassNamespace.Name,
})

Duplicate with below

})

if input.DeployClusterClassInSeparateNamespace {
Byf("Deleting namespace used for optionally hosting the %q infrastructure spec", specName)
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
Byf("Deleting namespace used for optionally hosting the %q infrastructure spec", specName)
Byf("Deleting namespace used for hosting the %q test spec ClusterClass", specName)

maybe

@@ -172,10 +170,6 @@ func MergeTemplates(templates ...Template) (Template, error) {
}
}

if merged.targetNamespace != tmpl.TargetNamespace() {
Copy link
Member

Choose a reason for hiding this comment

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

I get why we need this change and I also saw that it doesn't lead to problems.

The way we are using this func now leads to an invalid merged.targetNamespace. Before this PR targetNamespace was correct because all templates are in the same namespace. Now merged.targetNamespace is not the namespace of all objects in the template anymore. This doesn't lead to problems because after we call MergeTemplates we only call YAML() and VariableMap() on the returned template, but this seems a bit brittle

Not sure what we should do, maybe rather not set the targetNamespace field if the templates are not all in the same namespace? Let's wait what @fabriziopandini thinks.

In any case, if we keep dropping this check here, please update the godoc of this func ("The merge operation returns an error if all the templates do not have the same TargetNamespace.").

@@ -111,6 +111,13 @@ func printVariablesOutput(template client.Template, options client.GetClusterTem
} else if val, ok := os.LookupEnv("KUBERNETES_VERSION"); ok {
variableMap[name] = ptr.To(val)
}
case "CLUSTER_CLASS_NAMESPACE":
Copy link
Member

Choose a reason for hiding this comment

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

comment above

		// Fix up default for well-know variables that have a special logic implemented in clusterctl.
		// NOTE: this logic mimics the defaulting rules implemented in client.GetClusterTemplate;

Sounds like if we do this here we should also add the same in client.GetClusterTemplate? (which is actually in client/config.go templateOptionsToVariables)

@fabriziopandini WDYT?

@@ -95,6 +95,9 @@ type ClusterUpgradeWithRuntimeSDKSpecInput struct {
ExtensionServiceNamespace string
// ExtensionServiceName is the name of the service to configure in the test-namespace scoped ExtensionConfig.
ExtensionServiceName string

// DeployClusterClassInSeparateNamespace is set if a second namespace is required for the ClusterClass deployment
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
// DeployClusterClassInSeparateNamespace is set if a second namespace is required for the ClusterClass deployment
// DeployClusterClassInSeparateNamespace defines if the ClusterClass should be deployed in a separate namespace.

Comment on lines 144 to 147
variables["CLUSTER_CLASS_NAMESPACE"] = clusterClassNamespace.Name
By("Creating a cluster referencing a clusterClass from another namespace")
} else {
By("Creating a cluster referencing a clusterClass")
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
variables["CLUSTER_CLASS_NAMESPACE"] = clusterClassNamespace.Name
By("Creating a cluster referencing a clusterClass from another namespace")
} else {
By("Creating a cluster referencing a clusterClass")
variables["CLUSTER_CLASS_NAMESPACE"] = clusterClassNamespace.Name
By("Creating a cluster referencing a ClusterClass from another namespace")
} else {
By("Creating a cluster referencing a ClusterClass")

nit

Copy link
Member

Choose a reason for hiding this comment

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

Hm quickstart also works with clusters without ClusterClass. Do we need these logs? :)

Comment on lines 182 to 185
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
Deleter: input.BootstrapClusterProxy.GetClient(),
Name: clusterClassNamespace.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
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
Deleter: input.BootstrapClusterProxy.GetClient(),
Name: clusterClassNamespace.Name,
})
if input.DeployClusterClassInSeparateNamespace {
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
Deleter: input.BootstrapClusterProxy.GetClient(),
Name: clusterClassNamespace.Name,
})
}

@@ -120,6 +120,7 @@ var _ = Describe("When following the Cluster API quick-start with ClusterClass [
By("Checking that resourceVersions are stable")
framework.ValidateResourceVersionStable(ctx, proxy, namespace, clusterctlcluster.FilterClusterObjectsWithNameFilter(clusterName))
},
DeployClusterClassInSeparateNamespace: true,
Copy link
Member

Choose a reason for hiding this comment

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

Hm. I would like to preserve the existing test coverage here for C + CC in the same namespace. Which is the mainstream use case at the moment.

I'm fine with implementing the flag for the quickstart coverage, but I wonder if we have to run the test with the flag in core CAPI. The quickstart part of the test is a subset of what we test in the Runtime SDK test

test/e2e/cross-ns-quick-start.go Outdated Show resolved Hide resolved
@@ -44,7 +46,7 @@ func addClusterClassIfMissing(ctx context.Context, template Template, clusterCla
return template, nil
}

clusterClassesTemplate, err := fetchMissingClusterClassTemplates(ctx, clusterClassClient, clusterClient, classes, targetNamespace, listVariablesOnly)
clusterClassesTemplate, err := fetchMissingClusterClassTemplates(ctx, clusterClassClient, clusterClient, classes, listVariablesOnly)
Copy link
Member

Choose a reason for hiding this comment

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

Okay took another look, seems all good

@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references-full branch 2 times, most recently from dff6c42 to bf08d8d Compare January 17, 2025 18:25
Signed-off-by: Danil-Grigorev <[email protected]>
@Danil-Grigorev Danil-Grigorev force-pushed the standardize-references-full branch from bf08d8d to d2a4e3b Compare January 17, 2025 18:29
@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-e2e-blocking-main d2a4e3b link true /test pull-cluster-api-e2e-blocking-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.

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/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.

Allow using a ClusterClass across namespaces
4 participants