Argo Workflow 没有将输入参数传递给 WorkflowTemplate

Argo Workflow not passing input parameters to WorkflowTemplate

我已将我的工作流场景分解为 2 个独立的 WorkflowTemplatesouter-template 将只定义步骤,而 inner-template 将保留 job 定义,该定义将启动所需的容器,以及所有其他花哨的东西。现在,当我提交请求 request.yaml 时,它确实将参数 message 传递给外部和内部模板,但失败并出现此错误:

    hello-59jg8-394098346:
      Boundary ID:  hello-59jg8-1953291600
      Children:
        hello-59jg8-534805352
      Display Name:    [0]
      Finished At:     2021-06-15T00:41:45Z
      Id:              hello-59jg8-394098346
      Message:         child 'hello-59jg8[0].init-step[0].step-1' errored
      Name:            hello-59jg8[0].init-step[0]
      Phase:           Error
      Started At:      2021-06-15T00:41:45Z
      Template Name:   HelloWorld
      Template Scope:  namespaced/outer-template
      Type:            StepGroup
    hello-59jg8-534805352:
      Boundary ID:   hello-59jg8-1953291600
      Display Name:  step-1
      Finished At:   2021-06-15T00:41:45Z
      Id:            hello-59jg8-534805352
      Message:       inputs.parameters.message was not supplied
      Name:          hello-59jg8[0].init-step[0].step-1
      Phase:         Error
      Started At:    2021-06-15T00:41:45Z
      Template Ref:
        Name:          inner-template
        Template:      InnerJob
      Template Scope:  namespaced/outer-template
      Type:            Skipped
  Phase:               Failed
  Started At:          2021-06-15T00:41:45Z
  Stored Templates:

下面两个是WorkflowTemplate,第三个是请求。

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: stepName
            value: ""
      resource:
        action: create
        successCondition: status.succeeded > 0
        failureCondition: status.failed > 0
        manifest: |
          apiVersion: batch/v1
          kind: Job
          metadata:
            generateName: hello-pod-
            annotations:
              sidecar.istio.io/inject: "false"
          spec:
            template:
              metadata:
                annotations:
                  sidecar.istio.io/inject: "false"
              spec:
                containers:
                  - name: hellopods
                    image: centos:7
                    command: [sh, -c]
                    args: ["echo ${message}; sleep 5; echo done; exit 0"]
                    env:
                      - name: message
                        value: "{{inputs.parameters.message}}"
                      - name: stepName
                        value: "{{inputs.parameters.stepName}}"
                restartPolicy: Never
      outputs:
        parameters:
          - name: job-name
            valueFrom:
              jsonPath: '{.metadata.name}'
          - name: job-obj
            valueFrom:
              jqFilter: '.'
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
                - name: stepName
                  value: "this is step 1"
        - - name: step-2
            templateRef:
              name: inner-template
              template: InnerJob
            arguments:
              parameters:
                - name: message
                - name: stepName
                  value: "this is step 2"
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:
          - - arguments:
                parameters:
                  - name: message
                    value: "Hello World....."
              name: init-step
              templateRef:
                name: outer-template
                template: HelloWorld

在步骤中将参数传递给模板时,必须明确设置参数值。

outer-template WorkflowTemplate 中,您调用了 inner-template 两次。在每种情况下,您都半指定了 message 参数。您还必须为每个参数设置 value

您应该在 step-1step-2 中设置 value: "{{inputs.parameters.message}}"。这将从 outer-template.HelloWorld.

中提取 message 输入参数
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: stepName
                  value: "this is step 1"
        - - name: step-2
            templateRef:
              name: inner-template
              template: InnerJob
            arguments:
              parameters:
                - name: message
                  value: "{{inputs.parameters.message}}
                - name: stepName
                  value: "this is step 2"