Skip to content

Unable to use .Release.Name in values.gotmpl #760

Closed

Description

@albertmichaelj

I have a use case where I want the .Release.Name to be used as a variable in a values.gotmpl file. However, no matter what I do, the values.gotmpl file will not render .Release.Name. Is this expected behavior? Are there suggestions on how to work around this?

My use case is that I have multiple deployments of the same app on the same kubernetes cluster with non-namespaced objects (specifically PVs and filepaths on an NFS server) that need to be given unique names. I am using the release name as a unique identifier to add as a prefix to these non-namespaced objects. So, if you can't use .Release.Name in a gotmpl file, is there any other way to pass a unique value to the gotmpl file and still run a single helmfile -f ... sync command?

Activity

  1. mumoshu commented on Jul 17, 2019

    @mumoshu
    Collaborator

    @albertmichaelj Hey!

    Release.Name is available only while rendering helmfile.yaml, not values file templates.

    As a work-around, can you extract the part of your values.gotmpl into helmfile.yaml like:

    releases:
    - name: yourapp
       chart: yourchart
       values:
       - pathOnNfs: /path/to{{.Release.Name}}

    If not, I think this is a valid feature request, as I see no downside of improving helmfile to allow .Release.Name within values.gotmpl.

  2. albertmichaelj commented on Jul 17, 2019

    @albertmichaelj
    Author

    @mumoshu Thanks for the response, and it's really helpful to know that I wasn't just doing something stupid. If it's not a major change, I think being able to specify some kind of unique value that can be propagated to the values.gotmpl file would be very, very helpful for my use case. The problem is that I (for various reasons) need to specify pathOnNfs multiple places in the values.yaml file, and while I could conceivably set the values a bunch of times in the helmfile, that would clutter things up quickly.

    This doesn't necessarily need to be the Release.Name. It could be something in the release like

    releases:
    - name: yourapp
        chart: yourchart
        environment:
          - customValue: "whatever"
        values:
          - values.gotmpl

    and then in values.gotmpl you could have something like:

    foo: {{ .Environment.Custom.Values.customValue }}

    This would be more flexible in that you could always set customValue to Release.Name using double rendering in the helmfile. The big need for me, is that I need someway to specify per release values that need to be repeated several times in the values.gotmpl for a variety of reasons (generally because I'm using an existing chart and I am trying to avoid forking the chart).

    There isn't any functionality currently like this in helmfile, right?

    I know that I can call helmfile with something like CUSTOM="whatever" helmfile -f helmfile.yaml sync and then I can use the CUSTOM environmental variable, but it keeps me from using a single helmfile call to update all of my releases (and I can't easily version control that command).

    Is this use case within scope for helmfile? If not, please don't make changes that aren't within the spirit of the tool.

    Thanks!

  3. mumoshu commented on Jul 23, 2019

    @mumoshu
    Collaborator

    @albertmichaelj Hey!

    A short-term solution to your problem would be to leverage sub-helmfile, like @janekbaraniewski has shared in #387 (comment).

    In longer-term, the combination of double-rendering and per-release overrides as you've suggested seems like the best way forward!

    Fortunately, we have a similar request that can accommodate your use-case as well. See the discussion starting from #745 (comment) - I think we can extend it so that you can rewrite your example as:

    releases:
    - name: yourapp
      chart: yourchart
      set:
      - valuesFrom:
          templateFile:
            path: values.gotmpl
            valuesFrom:
            # Instead of implicitly passing helmfile's values to the values.gotmpl
            # explicitly set this so that it inherits all the helmfile values into the template rendering context of `values.gotmpl`
            - valuesInherited: true
            # Overrides
            - inline:
                customValue: "whatever"

    The syntax seems a bit verbose but the benefits are countless - I believe it does support your use-case, and also (1)it's completely backward-compatible, (2)has extensibility to support other value sources like AWS SSM, Vault, etc.

    WDYT?

  4. albertmichaelj commented on Jul 23, 2019

    @albertmichaelj
    Author

    Thanks for your response! I think I understand the new syntax, but I'm not sure exactly how you would access the customValue. Would it be like:

    foo: {{ .Environment.Values.customValue }}

    with the idea being that the

    -inline:
        customValue: "whatever"

    overrides anything in the existing environment? If that is the case, then that would absolutely fit my use case.

    Do you have a timeline for implementing this feature? No worries if not, I'm just curious. Thanks again!

  5. sshishov commented on Mar 6, 2020

    @sshishov

    I am also waiting for the same solution! Need to propagate some variables to values file

  6. jim-barber-he commented on Apr 6, 2020

    @jim-barber-he

    I too would like the ability to query .Release.Name from within the values files.

    In my case I have some large configuration files for various components that make up the application; that are all stored in the values files to produce Kubernetes Secrets from that will be mounted as files in the containers.
    These configuration files are supplied to multiple releases, and the content of which are mostly the same with a few values that need to differ across the releases.
    Being able to test for .Release.Name from within the values files would let me do some conditional logic there to tailor the configs easily.

  7. skashmeri commented on Apr 25, 2020

    @skashmeri

    @mumoshu is there any chance of seeing this feature getting added to helmfile?

  8. mumoshu commented on Apr 25, 2020

    @mumoshu
    Collaborator

    Could anyone submit a pull request for this?

    I think this should be a matter of adding a Release field to the template data(that is used as a collection of template params while rendering a values.yaml template here

    r := tmpl.NewFileRenderer(st.readFile, filepath.Dir(path), st.valuesFileTemplateData())

  9. joshes commented on Aug 21, 2020

    @joshes
    Contributor

    I'd really like this to be available as well. I have taken a look at the code and doesn't seem that trivial as we have potentially numerous releases, but the EnvironmentSpec is more or less a global take on things.

    My use-case is trying to use the .Release.Name in conjunction with namespacing ssm values:

    releases:
      - name: my-app-db
        chart: stable/mysql
        values:
          - mysqlUser: my-app
          - mysqlPassword: password: ref+awsssm://{{ .Release.Name }}/mysql/password
    

    I'll continue to see how this can be added, any additional pointers welcome.

    Edit:
    I just realized that the .Release.Name would indeed render in this location with the double-quote trick:

    {{`{{.Release.Name}}`}}
    

    And that my issue with ssm is order of operations. Seems the template isn't rendered by the time its passed to the vals service.

  10. joshes commented on Aug 24, 2020

    @joshes
    Contributor

    I should mention that in the PR above, it also addresses the resolution of the ref+awsssm:// value interpolation (e.g., the Values plugin) as well. Using the double-quote trick it still didn't work originally.

  11. abdennour commented on Mar 3, 2021

    @abdennour
    Contributor

    For me, sometimes Relase.Name is interpolated, and sometimes, it does not... while using the same helm chart
    Seems like we need to test more this feature.

    For example, with jenkins helm chart, controller.ingress.hostName={{ .Release.Name }}.example.com never interpolated even using the other syntax :

    controller.ingress.hostName="{{`{{ .Release.Name }}`}}.example.com"
    

    Does not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions