refactoring helm template files for single object and array of objects

  Kiến thức lập trình

I need help with refactoring the template files in helm

Below is the config.yaml template file –

{{- define "service.config" -}}
{{- $config := .Values.config}}
---
apiVersion: batch/v1
kind: Job
metadata:
  generateName: {{ $config.name }}
  annotations:
    config.type: {{ $config.type }}
    config.policy: {{ $config.policy }}
{{- end }}
{{- end }}

Below is the configs.yaml template file –

{{- define "service.configs" -}}
{{- range $config := .Values.configs}}
---
apiVersion: batch/v1
kind: Job
metadata:
  generateName: {{ $config.name }}
  annotations:
    config.type: {{ $config.type }}
    config.policy: {{ $config.policy }}
{{- end }}
{{- end }}

you can see the config is for single value and configs is for array of values.
how can I refactor this?

LEAVE A COMMENT