Skip to content

Commit 12ff489

Browse files
committed
avoid setting FailureReason/FailureMessage
field will get deprecated in v1beta2, setting this currently avoids the Machine from being reconciled at all which does not make sense in this case because a Failed provisioningState is not necessarily terminal
1 parent 8a1f692 commit 12ff489

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

exp/controllers/azuremachinepoolmachine_controller.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ func (ampmr *AzureMachinePoolMachineController) reconcileNormal(ctx context.Cont
294294
switch state {
295295
case infrav1.Failed:
296296
ampmr.Recorder.Eventf(machineScope.AzureMachinePoolMachine, corev1.EventTypeWarning, "FailedVMState", "Azure scale set VM is in failed state")
297-
machineScope.SetFailureReason(azure.UpdateError)
298-
machineScope.SetFailureMessage(errors.Errorf("Azure VM state is %s", state))
299297
case infrav1.Deleting:
300298
log.V(4).Info("deleting machine because state is Deleting", "machine", machineScope.Name())
301299
if err := ampmr.Client.Delete(ctx, machineScope.Machine); err != nil {

exp/controllers/azuremachinepoolmachine_controller_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/runtime"
2929
"k8s.io/apimachinery/pkg/types"
30+
"k8s.io/client-go/tools/record"
3031
"k8s.io/utils/ptr"
3132
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3233
expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
@@ -60,6 +61,26 @@ func TestAzureMachinePoolMachineReconciler_Reconcile(t *testing.T) {
6061
g.Expect(err).NotTo(HaveOccurred())
6162
},
6263
},
64+
{
65+
Name: "should not set failure properties if VMSS VM has state Failed",
66+
Setup: func(cb *fake.ClientBuilder, reconciler *mock_azure.MockReconcilerMockRecorder) {
67+
objects := getReadyMachinePoolMachineClusterObjects(false, ptr.To(infrav1.Failed))
68+
reconciler.Reconcile(gomock2.AContext()).Return(nil)
69+
cb.WithObjects(objects...)
70+
},
71+
Verify: func(g *WithT, c client.Client, result ctrl.Result, err error) {
72+
g.Expect(err).NotTo(HaveOccurred())
73+
74+
ampm := &infrav1exp.AzureMachinePoolMachine{}
75+
err = c.Get(context.Background(), types.NamespacedName{
76+
Name: "ampm1",
77+
Namespace: "default",
78+
}, ampm)
79+
g.Expect(err).NotTo(HaveOccurred())
80+
g.Expect(ampm.Status.FailureReason).To(BeNil())
81+
g.Expect(ampm.Status.FailureMessage).To(BeNil())
82+
},
83+
},
6384
{
6485
Name: "should successfully delete",
6586
Setup: func(cb *fake.ClientBuilder, reconciler *mock_azure.MockReconcilerMockRecorder) {
@@ -136,7 +157,7 @@ func TestAzureMachinePoolMachineReconciler_Reconcile(t *testing.T) {
136157

137158
c.Setup(cb, reconciler.EXPECT())
138159
cl := cb.Build()
139-
controller := NewAzureMachinePoolMachineController(cl, nil, reconcilerutils.Timeouts{}, "foo", azure.NewCredentialCache())
160+
controller := NewAzureMachinePoolMachineController(cl, record.NewFakeRecorder(1), reconcilerutils.Timeouts{}, "foo", azure.NewCredentialCache())
140161
controller.reconcilerFactory = func(_ *scope.MachinePoolMachineScope) (azure.Reconciler, error) {
141162
return reconciler, nil
142163
}

0 commit comments

Comments
 (0)