Skip to content

Commit

Permalink
Add status helpers (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Dinov <[email protected]>
  • Loading branch information
atanasdinov authored Jul 24, 2024
1 parent 340d526 commit 2805764
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/upgradeplan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const (
// UpgradeInProgress indicates that the upgrade process has started.
UpgradeInProgress = "InProgress"

// UpgradeSkipped indicates that the upgrade has been skipped.
UpgradeSkipped = "Skipped"

// UpgradeSucceeded indicates that the upgrade process has been successful.
UpgradeSucceeded = "Succeeded"

Expand Down
35 changes: 33 additions & 2 deletions internal/controller/upgradeplan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ func (r *UpgradePlanReconciler) executePlan(ctx context.Context, upgradePlan *li
}

if len(upgradePlan.Status.Conditions) == 0 {
condition := metav1.Condition{Type: lifecyclev1alpha1.KubernetesUpgradedCondition, Status: metav1.ConditionUnknown, Reason: lifecyclev1alpha1.UpgradePending, Message: "Kubernetes upgrade is not yet started"}
meta.SetStatusCondition(&upgradePlan.Status.Conditions, condition)
setPendingCondition(upgradePlan, lifecyclev1alpha1.KubernetesUpgradedCondition, "Kubernetes upgrade is not yet started")

// Append OS and other components conditions here...
return ctrl.Result{Requeue: true}, nil
Expand Down Expand Up @@ -118,6 +117,28 @@ func (r *UpgradePlanReconciler) createPlan(ctx context.Context, upgradePlan *lif
return nil
}

func isHelmUpgradeFinished(plan *lifecyclev1alpha1.UpgradePlan, conditionType string) bool {

Check failure on line 120 in internal/controller/upgradeplan_controller.go

View workflow job for this annotation

GitHub Actions / lint

func `isHelmUpgradeFinished` is unused (unused)
condition := meta.FindStatusCondition(plan.Status.Conditions, conditionType)

if condition == nil {
return false
}

if condition.Status == metav1.ConditionTrue {
return true
} else if condition.Status == metav1.ConditionFalse &&
(condition.Reason == lifecyclev1alpha1.UpgradeSkipped || condition.Reason == lifecyclev1alpha1.UpgradeFailed) {
return true
}

return false
}

func setPendingCondition(plan *lifecyclev1alpha1.UpgradePlan, conditionType, message string) {
condition := metav1.Condition{Type: conditionType, Status: metav1.ConditionUnknown, Reason: lifecyclev1alpha1.UpgradePending, 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 All @@ -128,6 +149,16 @@ func setSuccessfulCondition(plan *lifecyclev1alpha1.UpgradePlan, conditionType,
meta.SetStatusCondition(&plan.Status.Conditions, condition)
}

func setFailedCondition(plan *lifecyclev1alpha1.UpgradePlan, conditionType, message string) {

Check failure on line 152 in internal/controller/upgradeplan_controller.go

View workflow job for this annotation

GitHub Actions / lint

func `setFailedCondition` is unused (unused)
condition := metav1.Condition{Type: conditionType, Status: metav1.ConditionFalse, Reason: lifecyclev1alpha1.UpgradeFailed, Message: message}
meta.SetStatusCondition(&plan.Status.Conditions, condition)
}

func setSkippedCondition(plan *lifecyclev1alpha1.UpgradePlan, conditionType, message string) {

Check failure on line 157 in internal/controller/upgradeplan_controller.go

View workflow job for this annotation

GitHub Actions / lint

func `setSkippedCondition` is unused (unused)
condition := metav1.Condition{Type: conditionType, Status: metav1.ConditionFalse, Reason: lifecyclev1alpha1.UpgradeSkipped, Message: message}
meta.SetStatusCondition(&plan.Status.Conditions, condition)
}

// SetupWithManager sets up the controller with the Manager.
func (r *UpgradePlanReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
Expand Down

0 comments on commit 2805764

Please sign in to comment.