Output multi-line text?

182 views
Skip to first unread message

Steven Canfield

unread,
May 23, 2022, 2:06:28 PM5/23/22
to Jsonnet
Hello,

I'm trying to replicate a setup I have with a k8s configmap that looks like:

apiVersion: v1
kind: ConfigMap
data:
  top_level_key: |
    a: 1
    b: 2

The point of this is that "top_level_key" contains a YAML doc itself.

When I generate this structure with jsonnet, I end up with 

data:
  top_level_key: "a: 1\nb: 2"

which is of course the same thing, but makes reading the thing as a human much harder. 

I can work around this with a shell script to generate the contents of top_level_key with one invocation of jsonnet and then import it using includestr, but it would be nice not to need the driver script.

Is there a way to "output multiline text" without 2 invocations of jsonnet?

Steven Canfield

unread,
May 24, 2022, 12:18:01 AM5/24/22
to Jsonnet
One workaround I've found is just to accept jsonnet's output and pipe the whole thing through yq -P which isn't awful.

Dave Cunningham

unread,
May 24, 2022, 1:08:48 PM5/24/22
to Steven Canfield, Jsonnet
It sounds like you're asking for std.manifestYamlDoc to support outputting multiline strings for strings that have newlines in them?



--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/bf152e30-cde3-4175-be6f-23336b647033n%40googlegroups.com.

Steven Canfield

unread,
May 24, 2022, 2:23:01 PM5/24/22
to Dave Cunningham, Jsonnet
Yep exactly. 
Reply all
Reply to author
Forward
0 new messages