@@ -51,8 +51,8 @@ import (
51
51
52
52
var hookResponsesConfigMapNameSuffix = "test-extension-hookresponses"
53
53
54
- func hookResponsesConfigMapName (clusterName string ) string {
55
- return fmt .Sprintf ("%s-%s" , clusterName , hookResponsesConfigMapNameSuffix )
54
+ func hookResponsesConfigMapName (clusterName , extensionConfigName string ) string {
55
+ return fmt .Sprintf ("%s-%s-%s " , clusterName , extensionConfigName , hookResponsesConfigMapNameSuffix )
56
56
}
57
57
58
58
// ClusterUpgradeWithRuntimeSDKSpecInput is the input for clusterUpgradeWithRuntimeSDKSpec.
@@ -229,6 +229,7 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
229
229
beforeClusterCreateTestHandler (ctx ,
230
230
input .BootstrapClusterProxy .GetClient (),
231
231
clusterRef ,
232
+ input .ExtensionConfigName ,
232
233
input .E2EConfig .GetIntervals (specName , "wait-cluster" ))
233
234
},
234
235
PostMachinesProvisioned : func () {
@@ -295,17 +296,20 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
295
296
beforeClusterUpgradeTestHandler (ctx ,
296
297
input .BootstrapClusterProxy .GetClient (),
297
298
clusterRef ,
299
+ input .ExtensionConfigName ,
298
300
input .E2EConfig .MustGetVariable (KubernetesVersionUpgradeTo ),
299
301
input .E2EConfig .GetIntervals (specName , "wait-machine-upgrade" ))
300
302
},
301
303
PreWaitForWorkersToBeUpgraded : func () {
302
304
machineSetPreflightChecksTestHandler (ctx ,
303
305
input .BootstrapClusterProxy .GetClient (),
304
- clusterRef )
306
+ clusterRef ,
307
+ input .ExtensionConfigName )
305
308
306
309
afterControlPlaneUpgradeTestHandler (ctx ,
307
310
input .BootstrapClusterProxy .GetClient (),
308
311
clusterRef ,
312
+ input .ExtensionConfigName ,
309
313
input .E2EConfig .MustGetVariable (KubernetesVersionUpgradeTo ),
310
314
input .E2EConfig .GetIntervals (specName , "wait-machine-upgrade" ))
311
315
},
@@ -329,11 +333,11 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
329
333
By ("Dumping resources and deleting the workload cluster; deletion waits for BeforeClusterDeleteHook to gate the operation" )
330
334
dumpAndDeleteCluster (ctx , input .BootstrapClusterProxy , namespace .Name , clusterName , input .ArtifactFolder )
331
335
332
- beforeClusterDeleteHandler (ctx , input .BootstrapClusterProxy .GetClient (), clusterRef , input .E2EConfig .GetIntervals (specName , "wait-delete-cluster" ))
336
+ beforeClusterDeleteHandler (ctx , input .BootstrapClusterProxy .GetClient (), clusterRef , input .ExtensionConfigName , input . E2EConfig .GetIntervals (specName , "wait-delete-cluster" ))
333
337
334
338
By ("Checking all lifecycle hooks have been called" )
335
339
// Assert that each hook has been called and returned "Success" during the test.
336
- Expect (checkLifecycleHookResponses (ctx , input .BootstrapClusterProxy .GetClient (), clusterRef , map [string ]string {
340
+ Expect (checkLifecycleHookResponses (ctx , input .BootstrapClusterProxy .GetClient (), clusterRef , input . ExtensionConfigName , map [string ]string {
337
341
"BeforeClusterCreate" : "Status: Success, RetryAfterSeconds: 0" ,
338
342
"BeforeClusterUpgrade" : "Status: Success, RetryAfterSeconds: 0" ,
339
343
"BeforeClusterDelete" : "Status: Success, RetryAfterSeconds: 0" ,
@@ -388,11 +392,11 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
388
392
// should be blocked by the AfterControlPlaneUpgrade hook.
389
393
// Test the MachineSet preflight checks by scaling up the MachineDeployment. The creation on the new Machine
390
394
// should be blocked because the preflight checks should not pass (kubeadm version skew preflight check should fail).
391
- func machineSetPreflightChecksTestHandler (ctx context.Context , c client.Client , clusterRef types.NamespacedName ) {
395
+ func machineSetPreflightChecksTestHandler (ctx context.Context , c client.Client , clusterRef types.NamespacedName , extensionConfigName string ) {
392
396
// Verify that the hook is called and the topology reconciliation is blocked.
393
397
hookName := "AfterControlPlaneUpgrade"
394
398
Eventually (func () error {
395
- if err := checkLifecycleHooksCalledAtLeastOnce (ctx , c , clusterRef , []string {hookName }); err != nil {
399
+ if err := checkLifecycleHooksCalledAtLeastOnce (ctx , c , clusterRef , extensionConfigName , []string {hookName }); err != nil {
396
400
return err
397
401
}
398
402
@@ -505,6 +509,7 @@ func extensionConfig(name, extensionServiceNamespace, extensionServiceName strin
505
509
},
506
510
},
507
511
Settings : map [string ]string {
512
+ "extensionConfigName" : name ,
508
513
"defaultAllHandlersToBlocking" : strconv .FormatBool (defaultAllHandlersToBlocking ),
509
514
},
510
515
},
@@ -526,12 +531,12 @@ func extensionConfig(name, extensionServiceNamespace, extensionServiceName strin
526
531
527
532
// Check that each hook in hooks has been called at least once by checking if its actualResponseStatus is in the hook response configmap.
528
533
// If the provided hooks have both keys and values check that the values match those in the hook response configmap.
529
- func checkLifecycleHookResponses (ctx context.Context , c client.Client , cluster types.NamespacedName , expectedHookResponses map [string ]string ) error {
530
- responseData := getLifecycleHookResponsesFromConfigMap (ctx , c , cluster )
534
+ func checkLifecycleHookResponses (ctx context.Context , c client.Client , cluster types.NamespacedName , extensionConfigName string , expectedHookResponses map [string ]string ) error {
535
+ responseData := getLifecycleHookResponsesFromConfigMap (ctx , c , cluster , extensionConfigName )
531
536
for hookName , expectedResponse := range expectedHookResponses {
532
537
actualResponse , ok := responseData [hookName + "-actualResponseStatus" ]
533
538
if ! ok {
534
- return errors .Errorf ("hook %s call not recorded in configMap %s" , hookName , klog .KRef (cluster .Namespace , hookResponsesConfigMapName (cluster .Name )))
539
+ return errors .Errorf ("hook %s call not recorded in configMap %s" , hookName , klog .KRef (cluster .Namespace , hookResponsesConfigMapName (cluster .Name , extensionConfigName )))
535
540
}
536
541
if expectedResponse != "" && expectedResponse != actualResponse {
537
542
return errors .Errorf ("hook %s was expected to be %s in configMap got %s" , hookName , expectedResponse , actualResponse )
@@ -541,29 +546,29 @@ func checkLifecycleHookResponses(ctx context.Context, c client.Client, cluster t
541
546
}
542
547
543
548
// Check that each hook in expectedHooks has been called at least once by checking if its actualResponseStatus is in the hook response configmap.
544
- func checkLifecycleHooksCalledAtLeastOnce (ctx context.Context , c client.Client , cluster types.NamespacedName , expectedHooks []string ) error {
545
- responseData := getLifecycleHookResponsesFromConfigMap (ctx , c , cluster )
549
+ func checkLifecycleHooksCalledAtLeastOnce (ctx context.Context , c client.Client , cluster types.NamespacedName , extensionConfigName string , expectedHooks []string ) error {
550
+ responseData := getLifecycleHookResponsesFromConfigMap (ctx , c , cluster , extensionConfigName )
546
551
for _ , hookName := range expectedHooks {
547
552
if _ , ok := responseData [hookName + "-actualResponseStatus" ]; ! ok {
548
- return errors .Errorf ("hook %s call not recorded in configMap %s" , hookName , klog .KRef (cluster .Namespace , hookResponsesConfigMapName (cluster .Name )))
553
+ return errors .Errorf ("hook %s call not recorded in configMap %s" , hookName , klog .KRef (cluster .Namespace , hookResponsesConfigMapName (cluster .Name , extensionConfigName )))
549
554
}
550
555
}
551
556
return nil
552
557
}
553
558
554
- func getLifecycleHookResponsesFromConfigMap (ctx context.Context , c client.Client , cluster types.NamespacedName ) map [string ]string {
559
+ func getLifecycleHookResponsesFromConfigMap (ctx context.Context , c client.Client , cluster types.NamespacedName , extensionConfigName string ) map [string ]string {
555
560
configMap := & corev1.ConfigMap {}
556
561
Eventually (func () error {
557
- return c .Get (ctx , client.ObjectKey {Namespace : cluster .Namespace , Name : hookResponsesConfigMapName (cluster .Name )}, configMap )
562
+ return c .Get (ctx , client.ObjectKey {Namespace : cluster .Namespace , Name : hookResponsesConfigMapName (cluster .Name , extensionConfigName )}, configMap )
558
563
}).Should (Succeed (), "Failed to get the hook response configmap" )
559
564
return configMap .Data
560
565
}
561
566
562
567
// beforeClusterCreateTestHandler calls runtimeHookTestHandler with a blockedCondition function which returns false if
563
568
// the Cluster has entered ClusterPhaseProvisioned.
564
- func beforeClusterCreateTestHandler (ctx context.Context , c client.Client , cluster types.NamespacedName , intervals []interface {}) {
569
+ func beforeClusterCreateTestHandler (ctx context.Context , c client.Client , cluster types.NamespacedName , extensionConfigName string , intervals []interface {}) {
565
570
hookName := "BeforeClusterCreate"
566
- runtimeHookTestHandler (ctx , c , cluster , hookName , true , func () bool {
571
+ runtimeHookTestHandler (ctx , c , cluster , hookName , extensionConfigName , true , func () bool {
567
572
blocked := true
568
573
// This hook should block the Cluster from entering the "Provisioned" state.
569
574
cluster := framework .GetClusterByName (ctx ,
@@ -638,9 +643,9 @@ func beforeClusterUpgradeAnnotationIsBlocking(ctx context.Context, c client.Clie
638
643
639
644
// beforeClusterUpgradeTestHandler calls runtimeHookTestHandler with a blocking function which returns false if
640
645
// any of the machines in the control plane has been updated to the target Kubernetes version.
641
- func beforeClusterUpgradeTestHandler (ctx context.Context , c client.Client , cluster types.NamespacedName , toVersion string , intervals []interface {}) {
646
+ func beforeClusterUpgradeTestHandler (ctx context.Context , c client.Client , cluster types.NamespacedName , extensionConfigName string , toVersion string , intervals []interface {}) {
642
647
hookName := "BeforeClusterUpgrade"
643
- runtimeHookTestHandler (ctx , c , cluster , hookName , true , func () bool {
648
+ runtimeHookTestHandler (ctx , c , cluster , hookName , extensionConfigName , true , func () bool {
644
649
var blocked = true
645
650
646
651
controlPlaneMachines := framework .GetControlPlaneMachinesByCluster (ctx ,
@@ -656,9 +661,9 @@ func beforeClusterUpgradeTestHandler(ctx context.Context, c client.Client, clust
656
661
657
662
// afterControlPlaneUpgradeTestHandler calls runtimeHookTestHandler with a blocking function which returns false if any
658
663
// MachineDeployment in the Cluster has upgraded to the target Kubernetes version.
659
- func afterControlPlaneUpgradeTestHandler (ctx context.Context , c client.Client , cluster types.NamespacedName , version string , intervals []interface {}) {
664
+ func afterControlPlaneUpgradeTestHandler (ctx context.Context , c client.Client , cluster types.NamespacedName , extensionConfigName string , version string , intervals []interface {}) {
660
665
hookName := "AfterControlPlaneUpgrade"
661
- runtimeHookTestHandler (ctx , c , cluster , hookName , true , func () bool {
666
+ runtimeHookTestHandler (ctx , c , cluster , hookName , extensionConfigName , true , func () bool {
662
667
var blocked = true
663
668
664
669
mds := framework .GetMachineDeploymentsByCluster (ctx ,
@@ -675,9 +680,9 @@ func afterControlPlaneUpgradeTestHandler(ctx context.Context, c client.Client, c
675
680
676
681
// beforeClusterDeleteHandler calls runtimeHookTestHandler with a blocking function which returns false if the Cluster
677
682
// can not be found in the API server.
678
- func beforeClusterDeleteHandler (ctx context.Context , c client.Client , cluster types.NamespacedName , intervals []interface {}) {
683
+ func beforeClusterDeleteHandler (ctx context.Context , c client.Client , cluster types.NamespacedName , extensionConfigName string , intervals []interface {}) {
679
684
hookName := "BeforeClusterDelete"
680
- runtimeHookTestHandler (ctx , c , cluster , hookName , false , func () bool {
685
+ runtimeHookTestHandler (ctx , c , cluster , hookName , extensionConfigName , false , func () bool {
681
686
var blocked = true
682
687
683
688
// If the Cluster is not found it has been deleted and the hook is unblocked.
@@ -696,12 +701,12 @@ func beforeClusterDeleteHandler(ctx context.Context, c client.Client, cluster ty
696
701
//
697
702
// Note: runtimeHookTestHandler assumes that the hook passed to it is currently returning a blocking response.
698
703
// Updating the response to be non-blocking happens inline in the function.
699
- func runtimeHookTestHandler (ctx context.Context , c client.Client , cluster types.NamespacedName , hookName string , withTopologyReconciledCondition bool , blockingCondition func () bool , intervals []interface {}) {
704
+ func runtimeHookTestHandler (ctx context.Context , c client.Client , cluster types.NamespacedName , hookName , extensionConfigName string , withTopologyReconciledCondition bool , blockingCondition func () bool , intervals []interface {}) {
700
705
log .Logf ("Blocking with %s hook for 60 seconds after the hook has been called for the first time" , hookName )
701
706
702
707
// Check that the LifecycleHook has been called at least once and - when required - that the TopologyReconciled condition is a Failure.
703
708
Eventually (func () error {
704
- if err := checkLifecycleHooksCalledAtLeastOnce (ctx , c , cluster , []string {hookName }); err != nil {
709
+ if err := checkLifecycleHooksCalledAtLeastOnce (ctx , c , cluster , extensionConfigName , []string {hookName }); err != nil {
705
710
return err
706
711
}
707
712
@@ -726,7 +731,7 @@ func runtimeHookTestHandler(ctx context.Context, c client.Client, cluster types.
726
731
// Patch the ConfigMap to set the hook response to "Success".
727
732
Byf ("Setting %s response to Status:Success to unblock the reconciliation" , hookName )
728
733
729
- configMap := & corev1.ConfigMap {ObjectMeta : metav1.ObjectMeta {Name : hookResponsesConfigMapName (cluster .Name ), Namespace : cluster .Namespace }}
734
+ configMap := & corev1.ConfigMap {ObjectMeta : metav1.ObjectMeta {Name : hookResponsesConfigMapName (cluster .Name , extensionConfigName ), Namespace : cluster .Namespace }}
730
735
Eventually (func () error {
731
736
return c .Get (ctx , util .ObjectKey (configMap ), configMap )
732
737
}).Should (Succeed (), "Failed to get ConfigMap %s" , klog .KObj (configMap ))
0 commit comments