Skip to content

Commit 2d4a64e

Browse files
Refactor to use empty CC namespace
Signed-off-by: Danil-Grigorev <[email protected]>
1 parent 865ffd1 commit 2d4a64e

File tree

7 files changed

+47
-156
lines changed

7 files changed

+47
-156
lines changed

test/e2e/cluster_upgrade_runtimesdk_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ var _ = Describe("When upgrading a workload cluster using ClusterClass in a diff
8282
framework.ValidateResourceVersionStable(ctx, proxy, namespace, clusterctlcluster.FilterClusterObjectsWithNameFilter(clusterName))
8383
},
8484
// "upgrades" is the same as the "topology" flavor but with an additional MachinePool.
85-
Flavor: ptr.To("cross-ns-upgrades-runtimesdk"),
85+
Flavor: ptr.To("upgrades-runtimesdk"),
8686
ClassNamespace: true,
8787
// The runtime extension gets deployed to the test-extension-system namespace and is exposed
8888
// by the test-extension-webhook-service.

test/e2e/cross-ns-quick-start.go

-138
This file was deleted.

test/e2e/data/infrastructure-docker/main/bases/cluster-with-topology.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ spec:
1414
serviceDomain: '${DOCKER_SERVICE_DOMAIN}'
1515
topology:
1616
class: "quick-start"
17+
classNamespace: '${CLUSTER_CLASS_NAMESPACE}'
1718
version: "${KUBERNETES_VERSION}"
1819
controlPlane:
1920
metadata:

test/e2e/data/infrastructure-docker/main/cluster-template-upgrades-runtimesdk/cluster-runtimesdk.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ spec:
1414
serviceDomain: '${DOCKER_SERVICE_DOMAIN}'
1515
topology:
1616
class: "quick-start-runtimesdk"
17+
classNamespace: '${CLUSTER_CLASS_NAMESPACE}'
1718
version: "${KUBERNETES_VERSION}"
1819
controlPlane:
1920
metadata: {}

test/e2e/quick_start.go

+30-5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type QuickStartSpecInput struct {
4444
// If not set, a random one will be generated.
4545
ClusterName *string
4646

47+
// ClassNamespace is an optional class namespace reference, configuring cross-namespace cluster class reference
48+
ClassNamespace *string
49+
4750
// InfrastructureProvider allows to specify the infrastructure provider to be used when looking for
4851
// cluster templates.
4952
// If not set, clusterctl will look at the infrastructure provider installed in the management cluster;
@@ -81,11 +84,12 @@ type QuickStartSpecInput struct {
8184
// NOTE: This test works with Clusters with and without ClusterClass.
8285
func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput) {
8386
var (
84-
specName = "quick-start"
85-
input QuickStartSpecInput
86-
namespace *corev1.Namespace
87-
cancelWatches context.CancelFunc
88-
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
87+
specName = "quick-start"
88+
input QuickStartSpecInput
89+
namespace *corev1.Namespace
90+
clusterClassNamespace *corev1.Namespace
91+
cancelWatches context.CancelFunc
92+
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
8993
)
9094

9195
BeforeEach(func() {
@@ -100,6 +104,12 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)
100104

101105
// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events.
102106
namespace, cancelWatches = framework.SetupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated)
107+
108+
if input.ClassNamespace != nil {
109+
clusterClassNamespace = framework.CreateNamespace(ctx, framework.CreateNamespaceInput{Creator: input.BootstrapClusterProxy.GetClient(), Name: *input.ClassNamespace}, "40s", "10s")
110+
Expect(clusterClassNamespace).ToNot(BeNil(), "Failed to create namespace %q", *input.ClassNamespace)
111+
}
112+
103113
clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult)
104114
})
105115

