@@ -56,6 +56,8 @@ import (
56
56
crclient "sigs.k8s.io/controller-runtime/pkg/client"
57
57
58
58
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"
59
61
"sigs.k8s.io/cluster-api-provider-openstack/test/e2e/shared"
60
62
)
61
63
@@ -1014,20 +1016,48 @@ var _ = Describe("e2e tests [PR-Blocking]", func() {
1014
1016
serverToDelete := allServers [controlPlaneMachines [0 ].Spec .InfrastructureRef .Name ]
1015
1017
err = shared .DeleteOpenStackServer (ctx , e2eCtx , serverToDelete .ID )
1016
1018
Expect (err ).NotTo (HaveOccurred ())
1019
+
1017
1020
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
+
1019
1025
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 )
1021
1027
if err != nil {
1022
- return false
1028
+ return clusterv1. Condition {}, err
1023
1029
}
1024
1030
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
1027
1033
}
1028
1034
}
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" )
1031
1061
})
1032
1062
})
1033
1063
})
0 commit comments