Skip to content

Commit 477a541

Browse files
[release-1.14] Updated the status before returning nil in reconcile (#196)
* Removed the call of resetObsoleteSPAs tentatively * Updated the status before returning nil in reconcile * Remove the revision if it is not in InitialRevisions and StageTargetRevisions --------- Co-authored-by: Vincent Hou <shou73@bloomberg.net>
1 parent 94c252c commit 477a541

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

pkg/reconciler/rolloutorchestrator/rolloutorchestrator.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,28 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ro *v1.RolloutOrchestrat
120120
ro.Spec.TargetRevisions) {
121121
// Start to move to the next stage.
122122
ro.Status.LaunchNewStage()
123+
return nil
123124
}
124125

126+
ro.Status.MarkStageRevisionScaleUpReady()
127+
ro.Status.MarkStageRevisionScaleDownReady()
128+
ro.Status.MarkStageRevisionReady()
129+
ro.Status.MarkLastStageRevisionComplete()
125130
return nil
126131
}
127132

128133
// resetObsoleteSPAs will set the StageMinScale to 0 and StageMaxScale to 1, if the revision with this spa is
129134
// not in ro.Spec.StageTargetRevisions.
130135
func (r *Reconciler) resetObsoleteSPAs(ctx context.Context, ro *v1.RolloutOrchestrator) error {
131-
records := map[string]bool{}
136+
records, recordsIni := map[string]bool{}, map[string]bool{}
132137
for _, rev := range ro.Spec.StageTargetRevisions {
133138
records[rev.RevisionName] = true
134139
}
140+
141+
for _, rev := range ro.Spec.InitialRevisions {
142+
recordsIni[rev.RevisionName] = true
143+
}
144+
135145
// Get the list of all the SPAs for the knative service.
136146
spaList, err := r.stagePodAutoscalerLister.StagePodAutoscalers(ro.Namespace).List(labels.SelectorFromSet(labels.Set{
137147
serving.ServiceLabelKey: ro.Name,
@@ -142,9 +152,9 @@ func (r *Reconciler) resetObsoleteSPAs(ctx context.Context, ro *v1.RolloutOrches
142152
return err
143153
}
144154
for _, spa := range spaList {
145-
// The SPA and the revision share the same name. If the revision is not in the StageTargetRevisions,
146-
// update the SPA to make sure the revision scaling down to 0.
147-
if !records[spa.Name] && (spa.Status.DesiredScale == nil || *spa.Status.DesiredScale != 0) {
155+
// The SPA and the revision share the same name. If the revision is not in the StageTargetRevisions and not in
156+
// InitialRevisions, update the SPA to make sure the revision scaling down to 0.
157+
if !records[spa.Name] && !recordsIni[spa.Name] && (spa.Status.DesiredScale == nil || *spa.Status.DesiredScale != 0) {
148158
spa.Spec.StageMinScale = ptr.Int32(0)
149159
spa.Spec.StageMaxScale = ptr.Int32(1)
150160
_, err = r.client.ServingV1().StagePodAutoscalers(ro.Namespace).Update(ctx, spa, metav1.UpdateOptions{})

pkg/reconciler/rolloutorchestrator/strategies/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type RolloutStep interface {
5252
enqueueAfter func(interface{}, time.Duration)) (bool, error)
5353
// ModifyStatus function changes the status of the ro accordingly after the completion of the scaling up or down for the
5454
// revisions.
55-
ModifyStatus(ro *v1.RolloutOrchestrator)
55+
ModifyStatus(ro *v1.RolloutOrchestrator, ready bool)
5656
}
5757

5858
// The BaseScaleStep struct defines golang clients, that are necessary to access the kubernetes resources.

pkg/reconciler/rolloutorchestrator/strategies/strategy.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ func (r *Rollout) Reconcile(ctx context.Context, ro *v1.RolloutOrchestrator, rev
5454
if err != nil {
5555
return false, err
5656
}
57-
if ready {
58-
step.ModifyStatus(ro)
59-
} else {
57+
step.ModifyStatus(ro, ready)
58+
if !ready {
6059
return false, nil
6160
}
6261
}
@@ -111,8 +110,14 @@ func (s *ScaleUpStep) Verify(ctx context.Context, ro *v1.RolloutOrchestrator, re
111110

112111
// ModifyStatus for ScaleUpStep modifies the status of the rolloutOrchestrator after the new revision has scaled up to
113112
// the expected number of pods.
114-
func (s *ScaleUpStep) ModifyStatus(ro *v1.RolloutOrchestrator) {
115-
ro.Status.MarkStageRevisionScaleUpReady()
113+
func (s *ScaleUpStep) ModifyStatus(ro *v1.RolloutOrchestrator, ready bool) {
114+
if ready {
115+
ro.Status.MarkStageRevisionScaleUpReady()
116+
} else {
117+
ro.Status.MarkStageRevisionScaleUpInProgress(v1.StageRevisionStart, v1.RolloutNewStage)
118+
ro.Status.MarkStageRevisionInProgress(v1.StageRevisionStart, v1.RolloutNewStage)
119+
ro.Status.MarkLastStageRevisionInComplete()
120+
}
116121
}
117122

118123
// The ScaleDownStep struct is responsible for scaling down the pods for the old revisions.
@@ -268,8 +273,14 @@ func (s *ScaleDownStep) Verify(ctx context.Context, ro *v1.RolloutOrchestrator,
268273

269274
// ModifyStatus for ScaleDownStep modifies the status of the rolloutOrchestrator after the old revision has scaled down to
270275
// the expected number of pods.
271-
func (s *ScaleDownStep) ModifyStatus(ro *v1.RolloutOrchestrator) {
272-
ro.Status.MarkStageRevisionScaleDownReady()
276+
func (s *ScaleDownStep) ModifyStatus(ro *v1.RolloutOrchestrator, ready bool) {
277+
if ready {
278+
ro.Status.MarkStageRevisionScaleDownReady()
279+
} else {
280+
ro.Status.MarkStageRevisionScaleDownInProgress(v1.StageRevisionStart, v1.RolloutNewStage)
281+
ro.Status.MarkStageRevisionInProgress(v1.StageRevisionStart, v1.RolloutNewStage)
282+
ro.Status.MarkLastStageRevisionInComplete()
283+
}
273284
}
274285

275286
func NewRolloutStrategy(client clientset.Interface, kubeclient kubernetes.Interface, stagePodAutoscalerLister listers.StagePodAutoscalerLister) map[string]*Rollout {

0 commit comments

Comments
 (0)