Skip to content

Commit

Permalink
Add an error reason for unknown plan status
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Dinov <[email protected]>
  • Loading branch information
atanasdinov committed Aug 1, 2024
1 parent 993d97c commit 45c215f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/upgradeplan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (
RancherUpgradedCondition = "RancherUpgraded"
LonghornUpgradedCondition = "LonghornUpgraded"

// UpgradeError indicates that the upgrade process has encountered a transient error.
UpgradeError = "Error"

// UpgradePending indicates that the upgrade process has not begun.
UpgradePending = "Pending"

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,6 @@ func evaluateHelmChartState(state upgrade.HelmChartState) (setCondition setCondi
case upgrade.ChartStateFailed:
return setFailedCondition, true
default:
return nil, false
return setErrorCondition, false
}
}
4 changes: 1 addition & 3 deletions internal/controller/reconcile_longhorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ func (r *UpgradePlanReconciler) reconcileLonghorn(ctx context.Context, upgradePl
}

setCondition, requeue := evaluateHelmChartState(state)
if setCondition != nil {
setCondition(upgradePlan, lifecyclev1alpha1.LonghornUpgradedCondition, state.Message())
}
setCondition(upgradePlan, lifecyclev1alpha1.LonghornUpgradedCondition, state.Message())

return ctrl.Result{Requeue: requeue}, nil
}
4 changes: 1 addition & 3 deletions internal/controller/reconcile_rancher.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ func (r *UpgradePlanReconciler) reconcileRancher(ctx context.Context, upgradePla
}

setCondition, requeue := evaluateHelmChartState(state)
if setCondition != nil {
setCondition(upgradePlan, lifecyclev1alpha1.RancherUpgradedCondition, state.Message())
}
setCondition(upgradePlan, lifecyclev1alpha1.RancherUpgradedCondition, state.Message())

return ctrl.Result{Requeue: requeue}, nil
}
5 changes: 5 additions & 0 deletions internal/controller/upgradeplan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ func setPendingCondition(plan *lifecyclev1alpha1.UpgradePlan, conditionType, mes
meta.SetStatusCondition(&plan.Status.Conditions, condition)
}

func setErrorCondition(plan *lifecyclev1alpha1.UpgradePlan, conditionType, message string) {
condition := metav1.Condition{Type: conditionType, Status: metav1.ConditionUnknown, Reason: lifecyclev1alpha1.UpgradeError, Message: message}
meta.SetStatusCondition(&plan.Status.Conditions, condition)
}

func setInProgressCondition(plan *lifecyclev1alpha1.UpgradePlan, conditionType, message string) {
condition := metav1.Condition{Type: conditionType, Status: metav1.ConditionFalse, Reason: lifecyclev1alpha1.UpgradeInProgress, Message: message}
meta.SetStatusCondition(&plan.Status.Conditions, condition)
Expand Down

0 comments on commit 45c215f

Please sign in to comment.