@@ -56,6 +56,8 @@ import (
5656 crclient "sigs.k8s.io/controller-runtime/pkg/client"
5757
5858 infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
59+ "sigs.k8s.io/cluster-api-provider-openstack/internal/util/ssa"
60+ "sigs.k8s.io/cluster-api-provider-openstack/pkg/generated/applyconfiguration/api/v1beta1"
5961 "sigs.k8s.io/cluster-api-provider-openstack/test/e2e/shared"
6062)
6163
@@ -1014,20 +1016,48 @@ var _ = Describe("e2e tests [PR-Blocking]", func() {
10141016 serverToDelete := allServers [controlPlaneMachines [0 ].Spec .InfrastructureRef .Name ]
10151017 err = shared .DeleteOpenStackServer (ctx , e2eCtx , serverToDelete .ID )
10161018 Expect (err ).NotTo (HaveOccurred ())
1019+
10171020 shared .Logf ("Waiting for the OpenStackMachine to have a condition that the server has been unexpectedly deleted" )
1018- Eventually (func () bool {
1021+ retries := 0
1022+ Eventually (func () (clusterv1.Condition , error ) {
1023+ k8sClient := e2eCtx .Environment .BootstrapClusterProxy .GetClient ()
1024+
10191025 openStackMachine := & infrav1.OpenStackMachine {}
1020- err := e2eCtx . Environment . BootstrapClusterProxy . GetClient () .Get (ctx , crclient.ObjectKey {Name : controlPlaneMachines [0 ].Name , Namespace : controlPlaneMachines [0 ].Namespace }, openStackMachine )
1026+ err := k8sClient .Get (ctx , crclient.ObjectKey {Name : controlPlaneMachines [0 ].Name , Namespace : controlPlaneMachines [0 ].Namespace }, openStackMachine )
10211027 if err != nil {
1022- return false
1028+ return clusterv1. Condition {}, err
10231029 }
10241030 for _ , condition := range openStackMachine .Status .Conditions {
1025- if condition .Type == infrav1 .InstanceReadyCondition && condition . Status == corev1 . ConditionFalse && condition . Reason == infrav1 . InstanceDeletedReason && condition . Message == "server has been unexpectedly deleted" {
1026- return true
1031+ if condition .Type == infrav1 .InstanceReadyCondition {
1032+ return condition , nil
10271033 }
10281034 }
1029- return false
1030- }, e2eCtx .E2EConfig .GetIntervals (specName , "wait-delete-machine" )... ).Should (BeTrue ())
1035+
1036+ // Make some non-functional change to the object which will
1037+ // cause CAPO to reconcile it, otherwise we won't notice the
1038+ // server is gone until the configured controller-runtime
1039+ // resync.
1040+ retries ++
1041+ applyConfig := v1beta1 .OpenStackMachine (openStackMachine .Name , openStackMachine .Namespace ).
1042+ WithAnnotations (map [string ]string {
1043+ "e2e-test-retries" : fmt .Sprintf ("%d" , retries ),
1044+ })
1045+ err = k8sClient .Patch (ctx , openStackMachine , ssa .ApplyConfigPatch (applyConfig ), crclient .ForceOwnership , crclient .FieldOwner ("capo-e2e" ))
1046+ if err != nil {
1047+ return clusterv1.Condition {}, err
1048+ }
1049+
1050+ return clusterv1.Condition {}, errors .New ("condition InstanceReadyCondition not found" )
1051+ }, time .Minute * 3 , time .Second * 10 ).Should (MatchFields (
1052+ IgnoreExtras ,
1053+ Fields {
1054+ "Type" : Equal (infrav1 .InstanceReadyCondition ),
1055+ "Status" : Equal (corev1 .ConditionFalse ),
1056+ "Reason" : Equal (infrav1 .InstanceDeletedReason ),
1057+ "Message" : Equal (infrav1 .ServerUnexpectedDeletedMessage ),
1058+ "Severity" : Equal (clusterv1 .ConditionSeverityError ),
1059+ },
1060+ ), "OpenStackMachine should be marked not ready with InstanceDeletedReason" )
10311061 })
10321062 })
10331063})
0 commit comments