Search code examples
argo-workflows

Argo Workflows: Set container image from enviroment variables


I'm trying to set the container image for a template from environment variables. I've tried this:

- name: sftp-to-gcp-bucket
    script:
      image: "gcr.io/{{$CONTAINER}}/imagename:{{$VERSION}}"
      ...
      ...
      env:
      - name: CONTAINER
        valueFrom:
        secretKeyRef:
          name: enviroment-vars
          key: contenedor
      - name: VERSION
        valueFrom:
        secretKeyRef:
          name: enviroment-vars
          key: version

And I have the k8s secrets set correctly:

Name:         enviroment-vars
Namespace:    argo
Labels:       <none>
Annotations:  <none>

Type:  Opaque

Data
====
container:                  17 bytes
version:                    5 bytes

But the env variables doesn't seem to get injected into the image field... Do I have to make another template to parse the secrets and from that output inject them into the image?


Solution

  • The environment variables only have meaning in the container created by Argo Workflows. They are not accessible in the Workflow itself.

    There are a number of ways to load Kubernetes resources and use them as variables in a Workflow.

    In this case, I'd recommend loading parameters from a ConfigMap.

    apiVersion: argoproj.io/v1alpha1
    kind: Workflow
    spec:
      templates:
      - name: sftp-to-gcp-bucket
        inputs:
          parameters:
            - name: container
              valueFrom:
                configMapKeyRef:
                  name: enviroment-vars
                  key: contenedor
            - name: version
              valueFrom:
                configMapKeyRef:
                  name: enviroment-vars
                  key: version
        script:
          image: "gcr.io/{{inputs.parameters.container}}/imagename:{{inputs.parameters.version}}"