Search code examples
kubernetesargo-workflows

Argo Workflow error when using envFrom field


Workflow:

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}}"

Template:

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}}"

When deployed through the Argo UI I receive the following error from Kubernetes when starting the pod:

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

Using envFrom is supported and documented in the Argo documentation: https://argoproj.github.io/argo-workflows/fields/. Why is Kubernetes complaining here?


Solution

  • As mentioned in the comments, there are a couple issues with your manifests. They're valid YAML, but that YAML does not deserialize into valid Argo custom resources.

    1. In the Workflow, you have duplicated the parameters key in spec.templates[0].inputs.
    2. In the WorkflowTemplate, you have placed the configMapRef and secretRef names at the same level as the keys. configMapRef and secretRef are objects, so the name key should be nested under each of those.

    These are the corrected manifests:

    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 supports IDE-based validation which should help you find/avoid these issues.