@@ -340,15 +340,12 @@ func (dc *DeploymentController) scale(ctx context.Context, deployment *apps.Depl
340
340
// drives what happens in case we are trying to scale replica sets of the same size.
341
341
// In such a case when scaling up, we should scale up newer replica sets first, and
342
342
// when scaling down, we should scale down older replica sets first.
343
- var scalingOperation string
344
343
switch {
345
344
case deploymentReplicasToAdd > 0 :
346
345
sort .Sort (controller .ReplicaSetsBySizeNewer (allRSs ))
347
- scalingOperation = "up"
348
346
349
347
case deploymentReplicasToAdd < 0 :
350
348
sort .Sort (controller .ReplicaSetsBySizeOlder (allRSs ))
351
- scalingOperation = "down"
352
349
}
353
350
354
351
// 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
386
383
}
387
384
388
385
// 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 {
390
387
// Return as soon as we fail, the deployment is requeued
391
388
return err
392
389
}
@@ -400,17 +397,11 @@ func (dc *DeploymentController) scaleReplicaSetAndRecordEvent(ctx context.Contex
400
397
if * (rs .Spec .Replicas ) == newScale {
401
398
return false , rs , nil
402
399
}
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 )
410
401
return scaled , newRS , err
411
402
}
412
403
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 ) {
414
405
415
406
sizeNeedsUpdate := * (rs .Spec .Replicas ) != newScale
416
407
@@ -425,6 +416,12 @@ func (dc *DeploymentController) scaleReplicaSet(ctx context.Context, rs *apps.Re
425
416
deploymentutil .SetReplicasAnnotations (rsCopy , * (deployment .Spec .Replicas ), * (deployment .Spec .Replicas )+ deploymentutil .MaxSurge (* deployment ))
426
417
rs , err = dc .client .AppsV1 ().ReplicaSets (rsCopy .Namespace ).Update (ctx , rsCopy , metav1.UpdateOptions {})
427
418
if err == nil && sizeNeedsUpdate {
419
+ var scalingOperation string
420
+ if oldScale < newScale {
421
+ scalingOperation = "up"
422
+ } else {
423
+ scalingOperation = "down"
424
+ }
428
425
scaled = true
429
426
dc .eventRecorder .Eventf (deployment , v1 .EventTypeNormal , "ScalingReplicaSet" , "Scaled %s replica set %s from %d to %d" , scalingOperation , rs .Name , oldScale , newScale )
430
427
}
0 commit comments