@@ -130,11 +140,19 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)
130140
if input.ClusterName != nil {
131141
clusterName = *input.ClusterName
132142
}
143+
144+
variables := map[string]string{}
145+
if input.ClassNamespace != nil {
146+
variables["CLUSTER_CLASS_NAMESPACE"] = *input.ClassNamespace
147+
}
148+
149+
By("Creating a cluster referencing a clusterClass from another namespace")
133150
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
134151
ClusterProxy: input.BootstrapClusterProxy,
135152
ConfigCluster: clusterctl.ConfigClusterInput{
136153
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", input.BootstrapClusterProxy.GetName()),
137154
ClusterctlConfigPath: input.ClusterctlConfigPath,
155+
ClusterctlVariables: variables,
138156
KubeconfigPath: input.BootstrapClusterProxy.GetKubeconfigPath(),
139157
InfrastructureProvider: infrastructureProvider,
140158
Flavor: flavor,
@@ -154,11 +172,18 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)
154172
}
155173
},
156174
}, clusterResources)
175+
157176
By("PASSED!")
158177
})
159178

160179
AfterEach(func() {
161180
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
162181
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
182+
if input.ClassNamespace != nil {
183+
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
184+
Deleter: input.BootstrapClusterProxy.GetClient(),
185+
Name: clusterClassNamespace.Name,
186+
})
187+
}
163188
})
164189
}

test/e2e/quick_start_test.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ limitations under the License.
2020
package e2e
2121

2222
import (
23+
"fmt"
24+
2325
. "github.com/onsi/ginkgo/v2"
2426
. "github.com/onsi/gomega"
2527
"k8s.io/utils/ptr"
2628

2729
clusterctlcluster "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
2830
"sigs.k8s.io/cluster-api/test/framework"
2931
"sigs.k8s.io/cluster-api/test/framework/kubetest"
32+
"sigs.k8s.io/cluster-api/util"
3033
)
3134

3235
var _ = Describe("When following the Cluster API quick-start", func() {
@@ -125,17 +128,16 @@ var _ = Describe("When following the Cluster API quick-start with ClusterClass [
125128
})
126129

127130
var _ = Describe("When following the Cluster API quick-start with a cross-ns referenced ClusterClass [PR-Blocking] [ClusterClass]", func() {
128-
CrossNsSpecQuickstart(ctx, func() CrossNsSpecInput {
129-
return CrossNsSpecInput{
130-
QuickStartSpecInput: QuickStartSpecInput{
131-
E2EConfig: e2eConfig,
132-
ClusterctlConfigPath: clusterctlConfigPath,
133-
BootstrapClusterProxy: bootstrapClusterProxy,
134-
ArtifactFolder: artifactFolder,
135-
SkipCleanup: skipCleanup,
136-
Flavor: ptr.To("cross-ns-topology"),
137-
InfrastructureProvider: ptr.To("docker"),
138-
},
131+
QuickStartSpec(ctx, func() QuickStartSpecInput {
132+
return QuickStartSpecInput{
133+
E2EConfig: e2eConfig,
134+
ClusterctlConfigPath: clusterctlConfigPath,
135+
BootstrapClusterProxy: bootstrapClusterProxy,
136+
ArtifactFolder: artifactFolder,
137+
SkipCleanup: skipCleanup,
138+
Flavor: ptr.To("topology"),
139+
InfrastructureProvider: ptr.To("docker"),
140+
ClassNamespace: ptr.To(fmt.Sprintf("quick-start-%s", util.RandomString(6))),
139141
}
140142
})
141143
})

test/framework/clusterctl/clusterctl_helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func ApplyCustomClusterTemplateAndWait(ctx context.Context, input ApplyCustomClu
433433
if result.Cluster.Spec.Topology != nil {
434434
result.ClusterClass = framework.GetClusterClassByName(ctx, framework.GetClusterClassByNameInput{
435435
Getter: input.ClusterProxy.GetClient(),
436-
Namespace: result.Cluster.GetInfrastructureNamespace(),
436+
Namespace: result.Cluster.GetClassKey().Namespace,
437437
Name: result.Cluster.Spec.Topology.Class,
438438
})
439439
}

0 commit comments

Comments
 (0)