Golang template (helm) iterating over a list of maps

后端 未结 2 583
悲哀的现实
悲哀的现实 2021-02-10 02:12

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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-10 02:58

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

提交回复
热议问题