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

Kevin/eng 2022 investigate tpl values templates #33

Merged
merged 7 commits into from
May 16, 2024

Conversation

vekjja
Copy link
Contributor

@vekjja vekjja commented May 14, 2024

Update RenderTpl to map the include function.
This adds all values in the included .tpl file
The function was updated to accept the file path as a parameter as opposed to the byte data

vekjja added 3 commits May 14, 2024 12:34

Verified

This commit was signed with the committer’s verified signature.
UlisesGascon Ulises Gascón

Verified

This commit was signed with the committer’s verified signature.
targos Michaël Zasso
get the template dir from the file path
ISSUES: all templates in the file path are included in the rendered template,
        need to update to only include the explicietly mentioned file
Copy link

linear bot commented May 14, 2024

vekjja added 3 commits May 14, 2024 16:15
template/tpl.go Outdated
includePath := filepath.Join(baseDir, name)

// Read and parse the included template
includeContent, err := os.ReadFile(includePath)
Copy link
Member

Choose a reason for hiding this comment

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

is this a mirror of the implementation of include in helm? I feel like it might work differently

Copy link
Member

Choose a reason for hiding this comment

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

My general guess is it should really just use https://cs.opensource.google/go/go/+/refs/tags/go1.22.3:src/text/template/template.go;l=188 and then call execute on that (the expectation would be the template is defined in the file itself and so would have been parsed by the text/template library and lookup-able)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, but I'm not sure that's the Helm definition of include

Go provides a way of including one template in another using a built-in template directive. However, the built-in function cannot be used in Go template pipelines.

To make it possible to include a template, and then perform an operation on that template's output, Helm has a special include function: {{ include "toYaml" $value | indent 2 }}

The above includes a template called toYaml, passes it $value, and then passes the output of that template to the indent function.

Because YAML ascribes significance to indentation levels and whitespace, this is one great way to include snippets of code, but handle indentation in a relevant context.

Copy link
Member

Choose a reason for hiding this comment

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

It actually is, the confusion is because I believe helm needs to make a redefinition of that function to handle the fact they can be defined anywhere in the chart, not in-file. If you look at the implementation and how it's used, it references a named define block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, after further discussion with and these PR comments from @michaeljguarino, this Polly PR needs an update to not include the referenced template file but a template mentioned from a define directive within the current .tpl file being rendered.
Changes are coming henceforth.

…opposed to including the template file
@vekjja vekjja merged commit a934832 into main May 16, 2024
5 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants