argoproj / argo-workflows

Workflow Engine for Kubernetes
https://argo-workflows.readthedocs.io/
Apache License 2.0
15.13k stars 3.21k forks source link

Cannot access output parameters in non-exit hook #8954

Open Tolsto opened 2 years ago

Tolsto commented 2 years ago

Checklist

* [x] Double-checked my configuration. * [x] Tested using the latest version. * [x] Used the Emissary executor. ## Summary When trying to access output parameters in hooks other than `exit` I get `templates.main.steps failed to resolve {{steps.step-1.outputs.parameters.result}} ` Argo 3.3.6 ## Diagnostics This is the example from https://github.com/argoproj/argo-workflows/blob/df37649251f5791c40802defd923dd735924eb3a/examples/exit-handler-with-param.yaml with `exit` replaced with `foo` ```yaml apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: exit-handler-with-param- labels: workflows.argoproj.io/test: "true" annotations: workflows.argoproj.io/description: | onExitTemplate enables workflow to pass the arguments (parameters/Artifacts) to exit handler template. workflows.argoproj.io/version: '>= 3.1.0' spec: entrypoint: main templates: - name: main steps: - - name: step-1 template: output hooks: foo: template: exit arguments: parameters: - name: message value: "{{steps.step-1.outputs.parameters.result}}" - name: output container: image: python:alpine3.6 command: [sh, -c] args: ["echo -n hello world > /tmp/hello_world.txt"] outputs: parameters: - name: result valueFrom: default: "Foobar" # Default value to use if retrieving valueFrom fails. If not provided workflow will fail instead path: /tmp/hello_world.txt - name: exit inputs: parameters: - name: message script: image: python:alpine3.6 command: [ python ] source: | print("{{inputs.parameters.message}}") ``` ```bash level=info msg="Processing workflow" namespace=default workflow=exit-handler-with-param-jrg25 level=warning msg="Non-transient error: templates.main.steps failed to resolve {{steps.step-1.outputs.parameters.result}}" level=info msg="Updated phase -> Failed" namespace=default workflow=exit-handler-with-param-jrg25 level=info msg="Updated message -> invalid spec: templates.main.steps failed to resolve {{steps.step-1.outputs.parameters.result}}" namespace=default workflow=exit-handler-with-param-jrg25 level=info msg="Marking workflow completed" namespace=default workflow=exit-handler-with-param-jrg25 level=error msg="Unable to set ExecWorkflow" error="templates.main.steps failed to resolve {{steps.step-1.outputs.parameters.result}}" namespace=default workflow=exit-handler-with-param-jrg25 level=info msg="Checking daemoned children of " namespace=default workflow=exit-handler-with-param-jrg25 level=info msg="cleaning up pod" action=deletePod key=default/exit-handler-with-param-jrg25-1340600742-agent/deletePod ``` ---

Message from the maintainers:

Impacted by this bug? Give it a 👍. We prioritise the issues with the most 👍.

terrytangyuan commented 2 years ago

@sarabala1979 Could you take a look?

sarabala1979 commented 2 years ago

yes We will do it

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is a mentoring request, please provide an update here. Thank you for your contributions.

terrytangyuan commented 2 years ago

@sarabala1979 Who's working on this?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is a mentoring request, please provide an update here. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been closed due to inactivity. Feel free to re-open if you still encounter this issue.

Tolsto commented 2 years ago

Still experiencing this issue.

yavulan commented 2 years ago

@sarabala1979 @terrytangyuan It would be really useful to have this fixed.

My use case is having the exit hook to access and work with STDOUT of each task in dag workflow within a sensor (v3.3.9). And, most probably, this issue is the blocker for me. I'm using the same approach, but in my case the value is not interpolated correctly, so print("{{inputs.parameters.message}}") prints exactly this sting {{steps.step-1.outputs.parameters.result}}, not it's value.

Maybe there is some obvious approach that I'm missing to easily access STDOUT of each task from the exit hook?

Thank you.

terrytangyuan commented 2 years ago

Could you try the most recent release and see if the problem persists?

yavulan commented 2 years ago

In my case the issue still persist with releases 3.3.9 and v3.4.0-rc2

terrytangyuan commented 2 years ago

@sarabala1979 Could this be fixed by one of your recent commits?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is a mentoring request, please provide an update here. Thank you for your contributions.

yavulan commented 2 years ago

Comment to prevent closing

sarabala1979 commented 2 years ago

@Tolsto @yavulan can you try on v3.4.2? https://github.com/argoproj/argo-workflows/pull/9229

yavulan commented 2 years ago

Using the release 3.4.2 (which was released yesterday), the issue reproducing code produces an error - Failed: invalid spec: templates.main.steps failed to resolve {{steps.step-1.outputs.parameters.result}}. If you change hook name from foo to success - the error message is the same. But it works as expected with exit hook.

Though, we have an improvement - previously when you change {{steps.step-1.outputs.parameters.result}} to {{steps.step-1.status}} - it printed {{steps.step-1.status}}. Now it prints Succeeded. But if you use {{steps.step-1.exitCode}} - it prints string {{steps.step-1.exitCode}}, and the same problem is with {{steps.step-1.outputs.result}}.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is a mentoring request, please provide an update here. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is a mentoring request, please provide an update here. Thank you for your contributions.

Joibel commented 1 year ago

This does not work because the docs say it should not work. What does work (counter to the docs perhaps) is

        - - name: step-1
            template: output
        - - name: step-2
            template: output
            hooks:
              foo:
                template: exit
                expression: steps["step-1"].status == "Succeeded"
                arguments:
                  parameters:
                    - name: message
                      value: "{{steps.step-1.outputs.parameters.result}}"

Because the output of step 1 is available when step 2 runs.

What also doesn't work is the lack of expression in the foo hook, causing other issues. #10910 covers this.

In theory it should be possible to make step-1 get it's own outputs in the Succeeded or Failed status events, but the same is achievable in an exit hook already, so I'm suggesting just documenting this.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is a mentoring request, please provide an update here. Thank you for your contributions.