From a0baf3d031ba8a0af1d6e310b5d9c4c1d625bf47 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Mon, 11 Dec 2023 18:29:16 +0900
Subject: [PATCH] SRE-1763: Check rollout status before scaling down
---
internal/controller/argorollout_controller.go | 28 ++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/internal/controller/argorollout_controller.go b/internal/controller/argorollout_controller.go
index 34aa707..163defe 100644
--- a/internal/controller/argorollout_controller.go
+++ b/internal/controller/argorollout_controller.go
@@ -4,6 +4,7 @@ import (
"context"
argorolloutsapiv1alpha1 "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
+ corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
@@ -55,11 +56,36 @@ func (r *ArgoRolloutReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
logger.V(1).Info("Target ArgoRollout", argoRollout.Namespace, argoRollout.Name)
- // TODO: Check ArgoRollout status and scaledown if needed
+ if isCompleted(&argoRollout.Status) {
+ // TODO: find old replica set
+ // TODO: scale down the replica set
+ }
+
return ctrl.Result{}, nil
}
+
func (r *ArgoRolloutReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).For(&argorolloutsapiv1alpha1.Rollout{}).Complete(r)
}
+
+func isCompleted(status *argorolloutsapiv1alpha1.RolloutStatus) bool {
+ if status.Phase != argorolloutsapiv1alpha1.RolloutPhaseHealthy {
+ return false
+ }
+ completed := false
+ paused := true
+ for _, cond := range status.Conditions {
+ if cond.Type == argorolloutsapiv1alpha1.RolloutCompleted && cond.Status == corev1.ConditionTrue {
+ completed = true
+ }
+ if cond.Type == argorolloutsapiv1alpha1.RolloutPaused && cond.Status == corev1.ConditionFalse {
+ paused = false
+ }
+ }
+ if completed == true && paused == false && status.Replicas >= status.ReadyReplicas {
+ return true
+ }
+ return false
+}