<p>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.</p>

<p>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.</p>

<pre><code>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
</code></pre>

<p>I then try to run the file:</p>

<p><code>kubectl -n test apply -f test-cron.yaml</code></p>

<p>and get the following error:</p>

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

<p>Does anyone know what the issue is with the formatting?</p>

<p>Thanks</p>

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

<ol>
<li>escape every <code>"</code> with backlslash:  <code>\"</code></li>
<li>wrap the entire line with <code>"</code></li>
</ol>

<p>therefore-</p>

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

<p>should be escaped to</p>

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

<p><a href="http://www.yamllint.com/" rel="nofollow noreferrer">http://www.yamllint.com/</a> is a great place to track down such bugs.</p>
