From 85627050c9122300e843d5f559d2896364b557b6 Mon Sep 17 00:00:00 2001 From: Vincent Hou Date: Thu, 23 May 2024 19:21:01 -0400 Subject: [PATCH] Remove the revision if it is not in InitialRevisions and StageTargetRevisions --- .../rolloutorchestrator.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/reconciler/rolloutorchestrator/rolloutorchestrator.go b/pkg/reconciler/rolloutorchestrator/rolloutorchestrator.go index 515fdafea..f1cfdc3ad 100644 --- a/pkg/reconciler/rolloutorchestrator/rolloutorchestrator.go +++ b/pkg/reconciler/rolloutorchestrator/rolloutorchestrator.go @@ -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 @@ -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, recordsIni := map[string]bool{}, map[string]bool{} for _, rev := range ro.Spec.StageTargetRevisions { records[rev.RevisionName] = true } + + for _, rev := range ro.Spec.InitialRevisions { + recordsIni[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, @@ -141,9 +152,9 @@ func (r *Reconciler) resetObsoleteSPAs(ctx context.Context, ro *v1.RolloutOrches return err } 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) { + // The SPA and the revision share the same name. If the revision is not in the StageTargetRevisions and not in + // InitialRevisions, update the SPA to make sure the revision scaling down to 0. + if !records[spa.Name] && !recordsIni[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{})