Search code examples
kubernetesargo-workflowsargoproj

Argo template not able to read from output file location


An outer-template which calls inner-template twice since there are 2 steps. Inner template is a simple container which write some text to /command_output/result.txt. The workflow outputs attempts to read it thru:

- name: previous_step_output
  valueFrom:
    path: /command_output/result.txt

This does appear to be working for some reason. Based on the documentation I also created volumes and volumeMounts The error is:

 Service Account Name:  argo
  Templates:
    Arguments:
    Inputs:
    Metadata:
    Name:  HelloWorld
    Outputs:
    Steps:
      [map[arguments:map[parameters:[map[name:message value:Hello World.....]]] name:init-step templateRef:map[name:outer-template template:HelloWorld]]]
Status:
  Conditions:
    Status:     True
    Type:       Completed
  Finished At:  2021-06-17T23:50:37Z
  Message:      runtime error: invalid memory address or nil pointer dereference
  Nodes:
    hello-css4z:

Need some advise on what is missing. Attaching inner-template, outer-template and the request.yaml.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: inner-template
  namespace: cali
  labels:
    workflows.argoproj.io/controller-instanceid: cali
spec:
  templates:
    - name: InnerJob
      metadata:
        annotations:
          sidecar.istio.io/inject: "false"
      inputs:
        parameters:
          - name: message
          - name: previous_step_output
            value: ""
      resource:
        action: create
        successCondition: status.succeeded > 0
        failureCondition: status.failed > 0
        manifest: |
          apiVersion: batch/v1
          kind: Job
          metadata:
            namespace: default
            generateName: hellojob-
            annotations:
              sidecar.istio.io/inject: "false"
          spec:
            template:
              metadata:
                annotations:
                  sidecar.istio.io/inject: "false"
              spec:
                volumes:
                  - emptyDir: {}
                    name: cali-mount
                containers:
                  - name: export-tenant
                    image: centos:7
                    command: [sh, -c]
                    args: ["echo 'some result' > /command_output/result.txt; cat /command_output/result.txt; sleep 5; echo done; exit 0"]
                    env:
                      - name: message
                        value: "{{inputs.parameters.message}}"
                      - name: previous_step_output
                        value: "{{inputs.parameters.previous_step_output}}"
                    volumeMounts:
                      - mountPath: /command_output
                        name: cali-mount
                restartPolicy: Never
      outputs:
        parameters:
          - name: job-name
            valueFrom:
              jsonPath: '{.metadata.name}'
          - name: job-obj
            valueFrom:
              jqFilter: '.'
          - name: previous_step_output
            valueFrom:
              path: /command_output/result.txt
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: outer-template
  namespace: cali
  labels:
    workflows.argoproj.io/controller-instanceid: cali
spec:
  entrypoint: HelloWorld
  templates:
    - name: HelloWorld
      inputs:
        parameters:
          - name: message
      steps:
        - - name: step-1
            templateRef:
              name: inner-template
              template: InnerJob
            arguments:
              parameters:
                - name: message
                  value: "{{inputs.parameters.message}}"
        - - name: step-2
            templateRef:
              name: inner-template
              template: InnerJob
            arguments:
              parameters:
                - name: message
                  value: "{{inputs.parameters.message}}"
                - name: previous_step_output
                  value: "{{steps.step-1.outputs.parameters.previous_step_output}}"

request payload:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: hello-
  namespace: cali
  labels:
    workflows.argoproj.io/controller-instanceid: cali
spec:
  entrypoint: HelloWorld
  serviceAccountName: argo
  templates:
      - name: HelloWorld
        steps:
          - - name: init-step
              arguments:
                parameters:
                  - name: message
                    value: "Hello World....."
              templateRef:
                name: outer-template
                template: HelloWorld

Solution

  • As far as I can tell, Argo Workflows resource templates do not support reading files as output parameters.

    It looks like the only built-in method of communicating from a job resource to the instantiating workflow is via the JSON representation of the job resource itself.

    I would recommend converting the Job to a normal container template in the workflow. Then you could use all the typical communication methods (reading directly from stdout, reading a file into an output param, reading an output artifact, etc.).