From 269b54cbd1a54341497c0cb301fbdd03502c62ca Mon Sep 17 00:00:00 2001 From: jswxstw Date: Tue, 27 Aug 2024 12:50:39 +0800 Subject: [PATCH] fix: Do not reset the root node by default. Fixes #13196 (#13198) Signed-off-by: oninowang --- test/e2e/cli_test.go | 41 +++++++++++++++++++ ...try-workflow-with-failed-exit-handler.yaml | 18 ++++++++ workflow/util/util.go | 7 ---- 3 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 test/e2e/testdata/retry-workflow-with-failed-exit-handler.yaml diff --git a/test/e2e/cli_test.go b/test/e2e/cli_test.go index 9df058c717cb..380fd454dea5 100644 --- a/test/e2e/cli_test.go +++ b/test/e2e/cli_test.go @@ -986,6 +986,47 @@ func (s *CLISuite) TestRetryWorkflowWithContinueOn() { }) } +func (s *CLISuite) TestRetryWorkflowWithFailedExitHandler() { + var workflowName string + s.Given(). + Workflow(`@testdata/retry-workflow-with-failed-exit-handler.yaml`). + When(). + SubmitWorkflow(). + WaitForWorkflow(fixtures.ToBeFailed). + Then(). + ExpectWorkflow(func(t *testing.T, metadata *metav1.ObjectMeta, status *wfv1.WorkflowStatus) { + workflowName = metadata.Name + assert.Len(t, status.Nodes, 2) + }). + RunCli([]string{"retry", workflowName}, func(t *testing.T, output string, err error) { + if assert.NoError(t, err, output) { + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + } + }) + + s.Given(). + When(). + WaitForWorkflow(fixtures.ToBeCompleted). + Then(). + ExpectWorkflow(func(t *testing.T, metadata *metav1.ObjectMeta, status *wfv1.WorkflowStatus) { + workflowName = metadata.Name + assert.Equal(t, wfv1.WorkflowFailed, status.Phase) + assert.Len(t, status.Nodes, 2) + }). + ExpectWorkflowNode(func(status wfv1.NodeStatus) bool { + return status.Name == workflowName + }, func(t *testing.T, status *wfv1.NodeStatus, pod *corev1.Pod) { + assert.Equal(t, wfv1.NodeSucceeded, status.Phase) + }). + ExpectWorkflowNode(func(status wfv1.NodeStatus) bool { + return strings.Contains(status.Name, ".onExit") + }, func(t *testing.T, status *wfv1.NodeStatus, pod *corev1.Pod) { + assert.Equal(t, wfv1.NodeFailed, status.Phase) + assert.Contains(t, status.Message, "exit code 1") + }) +} + func (s *CLISuite) TestWorkflowStop() { s.Given(). Workflow("@smoke/basic.yaml"). diff --git a/test/e2e/testdata/retry-workflow-with-failed-exit-handler.yaml b/test/e2e/testdata/retry-workflow-with-failed-exit-handler.yaml new file mode 100644 index 000000000000..565485c2b7f8 --- /dev/null +++ b/test/e2e/testdata/retry-workflow-with-failed-exit-handler.yaml @@ -0,0 +1,18 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Workflow +metadata: + name: retry-workflow-with-failed-exit-handler +spec: + entrypoint: hello + onExit: exit-handler + templates: + - name: hello + container: + image: alpine:3.18 + command: [sh, -c] + args: ["echo hello"] + - name: exit-handler + container: + image: alpine:3.18 + command: [sh, -c] + args: ["exit 1"] \ No newline at end of file diff --git a/workflow/util/util.go b/workflow/util/util.go index f621461c3033..3a3246f78fce 100644 --- a/workflow/util/util.go +++ b/workflow/util/util.go @@ -989,13 +989,6 @@ func FormulateRetryWorkflow(ctx context.Context, wf *wfv1.Workflow, restartSucce // Do not allow retry of workflows with pods in Running/Pending phase return nil, nil, errors.InternalErrorf("Workflow cannot be retried with node %s in %s phase", node.Name, node.Phase) } - - if node.Name == wf.ObjectMeta.Name { - log.Debugf("Reset root node: %s", node.Name) - newNode := node.DeepCopy() - newWF.Status.Nodes.Set(newNode.ID, resetNode(*newNode)) - continue - } } if len(deletedNodes) > 0 {