From 45c215fc341403247e5785b12cb9c0fac8854664 Mon Sep 17 00:00:00 2001 From: Atanas Dinov Date: Thu, 1 Aug 2024 11:49:59 +0300 Subject: [PATCH] Add an error reason for unknown plan status Signed-off-by: Atanas Dinov --- api/v1alpha1/upgradeplan_types.go | 3 +++ internal/controller/helm.go | 2 +- internal/controller/reconcile_longhorn.go | 4 +--- internal/controller/reconcile_rancher.go | 4 +--- internal/controller/upgradeplan_controller.go | 5 +++++ 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/v1alpha1/upgradeplan_types.go b/api/v1alpha1/upgradeplan_types.go index 0a5bd92..90622bf 100644 --- a/api/v1alpha1/upgradeplan_types.go +++ b/api/v1alpha1/upgradeplan_types.go @@ -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" diff --git a/internal/controller/helm.go b/internal/controller/helm.go index 7ca8e93..e9428c2 100644 --- a/internal/controller/helm.go +++ b/internal/controller/helm.go @@ -196,6 +196,6 @@ func evaluateHelmChartState(state upgrade.HelmChartState) (setCondition setCondi case upgrade.ChartStateFailed: return setFailedCondition, true default: - return nil, false + return setErrorCondition, false } } diff --git a/internal/controller/reconcile_longhorn.go b/internal/controller/reconcile_longhorn.go index 5392e03..9194b68 100644 --- a/internal/controller/reconcile_longhorn.go +++ b/internal/controller/reconcile_longhorn.go @@ -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 } diff --git a/internal/controller/reconcile_rancher.go b/internal/controller/reconcile_rancher.go index 3e4a160..b51740e 100644 --- a/internal/controller/reconcile_rancher.go +++ b/internal/controller/reconcile_rancher.go @@ -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 } diff --git a/internal/controller/upgradeplan_controller.go b/internal/controller/upgradeplan_controller.go index e794ff4..e25d7c4 100644 --- a/internal/controller/upgradeplan_controller.go +++ b/internal/controller/upgradeplan_controller.go @@ -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)