0

工作流程:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: my-workflow-
spec:
  entrypoint: main
  arguments:
    parameters:
      - name: configmap
        value: my-configmap
      - name: secret
        value: my-secret
  templates:
    - name: main
      steps:
        - - name: main
            templateRef:
              name: my-template
              template: main
            arguments:
              parameters:
                - name: configmap
                  value: "{{workflow.parameters.configmap}}"
                - name: secret
                  value: "{{workflow.parameters.secret}}"

模板:

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: my-template
spec:
  entrypoint: main
  templates:
    - name: main
      inputs:
        parameters:
          - name: configmap
        parameters:
          - name: secret
      container:
        image: my-image:1.2.3
        envFrom:
          - configMapRef:
            name: "{{inputs.parameters.configmap}}"
          - secretRef:
            name: "{{inputs.parameters.secret}}"

通过 Argo UI 部署时,我在启动 pod 时收到来自 Kubernetes 的以下错误:

spec.containers[1].envFrom: Invalid value: \"\": must specify one of: `configMapRef` or `secretRef`

envFromArgo 文档支持并记录了使用: https ://argoproj.github.io/argo-workflows/fields/ 。为什么 Kubernetes 在这里抱怨?

4

1 回答 1

2

如评论中所述,您的清单存在一些问题。它们是有效的 YAML,但 YAML 不会反序列化为有效的 Argo 自定义资源。

  1. 在工作流中,您复制了中的parameters密钥spec.templates[0].inputs
  2. 在 WorkflowTemplate 中,您已将configMapRefsecretRef名称放置在与键相同的级别。configMapRefsecretRef是对象,所以name键应该嵌套在每个对象下。

这些是更正后的清单:

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: my-template
spec:
  entrypoint: main
  templates:
    - name: main
      inputs:
        parameters:
          - name: configmap
          - name: secret
      container:
        image: my-image:1.2.3
        envFrom:
          - configMapRef:
              name: "{{inputs.parameters.configmap}}"
          - secretRef:
              name: "{{inputs.parameters.secret}}"

---

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: my-workflow-
spec:
  entrypoint: main
  arguments:
    parameters:
      - name: configmap
        value: my-configmap
      - name: secret
        value: my-secret
  templates:
    - name: main
      steps:
        - - name: main
            templateRef:
              name: my-template
              template: main
            arguments:
              parameters:
                - name: configmap
                  value: "{{workflow.parameters.configmap}}"
                - name: secret
                  value: "{{workflow.parameters.secret}}"

Argo Workflows 支持基于 IDE 的验证,可以帮助您发现/避免这些问题。

于 2021-05-13T19:02:35.007 回答