@@ -505,7 +505,7 @@ func (r *RequestBase) applyChange(ctx context.Context, key ObjectKey, state Reso
505505switch state {
506506case ResourceStateUpdated :
507507r .logger .Info ("update object" , "object" , key )
508- obj := r .newObjects [key ]
508+ object := r .newObjects [key ]
509509
510510// Edge case: Deployments, when they are scaled, will apply changes in the following order:
511511// 1) Change the number of replicas (pods) in the current ReplicaSet
@@ -518,18 +518,33 @@ func (r *RequestBase) applyChange(ctx context.Context, key ObjectKey, state Reso
518518// 1) First, we apply the template changes (use current number of replicas)
519519// 2) Then apply the scale changes.
520520// That way the scale is only being applied to the new ReplicaSet.
521- if key .GroupVersionKind == AppsDeploymentGVK && obj .Materialized != nil {
522- currentObj := obj .Current .(* v1.Deployment )
523- newObj := obj .New .(* v1.Deployment )
524- materializedObj := obj .Materialized .(* v1.Deployment )
521+ if key .GroupVersionKind == AppsDeploymentGVK && object .Materialized != nil {
522+ currentObj := object .Current .(* v1.Deployment )
523+ newObj := object .New .(* v1.Deployment )
524+ materializedObj := object .Materialized .(* v1.Deployment )
525+ for _ , c := range currentObj .Status .Conditions {
526+ if c .Type == v1 .DeploymentProgressing && c .Reason == "ReplicaSetUpdated" {
527+ // We have an ongoing rollout, wait a little with scale-up.
528+ if newObj .Spec .Replicas != nil &&
529+ currentObj .Spec .Replicas != nil &&
530+ * newObj .Spec .Replicas > * currentObj .Spec .Replicas {
531+ newObj .Spec .Replicas = currentObj .Spec .Replicas
532+ }
533+ }
534+ }
535+
525536if ! equality .Semantic .DeepEqual (currentObj .Spec .Template , materializedObj .Spec .Template ) {
526537// We have changes to the template - don't apply potential replica changes yet.
527- newObj .Spec .Replicas = currentObj .Spec .Replicas
538+ if newObj .Spec .Replicas != nil &&
539+ currentObj .Spec .Replicas != nil &&
540+ * newObj .Spec .Replicas > * currentObj .Spec .Replicas {
541+ newObj .Spec .Replicas = currentObj .Spec .Replicas
542+ }
528543}
529544}
530545
531- obj .New .SetResourceVersion (obj .Current .GetResourceVersion ())
532- if err := r .client .Update (ctx , obj .New ); err != nil {
546+ object .New .SetResourceVersion (object .Current .GetResourceVersion ())
547+ if err := r .client .Update (ctx , object .New ); err != nil {
533548return fmt .Errorf ("could not update %s: %w" , key .GroupVersionKind , err )
534549}
535550
0 commit comments