<p>I want to create a kubernetes config map with multi-lines, such as this kind of yaml:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: nifi-bootstrap
data:
  run.sh: |-
    echo "Waiting to run nslookup..."
    sleep 30
</code></pre>

<p>How should I write it in a part function in my prototype?</p>

<pre><code>    parts:: {
        bootstrap(p):: {
            apiVersion: 'v1',
            kind: 'ConfigMap',
            metadata: {
                name: p.name + '-bootstrap',
                labels: {
                    app: p.app,
                    release: p.release,
                },
            },
            data: {
                'run.sh': "|-
line 1 
line 2
line 3
"
</code></pre>

<p>but it generates yaml like this: (ks show default):</p>

<pre><code>apiVersion: v1
data:
  run.sh: "|-\nline 1 \nline 2\nline 3\n"
kind: ConfigMap
</code></pre>

<p>I want to mount this config map and run it as script, but I doubt this output can work. Any idea on how to generate multi-line value in ksonnet/jsonnet?</p>

Xiang Zhang
<p>The <em>jsonnet</em> "equivalent" of <em>yaml</em>'s <code>|</code> is the <code>|||</code> construct (see <a href="https://jsonnet.org/ref/spec.html" rel="noreferrer">https://jsonnet.org/ref/spec.html</a>), applied  your example:</p>

<pre><code>$ cat foo.jsonnet
{
  parts:: {
    bootstrap(p):: {
      apiVersion: "v1",
      kind: "ConfigMap",
      metadata: {
        name: p.name + "-bootstrap",
        labels: {
          app: p.app,
          release: p.release,
        },
      },
      data: {
        "run.sh": |||
          line 1
          line 2
          line 3
        |||,
      },
    },
  },
} {
  foo: self.parts.bootstrap({name: "foo", app: "bar", release: "v1"}),
}
$ jsonnet foo.jsonnet
{
   "foo": {
      "apiVersion": "v1",
      "data": {
         "run.sh": "line 1\nline 2\nline 3\n"
      },
      "kind": "ConfigMap",
      "metadata": {
         "labels": {
            "app": "bar",
            "release": "v1"
         },
         "name": "foo-bootstrap"
      }
   }
}
$ jsonnet foo.jsonnet|jq -r '.foo.data["run.sh"]'
line 1
line 2
line 3
</code></pre>
