Golang template (helm) iterating over a list of maps

后端 未结 2 1265
不知归路
不知归路 2021-02-10 02:17

I\'m using helm to generate kubernetes yamls.

My values.yaml looks like this:

...
jobs:
  - nme: job1
    command: [sh, -c, \"/app/deployment/start.sh j         


        
2条回答
  •  星月不相逢
    2021-02-10 03:06

    I ended up saving the global context and then updating all of my references like this:

    {{ $global := . }}
    {{ range $i, $job := .Values.jobs -}}
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: {{ template "name" $global }}-{{ $job.name }}
      labels:
        chart: "{{ $global.Chart.Name }}-{{ $global.Chart.Version | replace "+" "_" }}"
    spec:
      activeDeadlineSeconds: {{ $job.activeDeadlineSeconds }}
      template:
        metadata:
          labels:
            app: {{ template "name" $global }}-{{ $job.name }}
        spec:
          containers:
          - name: {{ $global.Chart.Name }}
            image: "{{ $global.Values.image.repository }}:{{ $global.Values.image.tag }}"
            imagePullPolicy: {{ $global.Values.image.pullPolicy }}
            command: {{ $job.command }}
            env:
    {{ toYaml $global.Values.service.env | indent 10 }}
            ports:
            - containerPort: {{ $global.Values.service.internalPort }}
    {{- end }}
    

提交回复
热议问题