Skip to content

Commit

Permalink
Delay scaling down after rollout
Browse files Browse the repository at this point in the history
  • Loading branch information
h3poteto committed Jul 4, 2024
1 parent 61bf3aa commit fcf7cce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ var _ = Describe("E2E", func() {

time.Sleep(10 * time.Second)

// The old replica set should no be scaled down
err = k8sClient.Get(ctx, types.NamespacedName{Name: oldRS.Name, Namespace: namespace}, oldRS)
Expect(err).ShouldNot(HaveOccurred())
Expect(oldRS.Status.Replicas).Should(Equal(int32(replicas)))

// Wait 120 seconds
time.Sleep(120 * time.Second)
// The old replica set should be scaled down
err = k8sClient.Get(ctx, types.NamespacedName{Name: oldRS.Name, Namespace: namespace}, oldRS)
Expect(err).ShouldNot(HaveOccurred())
Expand Down
14 changes: 12 additions & 2 deletions internal/controller/argorollout_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (r *ArgoRolloutReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
klog.V(1).Infof("Old ReplicaSet: %s/%s", rs.Namespace, rs.Name)

retry, err := r.scaleDown(ctx, rs, targetScaleDown)
retry, err := r.scaleDown(ctx, rs, targetScaleDown, argoRollout)
if err != nil {
klog.Errorf("Failed to scale down ReplicaSet: %v", err)
return ctrl.Result{}, err
Expand Down Expand Up @@ -132,7 +132,17 @@ func isCompleted(status *argorolloutsapiv1alpha1.RolloutStatus) bool {
return false
}

func (r *ArgoRolloutReconciler) scaleDown(ctx context.Context, rs *appsv1.ReplicaSet, scaleDown *optimizerv1alpha1.RolloutScaleDown) (time.Duration, error) {
func (r *ArgoRolloutReconciler) scaleDown(ctx context.Context, rs *appsv1.ReplicaSet, scaleDown *optimizerv1alpha1.RolloutScaleDown, rollout *argorolloutsapiv1alpha1.Rollout) (time.Duration, error) {
rolloutUpdated := time.Now()
for _, cond := range rollout.Status.Conditions {
if cond.Type == argorolloutsapiv1alpha1.RolloutCompleted {
rolloutUpdated = cond.LastUpdateTime.Time
}
}
if rolloutUpdated.Add(time.Duration(scaleDown.Spec.CoolTimeSeconds) * time.Second).After(time.Now()) {
return 30 * time.Second, nil
}

lastUpdated := scaleDown.Status.LastScaleDownTime
if lastUpdated.Add(time.Duration(scaleDown.Spec.CoolTimeSeconds) * time.Second).After(time.Now()) {
return 30 * time.Second, nil
Expand Down

0 comments on commit fcf7cce

Please sign in to comment.