Skip to content

Commit e6641cd

Browse files
committed
rename scaleReplicaSetAndRecordEvent to scaleReplicaSetWithLazyAnnotationUpdate
1 parent a490c43 commit e6641cd

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

pkg/controller/deployment/recreate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (dc *DeploymentController) scaleDownOldReplicaSetsForRecreate(ctx context.C
8383
if *(rs.Spec.Replicas) == 0 {
8484
continue
8585
}
86-
scaledRS, updatedRS, err := dc.scaleReplicaSetAndRecordEvent(ctx, rs, 0, deployment)
86+
scaledRS, updatedRS, err := dc.scaleReplicaSetWithLazyAnnotationUpdate(ctx, rs, 0, deployment)
8787
if err != nil {
8888
return false, err
8989
}
@@ -127,6 +127,6 @@ func oldPodsRunning(newRS *apps.ReplicaSet, oldRSs []*apps.ReplicaSet, podMap ma
127127

128128
// scaleUpNewReplicaSetForRecreate scales up new replica set when deployment strategy is "Recreate".
129129
func (dc *DeploymentController) scaleUpNewReplicaSetForRecreate(ctx context.Context, newRS *apps.ReplicaSet, deployment *apps.Deployment) (bool, error) {
130-
scaled, _, err := dc.scaleReplicaSetAndRecordEvent(ctx, newRS, *(deployment.Spec.Replicas), deployment)
130+
scaled, _, err := dc.scaleReplicaSetWithLazyAnnotationUpdate(ctx, newRS, *(deployment.Spec.Replicas), deployment)
131131
return scaled, err
132132
}

pkg/controller/deployment/rolling.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ func (dc *DeploymentController) reconcileNewReplicaSet(ctx context.Context, allR
7272
}
7373
if *(newRS.Spec.Replicas) > *(deployment.Spec.Replicas) {
7474
// Scale down.
75-
scaled, _, err := dc.scaleReplicaSetAndRecordEvent(ctx, newRS, *(deployment.Spec.Replicas), deployment)
75+
scaled, _, err := dc.scaleReplicaSetWithLazyAnnotationUpdate(ctx, newRS, *(deployment.Spec.Replicas), deployment)
7676
return scaled, err
7777
}
7878
newReplicasCount, err := deploymentutil.NewRSNewReplicas(deployment, allRSs, newRS)
7979
if err != nil {
8080
return false, err
8181
}
82-
scaled, _, err := dc.scaleReplicaSetAndRecordEvent(ctx, newRS, newReplicasCount, deployment)
82+
scaled, _, err := dc.scaleReplicaSetWithLazyAnnotationUpdate(ctx, newRS, newReplicasCount, deployment)
8383
return scaled, err
8484
}
8585

@@ -178,7 +178,7 @@ func (dc *DeploymentController) cleanupUnhealthyReplicas(ctx context.Context, ol
178178
if newReplicasCount > *(targetRS.Spec.Replicas) {
179179
return nil, 0, fmt.Errorf("when cleaning up unhealthy replicas, got invalid request to scale down %s/%s %d -> %d", targetRS.Namespace, targetRS.Name, *(targetRS.Spec.Replicas), newReplicasCount)
180180
}
181-
_, updatedOldRS, err := dc.scaleReplicaSetAndRecordEvent(ctx, targetRS, newReplicasCount, deployment)
181+
_, updatedOldRS, err := dc.scaleReplicaSetWithLazyAnnotationUpdate(ctx, targetRS, newReplicasCount, deployment)
182182
if err != nil {
183183
return nil, totalScaledDown, err
184184
}
@@ -223,7 +223,7 @@ func (dc *DeploymentController) scaleDownOldReplicaSetsForRollingUpdate(ctx cont
223223
if newReplicasCount > *(targetRS.Spec.Replicas) {
224224
return 0, fmt.Errorf("when scaling down old RS, got invalid request to scale down %s/%s %d -> %d", targetRS.Namespace, targetRS.Name, *(targetRS.Spec.Replicas), newReplicasCount)
225225
}
226-
_, _, err := dc.scaleReplicaSetAndRecordEvent(ctx, targetRS, newReplicasCount, deployment)
226+
_, _, err := dc.scaleReplicaSetWithLazyAnnotationUpdate(ctx, targetRS, newReplicasCount, deployment)
227227
if err != nil {
228228
return totalScaledDown, err
229229
}

pkg/controller/deployment/sync.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,15 @@ func (dc *DeploymentController) scale(ctx context.Context, deployment *apps.Depl
311311
if *(activeOrLatest.Spec.Replicas) == *(deployment.Spec.Replicas) {
312312
return nil
313313
}
314-
_, _, err := dc.scaleReplicaSetAndRecordEvent(ctx, activeOrLatest, *(deployment.Spec.Replicas), deployment)
314+
_, _, err := dc.scaleReplicaSetWithLazyAnnotationUpdate(ctx, activeOrLatest, *(deployment.Spec.Replicas), deployment)
315315
return err
316316
}
317317

318318
// If the new replica set is saturated, old replica sets should be fully scaled down.
319319
// This case handles replica set adoption during a saturated new replica set.
320320
if deploymentutil.IsSaturated(deployment, newRS) {
321321
for _, old := range controller.FilterActiveReplicaSets(oldRSs) {
322-
if _, _, err := dc.scaleReplicaSetAndRecordEvent(ctx, old, 0, deployment); err != nil {
322+
if _, _, err := dc.scaleReplicaSetWithLazyAnnotationUpdate(ctx, old, 0, deployment); err != nil {
323323
return err
324324
}
325325
}
@@ -400,7 +400,11 @@ func (dc *DeploymentController) scale(ctx context.Context, deployment *apps.Depl
400400
return nil
401401
}
402402

403-
func (dc *DeploymentController) scaleReplicaSetAndRecordEvent(ctx context.Context, rs *apps.ReplicaSet, newScale int32, deployment *apps.Deployment) (bool, *apps.ReplicaSet, error) {
403+
// scaleReplicaSetWithLazyAnnotationUpdate does not update the replica set annotations (DesiredReplicasAnnotation and
404+
// MaxReplicasAnnotation) if no replica set scaling is requested.
405+
// IMPORTANT: This method should not be called when an annotation update is necessary (e.g. scale during a rolling update)
406+
// and scaleReplicaSet should be used instead.
407+
func (dc *DeploymentController) scaleReplicaSetWithLazyAnnotationUpdate(ctx context.Context, rs *apps.ReplicaSet, newScale int32, deployment *apps.Deployment) (bool, *apps.ReplicaSet, error) {
404408
// No need to scale
405409
if *(rs.Spec.Replicas) == newScale {
406410
return false, rs, nil

0 commit comments

Comments
 (0)