Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix machine reconciliation bug #1307

Merged
merged 1 commit into from
Jul 25, 2023
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
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