argo-workflows

How to reuse enum across Argo workflow templates?


Say I have a parameter with a big enum:

# yaml-language-server: $schema=https://raw.githubusercontent.com/argoproj/argo-workflows/v3.4.13/api/jsonschema/schema.json

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: time-zone-parameter
spec:
  arguments:
    parameters:
      - name: time-zone
        description: Time zone
        enum:
          - 'Africa/Abidjan'
          - …

Is it possible to reuse this enum in another WorkflowTemplate? I'd rather not have to copy and paste it all over the place.

Similar question.


Solution

  • Assuming it's a helm template you could do something like

    # chart/templates/_helpers.tpl
    {{- define "timeZoneEnum" -}}
    enum:
      - 'Africa/Abidjan'
      - …
    {{- end -}}
    
    
    # chart/templates/$your-argo-template-workflow.yaml
    apiVersion: argoproj.io/v1alpha1
    kind: WorkflowTemplate
    metadata:
      name: time-zone-parameter
    spec:
      arguments:
        parameters:
          - name: time-zone
            description: Time zone
    {{ include "timeZoneEnum" . | indent 8 }}