Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.14] Updated the status before returning nil in reconcile #196

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pkg/reconciler/rolloutorchestrator/rolloutorchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,28 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ro *v1.RolloutOrchestrat
ro.Spec.TargetRevisions) {
// Start to move to the next stage.
ro.Status.LaunchNewStage()
return nil
}

ro.Status.MarkStageRevisionScaleUpReady()
ro.Status.MarkStageRevisionScaleDownReady()
ro.Status.MarkStageRevisionReady()
ro.Status.MarkLastStageRevisionComplete()
return nil
}

// 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 @@ -142,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
2 changes: 1 addition & 1 deletion pkg/reconciler/rolloutorchestrator/strategies/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type RolloutStep interface {
enqueueAfter func(interface{}, time.Duration)) (bool, error)
// ModifyStatus function changes the status of the ro accordingly after the completion of the scaling up or down for the
// revisions.
ModifyStatus(ro *v1.RolloutOrchestrator)
ModifyStatus(ro *v1.RolloutOrchestrator, ready bool)
}

// The BaseScaleStep struct defines golang clients, that are necessary to access the kubernetes resources.
Expand Down
25 changes: 18 additions & 7 deletions pkg/reconciler/rolloutorchestrator/strategies/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ func (r *Rollout) Reconcile(ctx context.Context, ro *v1.RolloutOrchestrator, rev
if err != nil {
return false, err
}
if ready {
step.ModifyStatus(ro)
} else {
step.ModifyStatus(ro, ready)
if !ready {
return false, nil
}
}
Expand Down Expand Up @@ -111,8 +110,14 @@ func (s *ScaleUpStep) Verify(ctx context.Context, ro *v1.RolloutOrchestrator, re

// ModifyStatus for ScaleUpStep modifies the status of the rolloutOrchestrator after the new revision has scaled up to
// the expected number of pods.
func (s *ScaleUpStep) ModifyStatus(ro *v1.RolloutOrchestrator) {
ro.Status.MarkStageRevisionScaleUpReady()
func (s *ScaleUpStep) ModifyStatus(ro *v1.RolloutOrchestrator, ready bool) {
if ready {
ro.Status.MarkStageRevisionScaleUpReady()
} else {
ro.Status.MarkStageRevisionScaleUpInProgress(v1.StageRevisionStart, v1.RolloutNewStage)
ro.Status.MarkStageRevisionInProgress(v1.StageRevisionStart, v1.RolloutNewStage)
ro.Status.MarkLastStageRevisionInComplete()
}
}

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

// ModifyStatus for ScaleDownStep modifies the status of the rolloutOrchestrator after the old revision has scaled down to
// the expected number of pods.
func (s *ScaleDownStep) ModifyStatus(ro *v1.RolloutOrchestrator) {
ro.Status.MarkStageRevisionScaleDownReady()
func (s *ScaleDownStep) ModifyStatus(ro *v1.RolloutOrchestrator, ready bool) {
if ready {
ro.Status.MarkStageRevisionScaleDownReady()
} else {
ro.Status.MarkStageRevisionScaleDownInProgress(v1.StageRevisionStart, v1.RolloutNewStage)
ro.Status.MarkStageRevisionInProgress(v1.StageRevisionStart, v1.RolloutNewStage)
ro.Status.MarkLastStageRevisionInComplete()
}
}

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