Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status helpers #18

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}

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 @@
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 @@
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
Loading