Skip to content

Add fromYAML/toYAML functions #193

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dhaiducek
Copy link
Contributor

@dhaiducek dhaiducek commented Apr 11, 2025

fromYAML was straightforward, but toYAML brought complexities:

  • I added toYAML to the autoindent processing because it will result in a multiline string.
  • goyaml.v3 does odd things with multiline YAML (there's a comment in the code about it and two tests demonstrating the odd known issue)

That said, I might be okay if toYAML were just not available (since toJSON likely works more reliably) or if toYAML just pointed to toJSON, though there are cases where users might want to be able to generate YAML (like in object-templates-raw or in a ConfigMap).

I also noticed some of our RegExs were missing the Go template whitespace chomping character -}}, which affected one of the tests I wrote.

ref: https://issues.redhat.com/browse/ACM-19746

Copy link

openshift-ci bot commented Apr 11, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dhaiducek

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Comment on lines 832 to 833
newMatchStr = strings.Replace(newMatchStr, "toYaml", fmt.Sprintf("toYaml | indent %d", numSpaces), 1)
newMatchStr = strings.Replace(newMatchStr, "toYAML", fmt.Sprintf("toYAML | indent %d", numSpaces), 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/hold I realized this replacement doesn't account for the toYAML argument--I'll have to adjust it to a RegEx replacement.

Copy link
Contributor Author

@dhaiducek dhaiducek Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is resolved as a known issue and this block has been removed. Helm also notes that indentation processing can't be handled by the template processor and must be specified by the user. I'll create an issue to add hints/suggestions to error messages in this case.

// The output will not be indented, so you will want to pipe this to the
// 'indent' template function.

https://github.com/helm/helm/blob/5f1bb7fee8de4d03f0651e317f9a513d02202d8d/pkg/engine/files.go#L99-L100

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New issue opened for error message hints: https://issues.redhat.com/browse/ACM-20011

@dhaiducek dhaiducek force-pushed the 19746-fromYAML branch 2 times, most recently from 3389297 to 11c3b61 Compare April 14, 2025 17:25
@dhaiducek
Copy link
Contributor Author

/unhold

ref: https://issues.redhat.com/browse/ACM-19746
Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
I found having results on a separate line made it
easier to parse.

Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
Some of our RegEx expressions didn't account for
the `-}}` syntax

Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant