Skip to content

Commit

Permalink
Remove the revision if it is not in InitialRevisions and StageTargetR…
Browse files Browse the repository at this point in the history
…evisions
  • Loading branch information
houshengbo committed May 23, 2024
1 parent 71ccdf1 commit b26383c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/reconciler/rolloutorchestrator/rolloutorchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ro *v1.RolloutOrchestrat
return err
}

err = r.resetObsoleteSPAs(ctx, ro)
if err != nil {
return err
}

rollout := r.rolloutStrategy[strings.ToLower(ro.Spec.RolloutStrategy)]
if rollout == nil {
rollout = r.rolloutStrategy[strategies.AvailabilityStrategy]
}

ready, err := rollout.Reconcile(ctx, ro, revScalingUp, revScalingDown, r.enqueueAfter)
if err != nil {
return err
Expand Down Expand Up @@ -127,10 +133,15 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ro *v1.RolloutOrchestrat
// resetObsoleteSPAs will set the StageMinScale to 0 and StageMaxScale to 1, if the revision with this spa is
// not in ro.Spec.StageTargetRevisions.
func (r *Reconciler) resetObsoleteSPAs(ctx context.Context, ro *v1.RolloutOrchestrator) error {
records := map[string]bool{}
records, records_ini := map[string]bool{}, map[string]bool{}

Check failure on line 136 in pkg/reconciler/rolloutorchestrator/rolloutorchestrator.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

var-naming: don't use underscores in Go names; var records_ini should be recordsIni (revive)
for _, rev := range ro.Spec.StageTargetRevisions {
records[rev.RevisionName] = true
}

for _, rev := range ro.Spec.InitialRevisions {
records_ini[rev.RevisionName] = true
}

// Get the list of all the SPAs for the knative service.
spaList, err := r.stagePodAutoscalerLister.StagePodAutoscalers(ro.Namespace).List(labels.SelectorFromSet(labels.Set{
serving.ServiceLabelKey: ro.Name,
Expand All @@ -143,7 +154,7 @@ func (r *Reconciler) resetObsoleteSPAs(ctx context.Context, ro *v1.RolloutOrches
for _, spa := range spaList {
// The SPA and the revision share the same name. If the revision is not in the StageTargetRevisions,
// update the SPA to make sure the revision scaling down to 0.
if !records[spa.Name] && (spa.Status.DesiredScale == nil || *spa.Status.DesiredScale != 0) {
if !records[spa.Name] && !records_ini[spa.Name] && (spa.Status.DesiredScale == nil || *spa.Status.DesiredScale != 0) {
spa.Spec.StageMinScale = ptr.Int32(0)
spa.Spec.StageMaxScale = ptr.Int32(1)
_, err = r.client.ServingV1().StagePodAutoscalers(ro.Namespace).Update(ctx, spa, metav1.UpdateOptions{})
Expand Down

0 comments on commit b26383c

Please sign in to comment.