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 24, 2024
1 parent 71ccdf1 commit 8562705
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 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, 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,
Expand All @@ -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{})
Expand Down

0 comments on commit 8562705

Please sign in to comment.