From ba523bf073df41c1a272176ed3c17ef7f8c08f16 Mon Sep 17 00:00:00 2001 From: gussan <83329336+toyamagu-2021@users.noreply.github.com> Date: Sat, 26 Aug 2023 20:52:08 +0900 Subject: [PATCH] fix: Change node in paramScope to taskNode at executeDAG (#11422) (#11682) Signed-off-by: toyamagu2021@gmail.com --- test/e2e/hooks_test.go | 80 ++++++++++++++++++++++++++++++++++++++ workflow/controller/dag.go | 2 +- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/test/e2e/hooks_test.go b/test/e2e/hooks_test.go index 8bec8e81d19f..666d5942e81f 100644 --- a/test/e2e/hooks_test.go +++ b/test/e2e/hooks_test.go @@ -333,6 +333,86 @@ spec: }) } +func (s *HooksSuite) TestTemplateLevelHooksDagHasDependencyVersion() { + s.Given(). + Workflow(`apiVersion: argoproj.io/v1alpha1 +kind: Workflow +metadata: + generateName: lifecycle-hook-tmpl-level- +spec: + templates: + - name: main + dag: + tasks: + - name: A + template: fail + hooks: + running: + template: hook + expression: tasks.A.status == "Running" + success: + template: hook + expression: tasks.A.status == "Succeeded" + - name: B + template: success + dependencies: + - A + hooks: + running: + template: hook + expression: tasks.B.status == "Running" + success: + template: hook + expression: tasks.B.status == "Succeeded" + - name: success + container: + name: '' + image: argoproj/argosay:v2 + command: + - /bin/sh + - '-c' + args: + - /bin/sleep 1; /argosay; exit 0 + - name: fail + container: + name: '' + image: argoproj/argosay:v2 + command: + - /bin/sh + - '-c' + args: + - /bin/sleep 1; /argosay; exit 1 + - name: hook + container: + name: '' + image: argoproj/argosay:v2 + command: + - /bin/sh + - '-c' + args: + - /bin/sleep 1; /argosay + entrypoint: main +`).When(). + SubmitWorkflow(). + WaitForWorkflow(fixtures.ToBeFailed). + Then(). + ExpectWorkflow(func(t *testing.T, metadata *v1.ObjectMeta, status *v1alpha1.WorkflowStatus) { + assert.Equal(t, v1alpha1.WorkflowFailed, status.Phase) + // Make sure unnecessary hooks are not triggered + assert.Equal(t, status.Progress, v1alpha1.Progress("1/2")) + }). + ExpectWorkflowNode(func(status v1alpha1.NodeStatus) bool { + return strings.Contains(status.Name, "A.hooks.running") + }, func(t *testing.T, status *v1alpha1.NodeStatus, pod *apiv1.Pod) { + assert.Equal(t, v1alpha1.NodeSucceeded, status.Phase) + }). + ExpectWorkflowNode(func(status v1alpha1.NodeStatus) bool { + return strings.Contains(status.Name, "B") + }, func(t *testing.T, status *v1alpha1.NodeStatus, pod *apiv1.Pod) { + assert.Equal(t, v1alpha1.NodeOmitted, status.Phase) + }) +} + func (s *HooksSuite) TestWorkflowLevelHooksWaitForTriggeredHook() { s.Given(). Workflow(`apiVersion: argoproj.io/v1alpha1 diff --git a/workflow/controller/dag.go b/workflow/controller/dag.go index 024c89524b8d..52e36ef1750e 100644 --- a/workflow/controller/dag.go +++ b/workflow/controller/dag.go @@ -277,7 +277,7 @@ func (woc *wfOperationCtx) executeDAG(ctx context.Context, nodeName string, tmpl woc.markNodeError(node.Name, err) return node, err } - scope.addParamToScope(fmt.Sprintf("tasks.%s.status", task.Name), string(node.Phase)) + scope.addParamToScope(fmt.Sprintf("tasks.%s.status", task.Name), string(taskNode.Phase)) _, err = woc.executeTmplLifeCycleHook(ctx, scope, dagCtx.GetTask(taskName).Hooks, taskNode, dagCtx.boundaryID, dagCtx.tmplCtx, "tasks."+taskName) if err != nil { woc.markNodeError(node.Name, err)