Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render of multiline string breaks pretty yaml printing in certain cases #5344

Open
1 task done
distorhead opened this issue Mar 2, 2023 · 1 comment
Open
1 task done

Comments

@distorhead
Copy link
Member

Before proceeding

  • I didn't find a similar issue

Version

1.2.204

How to reproduce

Define a manifest with string-value as multiline yaml which contains empty string with number of spaces more than identation level:

---$
apiVersion: v1$
kind: ConfigMap$
metadata:$
  name: cm$
data:$
  stringkey: |$
    hello: world$
     $
    test: value$

Note that after hello: world there is 5 spaces, while identation of string value yaml is 4 spaces.

Result

Run werf render (or werf helm template .helm):

# Source: test/templates/cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: cm
  annotations:
    project.werf.io/env: ""
    project.werf.io/name: x
    werf.io/version: dev
data:
  stringkey: "hello: world\n \ntest: value\n"

stringkey value is no more multiline string.

Expected result

Running vanilla helm template .helm does not break multiline representation of stringkey:

---
# Source: test/templates/cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: cm
data:
  stringkey: |
    hello: world
     
    test: value

Additional information

No response

@distorhead
Copy link
Member Author

More cases.

Works OK:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: renew-role-mapping
data:
  aa: |
    xx: hello
{{ include "odsp_extend_role_mapping" . | indent 4 }}

Fails:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: renew-role-mapping
data:
  aa: |
    xx: hello
    key:
{{ include "odsp_extend_role_mapping" . | indent 6 }}

Workaround is to add trim either in include statement or in the template definition itself:

{{ include "odsp_extend_role_mapping" . | trim | indent 6 }}

Or:

{{- define "odsp_extend_role_mapping" -}} # << right trim here
...
{{- end }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant