Skip to content

Commit cd1066c

Browse files
committed
Don't set OSMachine Ready until all config is complete
With this change, an OpenStackMachine will not be marked Ready until it has been completely initialised, including setting its Addresses and adding it to the APIServer loadbalancer if required. Also fix a missing early return when the instance has been unexpectedly deleted.
1 parent 170dc4c commit cd1066c

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

controllers/openstackmachine_controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,6 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
365365
return ctrl.Result{}, err
366366
}
367367

368-
result := r.reconcileMachineState(scope, openStackMachine, machine, machineServer)
369-
if result != nil {
370-
return *result, nil
371-
}
372-
373368
computeService, err := compute.NewService(scope)
374369
if err != nil {
375370
return ctrl.Result{}, err
@@ -383,9 +378,9 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
383378
}
384379

385380
if instanceStatus == nil {
386-
msg := "server has been unexpectedly deleted"
387-
conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceDeletedReason, clusterv1.ConditionSeverityError, msg)
388-
openStackMachine.SetFailure(capoerrors.DeprecatedCAPIUpdateMachineError, errors.New(msg))
381+
conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceDeletedReason, clusterv1.ConditionSeverityError, infrav1.ServerUnexpectedDeletedMessage)
382+
openStackMachine.SetFailure(capoerrors.DeprecatedCAPIUpdateMachineError, errors.New(infrav1.ServerUnexpectedDeletedMessage)) //nolint:stylecheck // This error is not used as an error
383+
return ctrl.Result{}, nil
389384
}
390385

391386
instanceNS, err := instanceStatus.NetworkStatus()
@@ -413,6 +408,11 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
413408
conditions.MarkTrue(openStackMachine, infrav1.APIServerIngressReadyCondition)
414409
}
415410

411+
result := r.reconcileMachineState(scope, openStackMachine, machine, machineServer)
412+
if result != nil {
413+
return *result, nil
414+
}
415+
416416
scope.Logger().Info("Reconciled Machine create successfully")
417417
return ctrl.Result{}, nil
418418
}

test/e2e/suites/e2e/e2e_test.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)