Home > Enterprise >  Kubernetes Cronjob. Upgrade Schedule with helm command. Set does not accept * as first character
Kubernetes Cronjob. Upgrade Schedule with helm command. Set does not accept * as first character

Time:11-30

I have a cronjob running in an aks. Its rollout with an helm chart:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: {{ include "gdp-chart.fullname" . }}-importjob
  labels:
    {{- include "gdp-chart.labels" . | nindent 4 }}
spec:
  suspend: {{ .Values.import.suspend }}
  schedule: {{ .Values.import.schedule }}
  jobTemplate:
    metadata:
      name: import-job
    spec:
      template:
        spec:
          containers:
          - image: curlimages/curl
            name: import-job
            args:
            - "$(GDP_INT_IMPORT_URL)"
            {{- with .Values.import.env}}
            env:
              {{- toYaml . | nindent 12}}
            {{- end}}
          restartPolicy: Never

I want to set, spec.schedule with helm command, what works if the first character is an number:

helm upgrade --reuse-values --set import.schedule='1 13 8 12 *' gdp gdp-api

But if its * it fails:

helm upgrade --reuse-values --set import.schedule='* 13 8 12 *' gdp gdp-api

Error: UPGRADE FAILED: YAML parse error on gdp-api/templates/cronjob.yaml: error converting YAML to JSON: yaml: line 12: did not find expected alphabetic or numeric character

why is that so and can i somehow escape this? What also surprises me is that the error in another line.

CodePudding user response:

If a YAML value starts with a * then it is a YAML alias node that refers to another &anchor node earlier in the document. (It's somewhat unusual to use this particular YAML feature in Kubernetes and especially with Helm; you see it occasionally in Docker Compose setups.)

schedule: * 13 8 12 *

# looks like (not valid Kubernetes syntax)
x-schedule: &sched '* 13 8 12 *'
schedule: *sched

To avoid this, you need to quote the output value, so it doesn't look like a YAML anchor.

schedule: "* 13 8 12 *"

There are a couple of ways to do this in a Helm chart; either directly insert the quotes, or the naïve quote helper, or the more robust but less-documented toJson helper.

{{/* any of these will work */}}
schedule: "{{ .Values.import.schedule }}"
schedule: {{ quote .Values.import.schedule }}
schedule: {{ .Values.import.schedule | quote }}
schedule: {{ toJson .Values.import.schedule }}
  • Related