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 committed Aug 26, 2023
1 parent bc9b644 commit ba523bf
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
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion workflow/controller/dag.go
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 ba523bf

Please sign in to comment.