Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions exp/controllers/azuremachinepoolmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ func (ampmr *AzureMachinePoolMachineController) reconcileNormal(ctx context.Cont
switch state {
case infrav1.Failed:
ampmr.Recorder.Eventf(machineScope.AzureMachinePoolMachine, corev1.EventTypeWarning, "FailedVMState", "Azure scale set VM is in failed state")
machineScope.SetFailureReason(azure.UpdateError)
machineScope.SetFailureMessage(errors.Errorf("Azure VM state is %s", state))
case infrav1.Deleting:
log.V(4).Info("deleting machine because state is Deleting", "machine", machineScope.Name())
if err := ampmr.Client.Delete(ctx, machineScope.Machine); err != nil {
Expand Down
23 changes: 22 additions & 1 deletion exp/controllers/azuremachinepoolmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
Expand Down Expand Up @@ -60,6 +61,26 @@ func TestAzureMachinePoolMachineReconciler_Reconcile(t *testing.T) {
g.Expect(err).NotTo(HaveOccurred())
},
},
{
Name: "should not set failure properties if VMSS VM has state Failed",
Setup: func(cb *fake.ClientBuilder, reconciler *mock_azure.MockReconcilerMockRecorder) {
objects := getReadyMachinePoolMachineClusterObjects(false, ptr.To(infrav1.Failed))
reconciler.Reconcile(gomock2.AContext()).Return(nil)
cb.WithObjects(objects...)
},
Verify: func(g *WithT, c client.Client, result ctrl.Result, err error) {
g.Expect(err).NotTo(HaveOccurred())

ampm := &infrav1exp.AzureMachinePoolMachine{}
err = c.Get(context.Background(), types.NamespacedName{
Name: "ampm1",
Namespace: "default",
}, ampm)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ampm.Status.FailureReason).To(BeNil())
g.Expect(ampm.Status.FailureMessage).To(BeNil())
},
},
{
Name: "should successfully delete",
Setup: func(cb *fake.ClientBuilder, reconciler *mock_azure.MockReconcilerMockRecorder) {
Expand Down Expand Up @@ -136,7 +157,7 @@ func TestAzureMachinePoolMachineReconciler_Reconcile(t *testing.T) {

c.Setup(cb, reconciler.EXPECT())
cl := cb.Build()
controller := NewAzureMachinePoolMachineController(cl, nil, reconcilerutils.Timeouts{}, "foo", azure.NewCredentialCache())
controller := NewAzureMachinePoolMachineController(cl, record.NewFakeRecorder(1), reconcilerutils.Timeouts{}, "foo", azure.NewCredentialCache())
controller.reconcilerFactory = func(_ *scope.MachinePoolMachineScope) (azure.Reconciler, error) {
return reconciler, nil
}
Expand Down
Loading