Skip to content

Commit

Permalink
Bubble up conditions to capi objects (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
apluchik authored Jul 7, 2021
1 parent c98c2a2 commit 4b11680
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (m *MachineScope) PatchObject() error {

// Close the MachineScope by updating the machine spec, machine status.
func (m *MachineScope) Close() error {
return m.patchHelper.Patch(context.TODO(), m.AzureStackHCIMachine)
return m.PatchObject()
}

// GetBootstrapData returns the bootstrap data from the secret in the Machine's bootstrap.dataSecretName.
Expand Down
12 changes: 11 additions & 1 deletion controllers/azurestackhcicluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
azurestackhci "github.com/microsoft/cluster-api-provider-azurestackhci/cloud"
"github.com/microsoft/cluster-api-provider-azurestackhci/cloud/scope"
infrav1util "github.com/microsoft/cluster-api-provider-azurestackhci/pkg/util"
mocerrors "github.com/microsoft/moc/pkg/errors"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -132,9 +133,18 @@ func (r *AzureStackHCIClusterReconciler) reconcileNormal(clusterScope *scope.Clu

err := newAzureStackHCIClusterReconciler(clusterScope).Reconcile()
if err != nil {
switch mocerrors.GetErrorCode(err) {
case mocerrors.OutOfMemory.Error():
conditions.MarkFalse(azureStackHCICluster, infrav1.NetworkInfrastructureReadyCondition, infrav1.OutOfMemoryReason, clusterv1.ConditionSeverityError, err.Error())
case mocerrors.OutOfCapacity.Error():
conditions.MarkFalse(azureStackHCICluster, infrav1.NetworkInfrastructureReadyCondition, infrav1.OutOfCapacityReason, clusterv1.ConditionSeverityError, err.Error())
default:
conditions.MarkFalse(azureStackHCICluster, infrav1.NetworkInfrastructureReadyCondition, infrav1.ClusterReconciliationFailedReason, clusterv1.ConditionSeverityError, err.Error())
}

wrappedErr := errors.Wrap(err, "failed to reconcile cluster services")
r.Recorder.Eventf(azureStackHCICluster, corev1.EventTypeWarning, "ClusterReconcileFailed", wrappedErr.Error())
conditions.MarkFalse(azureStackHCICluster, infrav1.NetworkInfrastructureReadyCondition, infrav1.ClusterReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error())

return reconcile.Result{}, wrappedErr
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/azurestackhcimachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ func (r *AzureStackHCIMachineReconciler) reconcileNormal(machineScope *scope.Mac
// TODO(vincepri): Remove this annotation when clusterctl is no longer relevant.
machineScope.SetAnnotation("cluster-api-provider-azurestackhci", "true")

machineScope.AzureStackHCIMachine.Status.Conditions = append(machineScope.AzureStackHCIMachine.Status.Conditions, vm.Status.Conditions...)

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

machineScope.AzureStackHCIMachine.Status.Conditions = append(machineScope.AzureStackHCIMachine.Status.Conditions, vm.Status.Conditions...)

return reconcile.Result{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/azurestackhcivirtualmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (r *AzureStackHCIVirtualMachineReconciler) getOrCreate(virtualMachineScope
case mocerrors.OutOfMemory.Error():
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.OutOfMemoryReason, clusterv1.ConditionSeverityError, err.Error())
case mocerrors.OutOfCapacity.Error():
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.VMProvisionFailedReason, clusterv1.ConditionSeverityError, err.Error())
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.OutOfCapacityReason, clusterv1.ConditionSeverityError, err.Error())
default:
conditions.MarkFalse(virtualMachineScope.AzureStackHCIVirtualMachine, infrav1.VMRunningCondition, infrav1.VMProvisionFailedReason, clusterv1.ConditionSeverityError, err.Error())
}
Expand Down

0 comments on commit 4b11680

Please sign in to comment.