Skip to content

Commit

Permalink
fix: inopportune scaling events would lose some status fields (#3060)
Browse files Browse the repository at this point in the history
fix: inopportune scaling events would result in loss of data

Signed-off-by: Jesse Suen <[email protected]>
  • Loading branch information
jessesuen authored and zachaller committed Oct 30, 2023
1 parent 5b40f08 commit d68e8de
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions rollout/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d68e8de

Please sign in to comment.