Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helm: Passing array values through --set

i have a cronjob helm chat, i can define many jobs in values.yaml and cronjob.yaml will provision my jobs. I have faced an issue when setting the image tag id in command line, following command throw no errors but it wont update jobs image tag to new one.

helm upgrade cronjobs cronjobs/ --wait --set job.myservice.image.tag=b70d744 

cronjobs will run with old image tag how can i resolve this?

here is my cronjobs.yaml

{{- $chart_name := .Chart.Name }} {{- $chart_version := .Chart.Version | replace "+" "_" }} {{- $release_name := .Release.Name }}  {{- range $job := .Values.jobs }} --- apiVersion: batch/v1beta1 kind: CronJob metadata:   namespace: "{{ $job.namespace }}"   name: "{{ $release_name }}-{{ $job.name }}"   labels:     chart: "{{ $chart_name }}-{{ $chart_version }}" spec:   concurrencyPolicy: {{ $job.concurrencyPolicy }}   failedJobsHistoryLimit: {{ $job.failedJobsHistoryLimit }}   suspend: {{ $job.suspend }}   jobTemplate:     spec:       template:         metadata:           labels:             app: {{ $release_name }}             cron: {{ $job.name }}         spec:           containers:           - image: "{{ $job.image.repository }}:{{ $job.image.tag }}"             imagePullPolicy: {{ $job.image.imagePullPolicy }}             ports:               - name: http                 containerPort: 80                 protocol: TCP             name: {{ $job.name }}             args: {{ toYaml $job.args | indent 12 }}             env: {{ toYaml $job.image.env | indent 12 }}             volumeMounts:             - name: nfs               mountPath: "{{ $job.image.nfslogpath }}"           restartPolicy: OnFailure           imagePullSecrets:             - name: {{ $job.image.secret }}           volumes:             - name: nfs               nfs:                 server: "{{ $job.image.server }}"                 path: "{{ $job.image.nfspath }}"                 readOnly: false   schedule: {{ $job.schedule | quote }}   successfulJobsHistoryLimit: {{ $job.successfulJobsHistoryLimit }}   {{- end }} 

here is my values.yaml

jobs:   - name: myservice     namespace: default     image:       repository: xxx.com/myservice       tag: fe4544       pullPolicy: Always       secret: xxx       nfslogpath: "/var/logs/"       nfsserver: "xxx"       nfspath: "/nfs/xxx/cronjobs/"       nfsreadonly: false       env:     schedule: "*/5 * * * *"     args:     failedJobsHistoryLimit: 1     successfulJobsHistoryLimit: 3     concurrencyPolicy: Forbid     suspend: false    - name: myservice2     namespace: default     image:       repository: xxxx/myservice2       tag: 1dff39a       pullPolicy: IfNotPresent       secret: xxxx       nfslogpath: "/var/logs/"       nfsserver: "xxxx"       nfspath: "/nfs/xxx/cronjobs/"       nfsreadonly: false       env:     schedule: "*/30 * * * *"     args:     failedJobsHistoryLimit: 1     successfulJobsHistoryLimit: 2     concurrencyPolicy: Forbid     suspend: false 
like image 924
Jack Avatar asked Dec 19 '18 07:12

Jack


People also ask

What is CRDs in Helm?

This section of the Best Practices Guide deals with creating and using Custom Resource Definition objects. When working with Custom Resource Definitions (CRDs), it is important to distinguish two different pieces: There is a declaration of a CRD.

How do you update helm chart with new values?

To perform a helm release upgrade using the CLI, run the following command provided: helm upgrade <release name> <chart directory> -f my-values. yaml using the configuration specified in the customized values. yaml file. After a successful upgrade, the helm will return the following message.

How do you pass values to helm chart?

You can use a --values flag in your Helm commands to override the values in a chart and pass in a new file. Specify the name of the new file after the --values flag in the Helm command. Example: helm upgrade --install <service> -f values.


1 Answers

If you need to pass array values you can use curly braces (unix shell require quotes):

--set test={x,y,z} --set "test={x,y,z}" 

Result YAML:

test:   - x   - y   - z 

Source: https://helm.sh/docs/intro/using_helm/#the-format-and-limitations-of---set

EDITED : added double-quotes for unix shell like bash

like image 74
Thiago Falcao Avatar answered Sep 24 '22 00:09

Thiago Falcao