Skip to content

Commit

Permalink
fix: resolve output artifact of the step's hook. Fixes: argoproj#13860
Browse files Browse the repository at this point in the history
Signed-off-by: shuangkun <[email protected]>
  • Loading branch information
shuangkun committed Nov 3, 2024
1 parent 4742e9d commit b04e1aa
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/apis/workflow/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ func (lch *LifecycleHook) WithArgs(args Arguments) *LifecycleHook {
var _ TemplateReferenceHolder = &WorkflowStep{}

func (step *WorkflowStep) HasExitHook() bool {
return (step.Hooks != nil && step.Hooks.HasExitHook()) || step.OnExit != ""
return (step.Hooks != nil) || step.OnExit != ""
}

func (step *WorkflowStep) GetExitHook(args Arguments) *LifecycleHook {
Expand Down
60 changes: 60 additions & 0 deletions test/e2e/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,66 @@ spec:
}))
}

func (s *HooksSuite) TestHooksWithArtifacts() {
var onExitNodeName string
(s.Given().
Workflow(`apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: test-hook-
spec:
entrypoint: main
templates:
- name: main
steps:
- - name: hello1
template: parameterization
hooks:
success:
template: success-hook
expression: steps["hello1"].status == "Succeeded"
arguments:
artifacts:
- name: file_path
from: "{{steps.hello1.outputs.artifacts.result}}"
- name: parameterization
script:
image: python:alpine3.6
command: [python]
source: |
import os
with open("foo.txt", "w") as f:
f.write("Hello")
os.rename('foo.txt', '/tmp/foo.txt')
outputs:
artifacts:
- name: result
path: /tmp/foo.txt
- name: success-hook
inputs:
artifacts:
- name: file_path
path: /tmp/file_path
script:
image: python:alpine3.6
command: [sh, -c]
source: |
echo "File Path: {{inputs.artifacts.file_path.path}}"
`).When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeCompleted).
ExpectWorkflow(func(t *testing.T, metadata *v1.ObjectMeta, status *v1alpha1.WorkflowStatus) {
assert.Equal(t, v1alpha1.WorkflowSucceeded, status.Phase)
}).
ExpectWorkflowNode(func(status v1alpha1.NodeStatus) bool {
return strings.Contains(status.Name, ".hooks.succeed")
}, func(t *testing.T, status *v1alpha1.NodeStatus, pod *apiv1.Pod) {
assert.Equal(t, v1alpha1.NodeSucceeded, status.Phase)
}))
}

func TestHooksSuite(t *testing.T) {
suite.Run(t, new(HooksSuite))
}

0 comments on commit b04e1aa

Please sign in to comment.