Skip to content

Commit 9a364fd

Browse files
authored
Record the ERRORED event (#642)
1 parent d6d98d5 commit 9a364fd

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

api/v1beta1/conditions_consts.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ const (
3333
// InstanceStoppedReason instance is in a stopped state.
3434
InstanceStoppedReason = "InstanceStopped"
3535

36+
// InstanceErroredReason instance is in a errored state.
37+
InstanceErroredReason = "InstanceErrored"
38+
3639
// InstanceNotReadyReason used when the instance is in a pending state.
3740
InstanceNotReadyReason = "InstanceNotReady"
3841
)

api/v1beta1/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ var (
3131

3232
// PowerVSInstanceStateREBOOT is the string representing an instance in a REBOOT state.
3333
PowerVSInstanceStateREBOOT = PowerVSInstanceState("REBOOT")
34+
35+
// PowerVSInstanceStateERROR is the string representing an instance in a ERROR state.
36+
PowerVSInstanceStateERROR = PowerVSInstanceState("ERROR")
3437
)
3538

3639
// PowerVSImageState describes the state of an IBM Power VS image.

controllers/ibmpowervsmachine_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
infrav1beta1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta1"
3737
"sigs.k8s.io/cluster-api-provider-ibmcloud/cloud/scope"
38+
capibmrecord "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/record"
3839
)
3940

4041
// IBMPowerVSMachineReconciler reconciles a IBMPowerVSMachine object.
@@ -221,6 +222,15 @@ func (r *IBMPowerVSMachineReconciler) reconcileNormal(machineScope *scope.PowerV
221222
case infrav1beta1.PowerVSInstanceStateACTIVE:
222223
machineScope.SetReady()
223224
conditions.MarkTrue(machineScope.IBMPowerVSMachine, infrav1beta1.InstanceReadyCondition)
225+
case infrav1beta1.PowerVSInstanceStateERROR:
226+
msg := ""
227+
if instance.Fault != nil {
228+
msg = instance.Fault.Details
229+
}
230+
machineScope.SetNotReady()
231+
conditions.MarkFalse(machineScope.IBMPowerVSMachine, infrav1beta1.InstanceReadyCondition, infrav1beta1.InstanceErroredReason, capiv1beta1.ConditionSeverityError, msg)
232+
capibmrecord.Warnf(machineScope.IBMPowerVSMachine, "FailedBuildInstance", "Failed to build the instance - %s", msg)
233+
return ctrl.Result{}, nil
224234
default:
225235
machineScope.SetNotReady()
226236
machineScope.Info("PowerVS instance state is undefined", "state", *instance.Status, "instance-id", machineScope.GetInstanceID())

0 commit comments

Comments
 (0)