From d68e8de2e8bd70c3a4ad6c0195537e08571fb03a Mon Sep 17 00:00:00 2001 From: Jesse Suen Date: Wed, 4 Oct 2023 06:14:01 -0700 Subject: [PATCH] fix: inopportune scaling events would lose some status fields (#3060) fix: inopportune scaling events would result in loss of data Signed-off-by: Jesse Suen --- rollout/sync.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/rollout/sync.go b/rollout/sync.go index a4682fad70..25c0c14813 100644 --- a/rollout/sync.go +++ b/rollout/sync.go @@ -281,10 +281,11 @@ func (c *rolloutContext) syncReplicasOnly() error { if err != nil { return err } + newStatus := c.rollout.Status.DeepCopy() // NOTE: it is possible for newRS to be nil (e.g. when template and replicas changed at same time) if c.rollout.Spec.Strategy.BlueGreen != nil { - previewSvc, activeSvc, err := c.getPreviewAndActiveServices() + _, activeSvc, err := c.getPreviewAndActiveServices() if err != nil { return nil } @@ -293,7 +294,15 @@ func (c *rolloutContext) syncReplicasOnly() error { // so we can abort this resync return err } - return c.syncRolloutStatusBlueGreen(previewSvc, activeSvc) + activeRS, _ := replicasetutil.GetReplicaSetByTemplateHash(c.allRSs, newStatus.BlueGreen.ActiveSelector) + if activeRS != nil { + newStatus.HPAReplicas = activeRS.Status.Replicas + newStatus.AvailableReplicas = activeRS.Status.AvailableReplicas + } else { + // when we do not have an active replicaset, accounting is done on the default rollout selector + newStatus.HPAReplicas = replicasetutil.GetActualReplicaCountForReplicaSets(c.allRSs) + newStatus.AvailableReplicas = replicasetutil.GetAvailableReplicaCountForReplicaSets(c.allRSs) + } } // The controller wants to use the rolloutCanary method to reconcile the rollout if the rollout is not paused. // If there are no scaling events, the rollout should only sync its status @@ -303,9 +312,10 @@ func (c *rolloutContext) syncReplicasOnly() error { // so we can abort this resync return err } - return c.syncRolloutStatusCanary() + newStatus.AvailableReplicas = replicasetutil.GetAvailableReplicaCountForReplicaSets(c.allRSs) + newStatus.HPAReplicas = replicasetutil.GetActualReplicaCountForReplicaSets(c.allRSs) } - return fmt.Errorf("no rollout strategy provided") + return c.persistRolloutStatus(newStatus) } // isScalingEvent checks whether the provided rollout has been updated with a scaling event