Skip to content

feat: Allow .Release.Name to be used in gotmpl values templates - #1424

Merged
mumoshu merged 3 commits into
roboll:masterfrom
joshes:feaure-add-release-name-to-values-templates
Aug 29, 2020
Merged

mumoshu merged 3 commits into
roboll:masterfrom
joshes:feaure-add-release-name-to-values-templates

Conversation

@joshes

@joshes joshes commented Aug 21, 2020 •

Copy link
Copy Markdown
Contributor

This adds the ability to utilize .Release inside of gotmpl files as discussed here.

Resolves: #760

Added a simple test that passed once implemented and all tests are running green.

@joshes joshes changed the title add release name to values templates Feature: Allow .Release.Name to be used in gotmpl values templates Aug 24, 2020
@Romiko

Romiko commented Aug 27, 2020

Copy link
Copy Markdown

Hi, is this something that will be merged in soon?

@mumoshu

mumoshu commented Aug 29, 2020

Copy link
Copy Markdown
Collaborator

@Romiko Yes. I'll merge this today or tomorrow, immediately after I've finished stabilizing the latest minor version of Helmfile (v0.125.x).

@joshes Thanks for your contribution! This LGTM overall. But please let me modify this before/after merging this a bit, so that it doesn't accidentally expose other ReleaseSpec fields.

For example, this change as its current form result in exposing Release.Values to the template. It sounds useful initially, but in reality, it can contain either paths to values file OR map[string]interface{} of embedded values, which makes it hard for people to actually use. I'd like to discuss about it in a dedicated feature request(if someone submits it). Same for other ReleaseSpec fields.

@joshes

joshes commented Aug 29, 2020

Copy link
Copy Markdown
Contributor Author

@mumoshu Sounds good. That side effect did strike me as extremely useful as well initially but I hear what you're saying. :)

Thanks!

Comment thread pkg/state/types.go
// releaseTemplateData provides variables accessible while executing golang text/template expressions in releases of a helmfile YAML file
// releaseTemplateData provides variables accessible while executing golang text/template expressions in release templates
// and release values templates within a Helmfile YAML file.
type releaseTemplateData struct {

@mumoshu mumoshu Aug 29, 2020 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@joshes I realized that we already have a struct type for the template data used for rendering anything related to each release! FYI it was used for rendering things like valuesTemplate. So I refactored your change without modifying EnvironmentTemplateData.

Along the way I also realized that we already and unexpectedly exposed ReleaseSpec to the whole template in some case.

Fortunately, Helmfile had unit tests(TestHelmState_executeTemplates) that helped me to figure out which ReleaseSpec fields are intended to be exposed to the template. I extracted the fields to releseTemplateDataRelease(L34-L46).

@mumoshu mumoshu changed the title Feature: Allow .Release.Name to be used in gotmpl values templates feat: Allow .Release.Name to be used in gotmpl values templates Aug 29, 2020

@mumoshu mumoshu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@joshes Thanks a lot for implementing this! I especially appreciate the addition to the unit test, which helped me easily refactor this ☺️

@mumoshu
mumoshu merged commit 7b11ce8 into roboll:master Aug 29, 2020
mumoshu added a commit that referenced this pull request Sep 10, 2020
It was accidentally removed in #1424, and had been unexpectedly unavailable between v0.126.0 and v0.128.1.
mumoshu added a commit that referenced this pull request Sep 10, 2020
It was accidentally removed in #1424, and had been unexpectedly unavailable between v0.126.0 and v0.128.1.

Fixes #1464
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.

Unable to use .Release.Name in values.gotmpl

3 participants