@@ -19,7 +19,6 @@ package rollout
1919import (
2020 "context"
2121 "fmt"
22- "reflect"
2322 "time"
2423
2524 corev1 "k8s.io/api/core/v1"
@@ -313,34 +312,48 @@ func (m *canaryReleaseManager) doCanaryPaused(c *RolloutContext) (bool, error) {
313312 return false , nil
314313}
315314
316- func (m * canaryReleaseManager ) doCanaryJump (c * RolloutContext ) (jumped bool ) {
317- canaryStatus := c .NewStatus .CanaryStatus
318- // since we forbid adding or removing steps, currentStepIndex should always be valid
319- currentStep := c .Rollout .Spec .Strategy .Canary .Steps [canaryStatus .CurrentStepIndex - 1 ]
320- // nextIndex=-1 means the release is done, nextIndex=0 is not used
321- if nextIndex := canaryStatus .NextStepIndex ; nextIndex != util .NextBatchIndex (c .Rollout , canaryStatus .CurrentStepIndex ) && nextIndex > 0 {
322- currentIndexBackup := canaryStatus .CurrentStepIndex
323- currentStepStateBackup := canaryStatus .CurrentStepState
315+ // doStepJump implements the common logic for both canary and bluegreen rollout strategies
316+ // to handle step jumping based on NextStepIndex.
317+ func doStepJump (rollout * v1beta1.Rollout , newStatus * v1beta1.RolloutStatus , steps []v1beta1.CanaryStep , workloadReplicas int ) (jumped bool ) {
318+ status := newStatus .GetUnifiedStatus ()
319+ if status .IsNil () {
320+ klog .InfoS ("doStepJump skipped: unified status is nil" )
321+ return false
322+ }
323+ klog .InfoS ("will do step jump" , "steps" , len (steps ), "updatedReplicas" , * status .UpdatedReplicas ,
324+ "nextStepIndex" , status .NextStepIndex , "rollout" , klog .KObj (rollout ))
325+ if nextIndex := status .NextStepIndex ; nextIndex != util .NextBatchIndex (rollout , status .CurrentStepIndex ) &&
326+ nextIndex > 0 && nextIndex <= int32 (len (steps )) {
327+ currentIndexBackup := status .CurrentStepIndex
328+ currentStepStateBackup := status .CurrentStepState
324329 // update the current and next stepIndex
325- canaryStatus .CurrentStepIndex = nextIndex
326- canaryStatus .NextStepIndex = util .NextBatchIndex (c . Rollout , nextIndex )
327- nextStep := c . Rollout . Spec . Strategy . Canary . Steps [nextIndex - 1 ]
330+ status .CurrentStepIndex = nextIndex
331+ status .NextStepIndex = util .NextBatchIndex (rollout , nextIndex )
332+ nextStep := steps [nextIndex - 1 ]
328333 // compare next step and current step to decide the state we should go
329- if reflect .DeepEqual (nextStep .Replicas , currentStep .Replicas ) {
330- canaryStatus .CurrentStepState = v1beta1 .CanaryStepStateTrafficRouting
334+ nextStepReplicas , _ := intstr .GetScaledValueFromIntOrPercent (nextStep .Replicas , workloadReplicas , true )
335+ if int32 (nextStepReplicas ) == * status .UpdatedReplicas {
336+ status .CurrentStepState = v1beta1 .CanaryStepStateTrafficRouting
331337 } else {
332- canaryStatus .CurrentStepState = v1beta1 .CanaryStepStateInit
338+ status .CurrentStepState = v1beta1 .CanaryStepStateInit
333339 }
334- canaryStatus .LastUpdateTime = & metav1.Time {Time : time .Now ()}
335- klog .Infof ("rollout(%s/%s) step(%d->%d) state from(%s -> %s)" ,
336- c .Rollout .Namespace , c .Rollout .Name ,
337- currentIndexBackup , canaryStatus .CurrentStepIndex ,
338- currentStepStateBackup , canaryStatus .CurrentStepState )
340+ status .LastUpdateTime = & metav1.Time {Time : time .Now ()}
341+ klog .InfoS ("step jumped" , "rollout" , klog .KObj (rollout ),
342+ "oldCurrentIndex" , currentIndexBackup , "newCurrentIndex" , status .CurrentStepIndex ,
343+ "oldCurrentStepState" , currentStepStateBackup , "newCurrentStepState" , status .CurrentStepState )
339344 return true
340345 }
346+ klog .InfoS ("step not jumped" )
341347 return false
342348}
343349
350+ func (m * canaryReleaseManager ) doCanaryJump (c * RolloutContext ) (jumped bool ) {
351+ if c .Workload == nil {
352+ return false
353+ }
354+ return doStepJump (c .Rollout , c .NewStatus , c .Rollout .Spec .Strategy .Canary .Steps , int (c .Workload .Replicas ))
355+ }
356+
344357// cleanup after rollout is completed or finished
345358func (m * canaryReleaseManager ) doCanaryFinalising (c * RolloutContext ) (bool , error ) {
346359 canaryStatus := c .NewStatus .CanaryStatus
0 commit comments