Skip to content

Commit

Permalink
advanced deployment scale down old unhealthy pods firstly
Browse files Browse the repository at this point in the history
Signed-off-by: mingzhou.swx <mingzhou.swx@alibaba-inc.com>
  • Loading branch information
mingzhou.swx committed Jun 13, 2023
1 parent 3578b39 commit 74080d2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/controller/deployment/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,27 @@ func (dc *DeploymentController) scale(ctx context.Context, deployment *apps.Depl
scalingOperation = "down"
}

// Scale down the unhealthy replicas in old replica sets firstly to avoid some bad cases.
// For example:
// _______________________________________________________________________
// | ReplicaSet | oldRS-1 | oldRS-2 | newRS |
// | --------------| -------------------|----------------------|----------|
// | Replicas | 5 healthy Pods | 1 unhealthy Pods 1 | 0 |
// ------------------------------------------------------------------------
// If we want to scale down these replica sets from 6 to 5, we expect to scale down the oldRS-2
// from 1 to 0 firstly.
var err error
var cleanupCount int32
if deploymentReplicasToAdd < 0 {
oldRSs, cleanupCount, err = dc.cleanupUnhealthyReplicas(ctx, oldRSs, deployment, -deploymentReplicasToAdd)
if err != nil {
return err
}
klog.V(4).Infof("Cleaned up unhealthy replicas from old RSes by %d during scaling", cleanupCount)
deploymentReplicasToAdd += cleanupCount
allRSs = deploymentutil.FilterActiveReplicaSets(append(oldRSs, newRS))
}

// Iterate over all active replica sets and estimate proportions for each of them.
// The absolute value of deploymentReplicasAdded should never exceed the absolute
// value of deploymentReplicasToAdd.
Expand Down

0 comments on commit 74080d2

Please sign in to comment.