@@ -95,6 +95,9 @@ type ClusterUpgradeWithRuntimeSDKSpecInput struct {
95
95
ExtensionServiceNamespace string
96
96
// ExtensionServiceName is the name of the service to configure in the test-namespace scoped ExtensionConfig.
97
97
ExtensionServiceName string
98
+
99
+ // ClassNamespace is an optional class namespace reference, configuring cross-namespace cluster class reference
100
+ ClassNamespace bool
98
101
}
99
102
100
103
// ClusterUpgradeWithRuntimeSDKSpec implements a spec that upgrades a cluster and runs the Kubernetes conformance suite.
@@ -109,9 +112,9 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
109
112
)
110
113
111
114
var (
112
- input ClusterUpgradeWithRuntimeSDKSpecInput
113
- namespace * corev1.Namespace
114
- cancelWatches context.CancelFunc
115
+ input ClusterUpgradeWithRuntimeSDKSpecInput
116
+ namespace , infraNamespace * corev1.Namespace
117
+ cancelWatches , cancelInfraWatches context.CancelFunc
115
118
116
119
controlPlaneMachineCount int64
117
120
workerMachineCount int64
@@ -148,6 +151,7 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
148
151
149
152
// Set up a Namespace where to host objects for this spec and create a watcher for the Namespace events.
150
153
namespace , cancelWatches = framework .SetupSpecNamespace (ctx , specName , input .BootstrapClusterProxy , input .ArtifactFolder , input .PostNamespaceCreated )
154
+ infraNamespace , cancelInfraWatches = framework .SetupSpecNamespace (ctx , specName , input .BootstrapClusterProxy , input .ArtifactFolder , input .PostNamespaceCreated )
151
155
clusterName = fmt .Sprintf ("%s-%s" , specName , util .RandomString (6 ))
152
156
clusterResources = new (clusterctl.ApplyClusterTemplateAndWaitResult )
153
157
})
@@ -162,7 +166,7 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
162
166
By ("Deploy Test Extension ExtensionConfig" )
163
167
164
168
Expect (input .BootstrapClusterProxy .GetClient ().Create (ctx ,
165
- extensionConfig (specName , namespace . Name , input .ExtensionServiceNamespace , input .ExtensionServiceName ))).
169
+ extensionConfig (specName , input .ExtensionServiceNamespace , input .ExtensionServiceName , namespace . Name , infraNamespace . Name ))).
166
170
To (Succeed (), "Failed to create the extension config" )
167
171
168
172
By ("Creating a workload cluster; creation waits for BeforeClusterCreateHook to gate the operation" )
@@ -177,6 +181,11 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
177
181
infrastructureProvider = * input .InfrastructureProvider
178
182
}
179
183
184
+ variables := map [string ]string {}
185
+ if input .ClassNamespace {
186
+ variables ["CLUSTER_CLASS_NAMESPACE" ] = infraNamespace .Name
187
+ }
188
+
180
189
clusterctl .ApplyClusterTemplateAndWait (ctx , clusterctl.ApplyClusterTemplateAndWaitInput {
181
190
ClusterProxy : input .BootstrapClusterProxy ,
182
191
ConfigCluster : clusterctl.ConfigClusterInput {
@@ -190,6 +199,7 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
190
199
KubernetesVersion : input .E2EConfig .GetVariable (KubernetesVersionUpgradeFrom ),
191
200
ControlPlaneMachineCount : ptr.To [int64 ](controlPlaneMachineCount ),
192
201
WorkerMachineCount : ptr.To [int64 ](workerMachineCount ),
202
+ ClusterctlVariables : variables ,
193
203
},
194
204
PreWaitForCluster : func () {
195
205
beforeClusterCreateTestHandler (ctx ,
@@ -304,7 +314,7 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
304
314
if ! input .SkipCleanup {
305
315
// Delete the extensionConfig first to ensure the BeforeDeleteCluster hook doesn't block deletion.
306
316
Eventually (func () error {
307
- return input .BootstrapClusterProxy .GetClient ().Delete (ctx , extensionConfig (specName , namespace . Name , input .ExtensionServiceNamespace , input .ExtensionServiceName ))
317
+ return input .BootstrapClusterProxy .GetClient ().Delete (ctx , extensionConfig (specName , input .ExtensionServiceNamespace , input .ExtensionServiceName ))
308
318
}, 10 * time .Second , 1 * time .Second ).Should (Succeed (), "delete extensionConfig failed" )
309
319
310
320
Byf ("Deleting cluster %s" , klog .KObj (clusterResources .Cluster ))
@@ -322,8 +332,17 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
322
332
Deleter : input .BootstrapClusterProxy .GetClient (),
323
333
Name : namespace .Name ,
324
334
})
335
+
336
+ if input .ClassNamespace {
337
+ Byf ("Deleting namespace used for optionally hosting the %q infrastructure spec" , specName )
338
+ framework .DeleteNamespace (ctx , framework.DeleteNamespaceInput {
339
+ Deleter : input .BootstrapClusterProxy .GetClient (),
340
+ Name : infraNamespace .Name ,
341
+ })
342
+ }
325
343
}
326
344
cancelWatches ()
345
+ cancelInfraWatches ()
327
346
})
328
347
}
329
348
@@ -429,7 +448,7 @@ func machineSetPreflightChecksTestHandler(ctx context.Context, c client.Client,
429
448
// We make sure this cluster-wide object does not conflict with others by using a random generated
430
449
// name and a NamespaceSelector selecting on the namespace of the current test.
431
450
// Thus, this object is "namespaced" to the current test even though it's a cluster-wide object.
432
- func extensionConfig (name , namespace , extensionServiceNamespace , extensionServiceName string ) * runtimev1.ExtensionConfig {
451
+ func extensionConfig (name , extensionServiceNamespace , extensionServiceName string , namespaces ... string ) * runtimev1.ExtensionConfig {
433
452
return & runtimev1.ExtensionConfig {
434
453
ObjectMeta : metav1.ObjectMeta {
435
454
// Note: We have to use a constant name here as we have to be able to reference it in the ClusterClass
@@ -454,7 +473,7 @@ func extensionConfig(name, namespace, extensionServiceNamespace, extensionServic
454
473
{
455
474
Key : "kubernetes.io/metadata.name" ,
456
475
Operator : metav1 .LabelSelectorOpIn ,
457
- Values : [] string { namespace } ,
476
+ Values : namespaces ,
458
477
},
459
478
},
460
479
},
0 commit comments