diff --git a/pkg/kubectl-argo-rollouts/cmd/promote/promote.go b/pkg/kubectl-argo-rollouts/cmd/promote/promote.go index 8677270e2c..743a59c295 100644 --- a/pkg/kubectl-argo-rollouts/cmd/promote/promote.go +++ b/pkg/kubectl-argo-rollouts/cmd/promote/promote.go @@ -159,7 +159,7 @@ func getPatches(rollout *v1alpha1.Rollout, skipCurrentStep, skipAllStep, full bo } unifiedPatch = []byte(unpauseAndClearPauseConditionsPatch) - if rollout.Spec.Strategy.Canary != nil { + if rollout.Spec.Strategy.Canary != nil && !rollout.Status.ControllerPause { _, index := replicasetutil.GetCurrentCanaryStep(rollout) // At this point, the controller knows that the rollout is a canary with steps and GetCurrentCanaryStep returns 0 if // the index is not set in the rollout diff --git a/pkg/kubectl-argo-rollouts/cmd/promote/promote_test.go b/pkg/kubectl-argo-rollouts/cmd/promote/promote_test.go index 1b03501cf1..4d06e307f4 100644 --- a/pkg/kubectl-argo-rollouts/cmd/promote/promote_test.go +++ b/pkg/kubectl-argo-rollouts/cmd/promote/promote_test.go @@ -144,6 +144,56 @@ func TestPromoteCmdSuccesSkipAllSteps(t *testing.T) { assert.Empty(t, stderr) } +func TestPromoteCmdSuccesFirstStepWithDefaultPromote(t *testing.T) { + ro := v1alpha1.Rollout{ + ObjectMeta: metav1.ObjectMeta{ + Name: "guestbook", + Namespace: metav1.NamespaceDefault, + }, + Spec: v1alpha1.RolloutSpec{ + Strategy: v1alpha1.RolloutStrategy{ + Canary: &v1alpha1.CanaryStrategy{ + Steps: []v1alpha1.CanaryStep{ + { + SetWeight: pointer.Int32Ptr(1), + }, + { + SetWeight: pointer.Int32Ptr(2), + }, + }, + }, + }, + }, + } + + tf, o := options.NewFakeArgoRolloutsOptions(&ro) + defer tf.Cleanup() + fakeClient := o.RolloutsClient.(*fakeroclient.Clientset) + fakeClient.PrependReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { + if patchAction, ok := action.(kubetesting.PatchAction); ok { + patchRo := v1alpha1.Rollout{} + err := json.Unmarshal(patchAction.GetPatch(), &patchRo) + if err != nil { + panic(err) + } + ro.Status.CurrentStepIndex = patchRo.Status.CurrentStepIndex + } + return true, &ro, nil + }) + + cmd := NewCmdPromote(o) + cmd.PersistentPreRunE = o.PersistentPreRunE + cmd.SetArgs([]string{"guestbook"}) + + err := cmd.Execute() + assert.Nil(t, err) + assert.Equal(t, int32(1), *ro.Status.CurrentStepIndex) + stdout := o.Out.(*bytes.Buffer).String() + stderr := o.ErrOut.(*bytes.Buffer).String() + assert.Equal(t, stdout, "rollout 'guestbook' promoted\n") + assert.Empty(t, stderr) +} + func TestPromoteCmdSuccesFirstStep(t *testing.T) { ro := v1alpha1.Rollout{ ObjectMeta: metav1.ObjectMeta{