Skip to content

Commit

Permalink
fix machine reconcilation bug
Browse files Browse the repository at this point in the history
Signed-off-by: Prajyot-Parab <[email protected]>
  • Loading branch information
Prajyot-Parab committed Jul 25, 2023
1 parent 84cbbac commit d584dc6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion api/v1beta2/conditions_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ const (
// InstanceErroredReason instance is in a errored state.
InstanceErroredReason = "InstanceErrored"

// InstanceNotReadyReason used when the instance is in a pending state.
// InstanceNotReadyReason used when the instance is in a not ready state.
InstanceNotReadyReason = "InstanceNotReady"

// InstanceStateUnknownReason used when the instance is in a unknown state.
InstanceStateUnknownReason = "InstanceStateUnknown"
)

const (
Expand Down
9 changes: 9 additions & 0 deletions cloud/scope/powervs_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ func (m *PowerVSMachineScope) CreateMachine() (*models.PVMInstanceReference, err
// TODO need a reasonable wrapped error.
return instanceReply, nil
}

// Check if create request has been already triggered.
// If InstanceReadyCondition is Unknown then return and wait for it to get updated.
for _, con := range m.IBMPowerVSMachine.Status.Conditions {
if con.Type == infrav1beta2.InstanceReadyCondition && con.Status == corev1.ConditionUnknown {
return nil, nil
}
}

cloudInitData, err := m.GetBootstrapData()
if err != nil {
return nil, err
Expand Down
16 changes: 16 additions & 0 deletions cloud/scope/powervs_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ func TestCreateMachinePVS(t *testing.T) {
require.Equal(t, expectedOutput.ServerName, out.ServerName)
})

t.Run("Return NIL when Machine is not present in the Instance list and Machine state is unknown", func(t *testing.T) {
g := NewWithT(t)
setup(t)
t.Cleanup(teardown)
expectedOutput := (*models.PVMInstanceReference)(nil)
scope := setupPowerVSMachineScope(clusterName, *core.StringPtr("foo-machine-2"), core.StringPtr(pvsImage), core.StringPtr(pvsNetwork), true, mockpowervs)
scope.IBMPowerVSMachine.Status.Conditions = append(scope.IBMPowerVSMachine.Status.Conditions, capiv1beta1.Condition{
Type: infrav1beta2.InstanceReadyCondition,
Status: corev1.ConditionUnknown,
})
mockpowervs.EXPECT().GetAllInstance().Return(pvmInstances, nil)
out, err := scope.CreateMachine()
g.Expect(err).To(BeNil())
require.Equal(t, expectedOutput, out)
})

t.Run("Eror while getting instances", func(t *testing.T) {
g := NewWithT(t)
setup(t)
Expand Down
3 changes: 3 additions & 0 deletions controllers/ibmpowervsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ func (r *IBMPowerVSMachineReconciler) reconcileNormal(machineScope *scope.PowerV
machineScope.Info("PowerVS instance state is undefined", "state", *instance.Status, "instance-id", machineScope.GetInstanceID())
conditions.MarkUnknown(machineScope.IBMPowerVSMachine, infrav1beta2.InstanceReadyCondition, "", "")
}
} else {
machineScope.SetNotReady()
conditions.MarkUnknown(machineScope.IBMPowerVSMachine, infrav1beta2.InstanceReadyCondition, infrav1beta2.InstanceStateUnknownReason, "")
}

// Requeue after 2 minute if machine is not ready to update status of the machine properly.
Expand Down

0 comments on commit d584dc6

Please sign in to comment.