@@ -42,6 +42,7 @@ import (
4242 "sigs.k8s.io/cluster-api/controllers/external"
4343 "sigs.k8s.io/cluster-api/exp/topology/desiredstate"
4444 "sigs.k8s.io/cluster-api/internal/contract"
45+ "sigs.k8s.io/cluster-api/internal/hooks"
4546 "sigs.k8s.io/cluster-api/test/e2e/internal/log"
4647 "sigs.k8s.io/cluster-api/test/framework"
4748 "sigs.k8s.io/cluster-api/test/framework/clusterctl"
@@ -451,6 +452,14 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
451452
452453 beforeClusterDeleteHandler (ctx , input .BootstrapClusterProxy .GetClient (), clusterResources .Cluster , input .ExtensionConfigName )
453454
455+ Byf ("Waiting for cluster to be deleted" )
456+ framework .WaitForClusterDeleted (ctx , framework.WaitForClusterDeletedInput {
457+ ClusterProxy : input .BootstrapClusterProxy ,
458+ ClusterctlConfigPath : input .ClusterctlConfigPath ,
459+ Cluster : clusterResources .Cluster ,
460+ ArtifactFolder : input .ArtifactFolder ,
461+ }, input .E2EConfig .GetIntervals (specName , "wait-delete-cluster" )... )
462+
454463 By ("Checking all lifecycle hooks have been called" )
455464 // Assert that each hook has been called and returned "Success" during the test.
456465 expectedHooks := map [string ]string {
@@ -1037,12 +1046,19 @@ func afterWorkersUpgradeTestHandler(ctx context.Context, c client.Client, cluste
10371046// cannot be found in the API server.
10381047func beforeClusterDeleteHandler (ctx context.Context , c client.Client , cluster * clusterv1.Cluster , extensionConfigName string ) {
10391048 hookName := "BeforeClusterDelete"
1049+ clusterObjectKey := client .ObjectKeyFromObject (cluster )
10401050
10411051 // for BeforeClusterDelete, the hook is blocking if Get Cluster keep returning something different from IsNotFound error.
10421052 isBlockingDelete := func () bool {
10431053 var blocked = true
10441054
1045- if apierrors .IsNotFound (c .Get (ctx , client.ObjectKey {Name : cluster .Name , Namespace : cluster .Namespace }, & clusterv1.Cluster {})) {
1055+ // BeforeClusterDelete is unblocked either if the Cluster is gone or if OkToDeleteAnnotation is set.
1056+ cluster := & clusterv1.Cluster {}
1057+ if err := c .Get (ctx , clusterObjectKey , cluster ); err != nil {
1058+ if apierrors .IsNotFound (err ) {
1059+ blocked = false
1060+ }
1061+ } else if hooks .IsOkToDelete (cluster ) {
10461062 blocked = false
10471063 }
10481064 return blocked
0 commit comments