Skip to content

Commit

Permalink
fix: Change node in paramScope to taskNode at executeDAG (#11422) (#1…
Browse files Browse the repository at this point in the history
…1682)

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>
  • Loading branch information
toyamagu-2021 authored and terrytangyuan committed Sep 5, 2023
1 parent a85c4b8 commit 579a8e2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
80 changes: 80 additions & 0 deletions test/e2e/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,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
Expand Down
2 changes: 1 addition & 1 deletion workflow/controller/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 579a8e2

Please sign in to comment.