Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve output artifact of the step's hook. Fixes: #13860 #13861

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) TestHooksWithArtifactsInSteps() {
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"]
source: |
echo "File Path: {{inputs.artifacts.file_path.path}}"
`).When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeCompleted).
Then().
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.success")
}, 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))
}
2 changes: 1 addition & 1 deletion workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ func (ctx *templateValidationCtx) validateSteps(scope map[string]interface{}, tm
return errors.Errorf(errors.CodeBadRequest, "templates.%s.steps[%d].%s %s", tmpl.Name, i, step.Name, err.Error())
}

if step.HasExitHook() {
if step.HasExitHook() || step.Hooks != nil {
ctx.addOutputsToScope(resolvedTmpl, fmt.Sprintf("steps.%s", step.Name), scope, false, false)
}
resolvedTemplates[step.Name] = resolvedTmpl
Expand Down
Loading