@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"os"
23
23
"path/filepath"
24
+ "strconv"
24
25
"strings"
25
26
"time"
26
27
@@ -90,9 +91,15 @@ type ClusterUpgradeWithRuntimeSDKSpecInput struct {
90
91
// If not specified, this is a no-op.
91
92
PostUpgrade func (managementClusterProxy framework.ClusterProxy , workloadClusterNamespace , workloadClusterName string )
92
93
94
+ // ExtensionConfigName is the name of the ExtensionConfig. Defaults to "k8s-upgrade-with-runtimesdk".
95
+ // This value is provided to clusterctl as "EXTENSION_CONFIG_NAME" variable and can be used to template the
96
+ // name of the ExtensionConfig into the ClusterClass.
97
+ ExtensionConfigName string
98
+
93
99
// ExtensionServiceNamespace is the namespace where the service for the Runtime SDK is located
94
100
// and is used to configure in the test-namespace scoped ExtensionConfig.
95
101
ExtensionServiceNamespace string
102
+
96
103
// ExtensionServiceName is the name of the service to configure in the test-namespace scoped ExtensionConfig.
97
104
ExtensionServiceName string
98
105
}
@@ -133,6 +140,9 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
133
140
134
141
Expect (input .ExtensionServiceNamespace ).ToNot (BeEmpty ())
135
142
Expect (input .ExtensionServiceName ).ToNot (BeEmpty ())
143
+ if input .ExtensionConfigName == "" {
144
+ input .ExtensionConfigName = specName
145
+ }
136
146
137
147
if input .ControlPlaneMachineCount == nil {
138
148
controlPlaneMachineCount = 1
@@ -161,8 +171,11 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
161
171
162
172
By ("Deploy Test Extension ExtensionConfig" )
163
173
174
+ // In this test we are defaulting all handlers to blocking because we expect the handlers to block the
175
+ // cluster lifecycle by default. Setting defaultAllHandlersToBlocking to true enforces that the test-extension
176
+ // automatically creates the ConfigMap with blocking preloaded responses.
164
177
Expect (input .BootstrapClusterProxy .GetClient ().Create (ctx ,
165
- extensionConfig (specName , namespace . Name , input .ExtensionServiceNamespace , input .ExtensionServiceName ))).
178
+ extensionConfig (input . ExtensionConfigName , input .ExtensionServiceNamespace , input .ExtensionServiceName , true , namespace . Name ))).
166
179
To (Succeed (), "Failed to create the extension config" )
167
180
168
181
By ("Creating a workload cluster; creation waits for BeforeClusterCreateHook to gate the operation" )
@@ -177,6 +190,11 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
177
190
infrastructureProvider = * input .InfrastructureProvider
178
191
}
179
192
193
+ variables := map [string ]string {
194
+ // This is used to template the name of the ExtensionConfig into the ClusterClass.
195
+ "EXTENSION_CONFIG_NAME" : input .ExtensionConfigName ,
196
+ }
197
+
180
198
clusterctl .ApplyClusterTemplateAndWait (ctx , clusterctl.ApplyClusterTemplateAndWaitInput {
181
199
ClusterProxy : input .BootstrapClusterProxy ,
182
200
ConfigCluster : clusterctl.ConfigClusterInput {
@@ -190,6 +208,7 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
190
208
KubernetesVersion : input .E2EConfig .GetVariable (KubernetesVersionUpgradeFrom ),
191
209
ControlPlaneMachineCount : ptr.To [int64 ](controlPlaneMachineCount ),
192
210
WorkerMachineCount : ptr.To [int64 ](workerMachineCount ),
211
+ ClusterctlVariables : variables ,
193
212
},
194
213
PreWaitForCluster : func () {
195
214
beforeClusterCreateTestHandler (ctx ,
@@ -304,8 +323,8 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
304
323
if ! input .SkipCleanup {
305
324
// Delete the extensionConfig first to ensure the BeforeDeleteCluster hook doesn't block deletion.
306
325
Eventually (func () error {
307
- return input .BootstrapClusterProxy .GetClient ().Delete (ctx , extensionConfig (specName , namespace . Name , input .ExtensionServiceNamespace , input .ExtensionServiceName ))
308
- }, 10 * time .Second , 1 * time .Second ).Should (Succeed (), "delete extensionConfig failed" )
326
+ return input .BootstrapClusterProxy .GetClient ().Delete (ctx , extensionConfig (input . ExtensionConfigName , input .ExtensionServiceNamespace , input .ExtensionServiceName , true , namespace . Name ))
327
+ }, 10 * time .Second , 1 * time .Second ).Should (Succeed (), "Deleting ExtensionConfig failed" )
309
328
310
329
Byf ("Deleting cluster %s" , klog .KObj (clusterResources .Cluster ))
311
330
// While https://github.com/kubernetes-sigs/cluster-api/issues/2955 is addressed in future iterations, there is a chance
@@ -429,8 +448,8 @@ 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 {
433
- return & runtimev1.ExtensionConfig {
451
+ func extensionConfig (name , extensionServiceNamespace , extensionServiceName string , defaultAllHandlersToBlocking bool , namespaces ... string ) * runtimev1.ExtensionConfig {
452
+ cfg := & 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
436
455
// when configuring external patches.
@@ -448,25 +467,24 @@ func extensionConfig(name, namespace, extensionServiceNamespace, extensionServic
448
467
Namespace : extensionServiceNamespace ,
449
468
},
450
469
},
451
- NamespaceSelector : & metav1.LabelSelector {
452
- // Note: we are limiting the test extension to be used by the namespace where the test is run.
453
- MatchExpressions : []metav1.LabelSelectorRequirement {
454
- {
455
- Key : "kubernetes.io/metadata.name" ,
456
- Operator : metav1 .LabelSelectorOpIn ,
457
- Values : []string {namespace },
458
- },
459
- },
460
- },
461
470
Settings : map [string ]string {
462
- // In the E2E test we are defaulting all handlers to blocking because cluster_upgrade_runtimesdk_test
463
- // expects the handlers to block the cluster lifecycle by default.
464
- // Setting this value to true enforces that the test-extension automatically creates the ConfigMap with
465
- // blocking preloaded responses.
466
- "defaultAllHandlersToBlocking" : "true" ,
471
+ "defaultAllHandlersToBlocking" : strconv .FormatBool (defaultAllHandlersToBlocking ),
467
472
},
468
473
},
469
474
}
475
+ if len (namespaces ) > 0 {
476
+ cfg .Spec .NamespaceSelector = & metav1.LabelSelector {
477
+ // Note: we are limiting the test extension to be used by the namespace where the test is run.
478
+ MatchExpressions : []metav1.LabelSelectorRequirement {
479
+ {
480
+ Key : "kubernetes.io/metadata.name" ,
481
+ Operator : metav1 .LabelSelectorOpIn ,
482
+ Values : namespaces ,
483
+ },
484
+ },
485
+ }
486
+ }
487
+ return cfg
470
488
}
471
489
472
490
// Check that each hook in hooks has been called at least once by checking if its actualResponseStatus is in the hook response configmap.
0 commit comments