Skip to content

Commit 46232f1

Browse files
fix machine reconcilation bug (#1307)
Signed-off-by: Prajyot-Parab <[email protected]>
1 parent 84cbbac commit 46232f1

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

api/v1beta2/conditions_consts.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ const (
3636
// InstanceErroredReason instance is in a errored state.
3737
InstanceErroredReason = "InstanceErrored"
3838

39-
// InstanceNotReadyReason used when the instance is in a pending state.
39+
// InstanceNotReadyReason used when the instance is in a not ready state.
4040
InstanceNotReadyReason = "InstanceNotReady"
41+
42+
// InstanceStateUnknownReason used when the instance is in a unknown state.
43+
InstanceStateUnknownReason = "InstanceStateUnknown"
4144
)
4245

4346
const (

cloud/scope/powervs_machine.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ func (m *PowerVSMachineScope) CreateMachine() (*models.PVMInstanceReference, err
202202
// TODO need a reasonable wrapped error.
203203
return instanceReply, nil
204204
}
205+
206+
// Check if create request has been already triggered.
207+
// If InstanceReadyCondition is Unknown then return and wait for it to get updated.
208+
for _, con := range m.IBMPowerVSMachine.Status.Conditions {
209+
if con.Type == infrav1beta2.InstanceReadyCondition && con.Status == corev1.ConditionUnknown {
210+
return nil, nil
211+
}
212+
}
213+
205214
cloudInitData, err := m.GetBootstrapData()
206215
if err != nil {
207216
return nil, err

cloud/scope/powervs_machine_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ func TestCreateMachinePVS(t *testing.T) {
257257
require.Equal(t, expectedOutput.ServerName, out.ServerName)
258258
})
259259

260+
t.Run("Return NIL when Machine is not present in the Instance list and Machine state is unknown", func(t *testing.T) {
261+
g := NewWithT(t)
262+
setup(t)
263+
t.Cleanup(teardown)
264+
expectedOutput := (*models.PVMInstanceReference)(nil)
265+
scope := setupPowerVSMachineScope(clusterName, *core.StringPtr("foo-machine-2"), core.StringPtr(pvsImage), core.StringPtr(pvsNetwork), true, mockpowervs)
266+
scope.IBMPowerVSMachine.Status.Conditions = append(scope.IBMPowerVSMachine.Status.Conditions, capiv1beta1.Condition{
267+
Type: infrav1beta2.InstanceReadyCondition,
268+
Status: corev1.ConditionUnknown,
269+
})
270+
mockpowervs.EXPECT().GetAllInstance().Return(pvmInstances, nil)
271+
out, err := scope.CreateMachine()
272+
g.Expect(err).To(BeNil())
273+
require.Equal(t, expectedOutput, out)
274+
})
275+
260276
t.Run("Eror while getting instances", func(t *testing.T) {
261277
g := NewWithT(t)
262278
setup(t)

controllers/ibmpowervsmachine_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ func (r *IBMPowerVSMachineReconciler) reconcileNormal(machineScope *scope.PowerV
262262
machineScope.Info("PowerVS instance state is undefined", "state", *instance.Status, "instance-id", machineScope.GetInstanceID())
263263
conditions.MarkUnknown(machineScope.IBMPowerVSMachine, infrav1beta2.InstanceReadyCondition, "", "")
264264
}
265+
} else {
266+
machineScope.SetNotReady()
267+
conditions.MarkUnknown(machineScope.IBMPowerVSMachine, infrav1beta2.InstanceReadyCondition, infrav1beta2.InstanceStateUnknownReason, "")
265268
}
266269

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

0 commit comments

Comments
 (0)