kubernetesargo-workflows

Argo workflows template: using variable for name in valueFrom


So I try to get the value from a configMap as input to a template in a Argo workflow template. I want to use a variable in the name attribute, see example.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: configmapkeyref-variable-name
spec:
  entrypoint: prepare
  ttlStrategy:
    secondsAfterCompletion: 3600 # 1h
  podGC:
    strategy: OnWorkflowSuccess
  arguments:
    parameters:
      - name: system
        value: a
  templates:
    - name: prepare
      inputs:
        parameters:
          - name: system
            value: '{{workflow.parameters.system}}'
          - name: hook
            valueFrom:
              configMapKeyRef:
                name: "hooks-{{workflow.parameters.system}}" # This don't work!
                # name: "hooks-a" # This works!
                key: prepare
              default: "default value"
      script:
        image: ubuntu:latest
        imagePullPolicy: Always
        command: ["/bin/bash"]
        source: |
          echo "system: {{workflow.parameters.system}}"
          echo "system: {{inputs.parameters.system}}"
          echo "HOOK: {{inputs.parameters.hook}}"

I'm not sure it this is possible at all but need to get fetch different configMap depending on the value of parameter "system".

I wonder if anyone can help me out with this? =) I have spent a lot of time to read on the documentation pages but i'm stuck :/

Best regards Thomas


Solution

  • I adjusted my example using an env var instead of an input which work as I wanted to.

    apiVersion: argoproj.io/v1alpha1
    kind: WorkflowTemplate
    metadata:
      name: configmapkeyref-variable-name
    spec:
      entrypoint: prepare
      ttlStrategy:
        secondsAfterCompletion: 3600 # 1h
      podGC:
        strategy: OnWorkflowSuccess
      arguments:
        parameters:
          - name: system
            value: adam
      templates:
        - name: prepare
          inputs:
            parameters:
              - name: system
                value: '{{workflow.parameters.system}}'
          script:
            image: ubuntu:latest
            imagePullPolicy: Always
            command: ["/bin/bash"]
            env:
              - name: HOOK
                valueFrom:
                  configMapKeyRef:
                    name: "hooks-{{inputs.parameters.system}}"
                    key: prepare
                    optional: true
            source: |
              echo "system: {{workflow.parameters.system}}"
              echo "system: {{inputs.parameters.system}}"
              echo "HOOK: $HOOK"
    

    This works for me and I don't know why I can't use a variable in the "name" attribute of the ConfigMapKeyRef when it is used in the "input" section but works in the "env" section, could be by design or a bug.