-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: main
Are you sure you want to change the base?
✨ Add e2e tests & clusterctl changes for cross-ns CC ref #11395
Conversation
d92a5c2
to
7560e66
Compare
7560e66
to
09ce978
Compare
Renamed wip since it builds on a PR not yet merged |
There was a problem hiding this 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
test/e2e/data/infrastructure-docker/main/cluster-template-cross-ns-topology/cluster.yaml
Outdated
Show resolved
Hide resolved
test/e2e/cross-ns-quick-start.go
Outdated
// 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. |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
- ClusterClass and referenced templates
- A cluster resource in a different namespace
- repeat 2 for any namespace without failures on
clusterctl
side, or any existing template modifications.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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?
09ce978
to
2d4a64e
Compare
2d4a64e
to
c181e3e
Compare
9b2cce5
to
b2cbee3
Compare
There was a problem hiding this 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
bb6604e
to
9c1fec9
Compare
- 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]>
Signed-off-by: Danil-Grigorev <[email protected]>
Signed-off-by: Danil-Grigorev <[email protected]>
Signed-off-by: Danil-Grigorev <[email protected]>
Signed-off-by: Danil-Grigorev <[email protected]>
Signed-off-by: Danil-Grigorev <[email protected]>
9c1fec9
to
ce94b11
Compare
Signed-off-by: Danil-Grigorev <[email protected]>
ce94b11
to
0a130d3
Compare
Byf("Deleting namespace used for hosting the %q test spec", specName) | ||
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{ | ||
Deleter: input.BootstrapClusterProxy.GetClient(), | ||
Name: clusterClassNamespace.Name, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
test/e2e/quick_start.go
Outdated
variables["CLUSTER_CLASS_NAMESPACE"] = clusterClassNamespace.Name | ||
By("Creating a cluster referencing a clusterClass from another namespace") | ||
} else { | ||
By("Creating a cluster referencing a clusterClass") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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? :)
test/e2e/quick_start.go
Outdated
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{ | ||
Deleter: input.BootstrapClusterProxy.GetClient(), | ||
Name: clusterClassNamespace.Name, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, | |
}) | |
} |
test/e2e/quick_start_test.go
Outdated
@@ -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, |
There was a problem hiding this comment.
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
@@ -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) |
There was a problem hiding this comment.
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
dff6c42
to
bf08d8d
Compare
Signed-off-by: Danil-Grigorev <[email protected]>
bf08d8d
to
d2a4e3b
Compare
@Danil-Grigorev: The following test failed, say
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. |
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