ytt icon indicating copy to clipboard operation
ytt copied to clipboard

ytt formatting converts multi line strings to single line strings due to trailing spaces

Open fritzduchardt opened this issue 1 year ago • 6 comments

What steps did you take: I am running ytt on a config map with a multi line string and a trailing space after the colon in line 7, e.g.:

  1 apiVersion: v1
  2 kind: ConfigMap
  3 metadata:
  4   name: my-config.map
  5 data:
  6   config: |
  7     metricsConfig: 
  8       enabled: true
  9       path: /metrics
 10       port: 9090
 11       ignoreErrors: false
 12       secure: false

What happened: Ytt unexpectedly converts the multi-line string to a single-line string:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config.map
data:
  config: "metricsConfig: \n  enabled: true\n  path: /metrics\n  port: 9090\n  ignoreErrors: false\n  secure: false\n"

What did you expect: The multi-line string should be kept. The trailing white space could be removed.

Environment:

  • ytt version (use ytt --version): 0.44.0
  • OS (e.g. from /etc/os-release): Ubuntu 20.04.4 LTS

Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible" 👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.

fritzduchardt avatar Jun 05 '23 11:06 fritzduchardt

I don't have any errant trailing spaces in my multi-line strings but recently also saw that ytt is now collapsing everything into a very long single line string, so it would be great to get this behaviour reverted or configurable.

dteoh avatar Jun 07 '23 04:06 dteoh

I'm able to successfully reproduce this issue. We will run our thoughts on this internally and set the priority accordingly.

Meanwhile, if you are willing to contribute, we will be happy to review it on a priority basis.

sethiyash avatar Jun 07 '23 15:06 sethiyash

Also, could you please let us know if this is a blocking issue for your use case or you found any workaround?

vmunishwar avatar Jun 07 '23 17:06 vmunishwar

My current workaround is to run sed -r " s#:\s+$#:#g" on my yamls before handing them to ytt.

fritzduchardt avatar Jun 15 '23 07:06 fritzduchardt

@sethiyash Please have a look at my PR to fix the issue

fritzduchardt avatar Jun 26 '23 13:06 fritzduchardt

@fritzduchardt Thank you for reaching out with this issue and we appreciate the work you have done to fix it. However, this seems to be an issue present in yaml.v2 library which is used in ytt and also we verified that this issue is present in yaml.v3 library. It would be nice if we can raise this PR in API v2 of the yaml package for Go. Please let us know your thoughts on this. Thank you.

vmunishwar avatar Jul 12 '23 16:07 vmunishwar