Skip to content

Commit

Permalink
Updated the status before returning nil in reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
houshengbo committed May 23, 2024
1 parent f6a15a9 commit 65ee8fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
9 changes: 8 additions & 1 deletion pkg/reconciler/rolloutorchestrator/rolloutorchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ro *v1.RolloutOrchestrat
if rollout == nil {
rollout = r.rolloutStrategy[strategies.AvailabilityStrategy]
}

fmt.Println("brefore calling rollout.Reconcile")
ready, err := rollout.Reconcile(ctx, ro, revScalingUp, revScalingDown, r.enqueueAfter)
if err != nil {
fmt.Println("rollout.Reconcile has errors")
return err
}
if !ready {
fmt.Println("rollout.Reconcile not ready")
return nil
}

Expand All @@ -115,8 +117,13 @@ 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
}

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
26 changes: 19 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,15 @@ 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

0 comments on commit 65ee8fe

Please sign in to comment.