@@ -340,15 +340,12 @@ func (dc *DeploymentController) scale(ctx context.Context, deployment *apps.Depl
340340// drives what happens in case we are trying to scale replica sets of the same size.
341341// In such a case when scaling up, we should scale up newer replica sets first, and
342342// when scaling down, we should scale down older replica sets first.
343- var scalingOperation string
344343switch {
345344case deploymentReplicasToAdd > 0 :
346345sort .Sort (controller .ReplicaSetsBySizeNewer (allRSs ))
347- scalingOperation = "up"
348346
349347case deploymentReplicasToAdd < 0 :
350348sort .Sort (controller .ReplicaSetsBySizeOlder (allRSs ))
351- scalingOperation = "down"
352349}
353350
354351// Iterate over all active replica sets and estimate proportions for each of them.
@@ -386,7 +383,7 @@ func (dc *DeploymentController) scale(ctx context.Context, deployment *apps.Depl
386383}
387384
388385// TODO: Use transactions when we have them.
389- if _ , _ , err := dc .scaleReplicaSet (ctx , rs , nameToSize [rs .Name ], deployment , scalingOperation ); err != nil {
386+ if _ , _ , err := dc .scaleReplicaSet (ctx , rs , nameToSize [rs .Name ], deployment ); err != nil {
390387// Return as soon as we fail, the deployment is requeued
391388return err
392389}
@@ -400,17 +397,11 @@ func (dc *DeploymentController) scaleReplicaSetAndRecordEvent(ctx context.Contex
400397if * (rs .Spec .Replicas ) == newScale {
401398return false , rs , nil
402399}
403- var scalingOperation string
404- if * (rs .Spec .Replicas ) < newScale {
405- scalingOperation = "up"
406- } else {
407- scalingOperation = "down"
408- }
409- scaled , newRS , err := dc .scaleReplicaSet (ctx , rs , newScale , deployment , scalingOperation )
400+ scaled , newRS , err := dc .scaleReplicaSet (ctx , rs , newScale , deployment )
410401return scaled , newRS , err
411402}
412403
413- func (dc * DeploymentController ) scaleReplicaSet (ctx context.Context , rs * apps.ReplicaSet , newScale int32 , deployment * apps.Deployment , scalingOperation string ) (bool , * apps.ReplicaSet , error ) {
404+ func (dc * DeploymentController ) scaleReplicaSet (ctx context.Context , rs * apps.ReplicaSet , newScale int32 , deployment * apps.Deployment ) (bool , * apps.ReplicaSet , error ) {
414405
415406sizeNeedsUpdate := * (rs .Spec .Replicas ) != newScale
416407
@@ -425,6 +416,12 @@ func (dc *DeploymentController) scaleReplicaSet(ctx context.Context, rs *apps.Re
425416deploymentutil .SetReplicasAnnotations (rsCopy , * (deployment .Spec .Replicas ), * (deployment .Spec .Replicas )+ deploymentutil .MaxSurge (* deployment ))
426417rs , err = dc .client .AppsV1 ().ReplicaSets (rsCopy .Namespace ).Update (ctx , rsCopy , metav1.UpdateOptions {})
427418if err == nil && sizeNeedsUpdate {
419+ var scalingOperation string
420+ if oldScale < newScale {
421+ scalingOperation = "up"
422+ } else {
423+ scalingOperation = "down"
424+ }
428425scaled = true
429426dc .eventRecorder .Eventf (deployment , v1 .EventTypeNormal , "ScalingReplicaSet" , "Scaled %s replica set %s from %d to %d" , scalingOperation , rs .Name , oldScale , newScale )
430427}
0 commit comments