Skip to content

Commit

Permalink
Register the errors for the powervs vm build failure
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumatag committed May 5, 2022
1 parent 38f7d43 commit 4e4a48e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cloud/scope/powervs_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/klog/v2/klogr"
"k8s.io/utils/pointer"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
capierrors "sigs.k8s.io/cluster-api/errors"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -355,6 +356,16 @@ func (m *PowerVSMachineScope) SetNotReady() {
m.IBMPowerVSMachine.Status.Ready = false
}

// SetFailureReason will set status FailureReason for the machine.
func (m *PowerVSMachineScope) SetFailureReason(reason capierrors.MachineStatusError) {
m.IBMPowerVSMachine.Status.FailureReason = &reason
}

// SetFailureMessage will set status FailureMessage for the machine.
func (m *PowerVSMachineScope) SetFailureMessage(message string) {
m.IBMPowerVSMachine.Status.FailureMessage = &message
}

// IsReady will return the status for the machine.
func (m *PowerVSMachineScope) IsReady() bool {
return m.IBMPowerVSMachine.Status.Ready
Expand Down
3 changes: 3 additions & 0 deletions controllers/ibmpowervsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
capierrors "sigs.k8s.io/cluster-api/errors"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/conditions"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -228,6 +229,8 @@ func (r *IBMPowerVSMachineReconciler) reconcileNormal(machineScope *scope.PowerV
msg = instance.Fault.Details
}
machineScope.SetNotReady()
machineScope.SetFailureReason(capierrors.UpdateMachineError)
machineScope.SetFailureMessage(msg)
conditions.MarkFalse(machineScope.IBMPowerVSMachine, infrav1beta1.InstanceReadyCondition, infrav1beta1.InstanceErroredReason, capiv1beta1.ConditionSeverityError, msg)
capibmrecord.Warnf(machineScope.IBMPowerVSMachine, "FailedBuildInstance", "Failed to build the instance - %s", msg)
return ctrl.Result{}, nil
Expand Down

0 comments on commit 4e4a48e

Please sign in to comment.