YAML parse error on curl command parameters

10/22/2019

I'm trying to create a small cronjob in k8s that simply executes a HTTP Post using curl in a busybox container. The formatting is wrong though and i cannot figure out what i have to change.

I've tried googling the error message i'm getting as well as change the formatting of the curl command in various ways without any success.

apiVersion: batch/v1beta1
kind: CronJob
#namespace: test
metadata:
  name: test-cron
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: test-cron
            image: busybox
            args:
            - /bin/sh
            - -c
            - curl "https://test-es01.test.svc.clu01.test.local:9200/logs_write/_rollover" -H 'Content-Type: application/json' -d '{"conditions: {"max_size": "5gb"}}'
          restartPolicy: OnFailure

I then try to run the file:

kubectl -n test apply -f test-cron.yaml

and get the following error:

error: error parsing test-cron.yaml: error converting YAML to JSON: yaml: line 20: mapping values are not allowed in this context

Does anyone know what the issue is with the formatting?

Thanks

-- nillenilsson
curl
docker
kubernetes
markdown
yaml

1 Answer

10/22/2019

thats because your curl command contains semicolon so yaml thinks you are trying to define an object. to fix the error:

  1. escape every " with backlslash: \"
  2. wrap the entire line with "

therefore-

 - curl "https://test-es01.test.svc.clu01.test.local:9200/logs_write/_rollover" -H 'Content-Type: application/json' -d '{"conditions: {"max_size": "5gb"}}'

should be escaped to

- "curl \"https://test-es01.test.svc.clu01.test.local:9200/logs_write/_rollover\" -H 'Content-Type: application/json' -d '{\"conditions: {\"max_size\": \"5gb\"}}'\n"

http://www.yamllint.com/ is a great place to track down such bugs.

-- Efrat Levitan
Source: StackOverflow