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

Expose digFromDict function #368

Open
pursultani opened this issue May 16, 2023 · 1 comment
Open

Expose digFromDict function #368

pursultani opened this issue May 16, 2023 · 1 comment

Comments

@pursultani
Copy link

dig is a very useful function. Since it uses a variadic argument to specify the keys, the caller needs to know them prior to calling it. While handy in most cases, this is a limitation for implementing more advanced templates partials and helpers where the helper receives the list of the keys as a parameter.

digFromDict (which dig already uses) has the signature that satisfies the requirements that was mentioned above and can be a complement to dig for special purposes. It just needs to be exposed.

The following example (for Helm) tries to depict this:

--- values.yaml
global:
  module1:
    settings: {}
    #  foo:
    #    bar:

module1:
  settings: {}
  #  foo:
  #    bar:
{{- define "settings.helper" -}}
{{- coalesce (digFromDict .local "" .keys) (digFromDict .global "" .keys) .default -}}
{{- end -}}

{{- define "module1.settings.fooBar" -}}
{{- include "settings.helper" (dict
        "local" .Values.module1.settings
        "global" .Values.global.module1.settings
        "default" "fooBar"
        "keys" (list "foo" "bar")
    )
-}}
{{- end -}}

A helper like "settings.helper" can not be implemented with dig.

@pursultani
Copy link
Author

I want to make an additional note that this is a generic problem with functions with variadic arguments. They can be used in a limited settings and their usage can not be parametrized with lists. #330 is a similar issue.

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