@@ -21,6 +21,7 @@ import (
2121 "fmt"
2222 "os"
2323 "path/filepath"
24+ "strconv"
2425 "strings"
2526 "time"
2627
@@ -90,9 +91,15 @@ type ClusterUpgradeWithRuntimeSDKSpecInput struct {
9091 // If not specified, this is a no-op.
9192 PostUpgrade func (managementClusterProxy framework.ClusterProxy , workloadClusterNamespace , workloadClusterName string )
9293
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+
9399 // ExtensionServiceNamespace is the namespace where the service for the Runtime SDK is located
94100 // and is used to configure in the test-namespace scoped ExtensionConfig.
95101 ExtensionServiceNamespace string
102+
96103 // ExtensionServiceName is the name of the service to configure in the test-namespace scoped ExtensionConfig.
97104 ExtensionServiceName string
98105}
@@ -133,6 +140,9 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
133140
134141 Expect (input .ExtensionServiceNamespace ).ToNot (BeEmpty ())
135142 Expect (input .ExtensionServiceName ).ToNot (BeEmpty ())
143+ if input .ExtensionConfigName == "" {
144+ input .ExtensionConfigName = specName
145+ }
136146
137147 if input .ControlPlaneMachineCount == nil {
138148 controlPlaneMachineCount = 1
@@ -161,8 +171,11 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
161171
162172 By ("Deploy Test Extension ExtensionConfig" )
163173
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.
164177 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 ))).
166179 To (Succeed (), "Failed to create the extension config" )
167180
168181 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
177190 infrastructureProvider = * input .InfrastructureProvider
178191 }
179192
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+
180198 clusterctl .ApplyClusterTemplateAndWait (ctx , clusterctl.ApplyClusterTemplateAndWaitInput {
181199 ClusterProxy : input .BootstrapClusterProxy ,
182200 ConfigCluster : clusterctl.ConfigClusterInput {
@@ -190,6 +208,7 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
190208 KubernetesVersion : input .E2EConfig .GetVariable (KubernetesVersionUpgradeFrom ),
191209 ControlPlaneMachineCount : ptr.To [int64 ](controlPlaneMachineCount ),
192210 WorkerMachineCount : ptr.To [int64 ](workerMachineCount ),
211+ ClusterctlVariables : variables ,
193212 },
194213 PreWaitForCluster : func () {
195214 beforeClusterCreateTestHandler (ctx ,
@@ -304,8 +323,8 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
304323 if ! input .SkipCleanup {
305324 // Delete the extensionConfig first to ensure the BeforeDeleteCluster hook doesn't block deletion.
306325 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" )
309328
310329 Byf ("Deleting cluster %s" , klog .KObj (clusterResources .Cluster ))
311330 // 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,
429448// We make sure this cluster-wide object does not conflict with others by using a random generated
430449// name and a NamespaceSelector selecting on the namespace of the current test.
431450// 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 {
434453 ObjectMeta : metav1.ObjectMeta {
435454 // Note: We have to use a constant name here as we have to be able to reference it in the ClusterClass
436455 // when configuring external patches.
@@ -448,25 +467,24 @@ func extensionConfig(name, namespace, extensionServiceNamespace, extensionServic
448467 Namespace : extensionServiceNamespace ,
449468 },
450469 },
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- },
461470 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 ),
467472 },
468473 },
469474 }
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
470488}
471489
472490// 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