Skip to content

Commit 4b11680

Browse files
authored
Bubble up conditions to capi objects (#141)
1 parent c98c2a2 commit 4b11680

4 files changed

+15
-5
lines changed

cloud/scope/machine.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (m *MachineScope) PatchObject() error {
209209

210210
// Close the MachineScope by updating the machine spec, machine status.
211211
func (m *MachineScope) Close() error {
212-
return m.patchHelper.Patch(context.TODO(), m.AzureStackHCIMachine)
212+
return m.PatchObject()
213213
}
214214

215215
// GetBootstrapData returns the bootstrap data from the secret in the Machine's bootstrap.dataSecretName.

controllers/azurestackhcicluster_controller.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
azurestackhci "github.com/microsoft/cluster-api-provider-azurestackhci/cloud"
2727
"github.com/microsoft/cluster-api-provider-azurestackhci/cloud/scope"
2828
infrav1util "github.com/microsoft/cluster-api-provider-azurestackhci/pkg/util"
29+
mocerrors "github.com/microsoft/moc/pkg/errors"
2930
"github.com/pkg/errors"
3031
corev1 "k8s.io/api/core/v1"
3132
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -132,9 +133,18 @@ func (r *AzureStackHCIClusterReconciler) reconcileNormal(clusterScope *scope.Clu
132133

133134
err := newAzureStackHCIClusterReconciler(clusterScope).Reconcile()
134135
if err != nil {
136+
switch mocerrors.GetErrorCode(err) {
137+
case mocerrors.OutOfMemory.Error():
138+
conditions.MarkFalse(azureStackHCICluster, infrav1.NetworkInfrastructureReadyCondition, infrav1.OutOfMemoryReason, clusterv1.ConditionSeverityError, err.Error())
139+
case mocerrors.OutOfCapacity.Error():
140+
conditions.MarkFalse(azureStackHCICluster, infrav1.NetworkInfrastructureReadyCondition, infrav1.OutOfCapacityReason, clusterv1.ConditionSeverityError, err.Error())
141+
default:
142+
conditions.MarkFalse(azureStackHCICluster, infrav1.NetworkInfrastructureReadyCondition, infrav1.ClusterReconciliationFailedReason, clusterv1.ConditionSeverityError, err.Error())
143+
}
144+
135145
wrappedErr := errors.Wrap(err, "failed to reconcile cluster services")
136146
r.Recorder.Eventf(azureStackHCICluster, corev1.EventTypeWarning, "ClusterReconcileFailed", wrappedErr.Error())
137-
conditions.MarkFalse(azureStackHCICluster, infrav1.NetworkInfrastructureReadyCondition, infrav1.ClusterReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error())
147+
138148
return reconcile.Result{}, wrappedErr
139149
}
140150

controllers/azurestackhcimachine_controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ func (r *AzureStackHCIMachineReconciler) reconcileNormal(machineScope *scope.Mac
222222
// TODO(vincepri): Remove this annotation when clusterctl is no longer relevant.
223223
machineScope.SetAnnotation("cluster-api-provider-azurestackhci", "true")
224224

225+
machineScope.AzureStackHCIMachine.Status.Conditions = append(machineScope.AzureStackHCIMachine.Status.Conditions, vm.Status.Conditions...)
226+
225227
if vm.Status.VMState == nil {
226228
machineScope.Info("Waiting for VM controller to set vm state")
227229
return reconcile.Result{Requeue: true, RequeueAfter: time.Minute}, nil
@@ -241,8 +243,6 @@ func (r *AzureStackHCIMachineReconciler) reconcileNormal(machineScope *scope.Mac
241243
machineScope.SetFailureMessage(errors.Errorf("AzureStackHCI VM state %q is unexpected", *machineScope.GetVMState()))
242244
}
243245

244-
machineScope.AzureStackHCIMachine.Status.Conditions = append(machineScope.AzureStackHCIMachine.Status.Conditions, vm.Status.Conditions...)
245-
246246
return reconcile.Result{}, nil
247247
}
248248

controllers/azurestackhcivirtualmachine_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (r *AzureStackHCIVirtualMachineReconciler) getOrCreate(virtualMachineScope
188188
case mocerrors.OutOfMemory.Error():
189189
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.OutOfMemoryReason, clusterv1.ConditionSeverityError, err.Error())
190190
case mocerrors.OutOfCapacity.Error():
191-
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.VMProvisionFailedReason, clusterv1.ConditionSeverityError, err.Error())
191+
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.OutOfCapacityReason, clusterv1.ConditionSeverityError, err.Error())
192192
default:
193193
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.VMProvisionFailedReason, clusterv1.ConditionSeverityError, err.Error())
194194
}

0 commit comments

Comments
 (0)