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

Mutate default parameters with jsonnet before being processed #373

Open
ccremer opened this issue Nov 1, 2021 · 2 comments
Open

Mutate default parameters with jsonnet before being processed #373

ccremer opened this issue Nov 1, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@ccremer
Copy link
Contributor

ccremer commented Nov 1, 2021

Context

Many commodore components integrate a Helm chart and expose Helm values through a parameter called helm_values.
The component would often override certain helm values.

Sometimes though it can be necessary to provide config values based on other values.
Consider a component that primarily supports Rancher and OpenShift 4 distributions.
The values for each distro differs greatly, but there is no real way to configure the Helm chart based on another parameters.

For example, if <component>.distro=openshift then the value of <component>.helm_values.securityContext must become null, otherwise default to {fsGroup=1000, etc}. Or the other way round: The chart's default is empty and working for one distro, but for another distro we need to set 5 parameters in various places within the hierarchy, without completely replacing the "tree of values".

Proposal

Add possibility to add a jsonnet filter that can mutate the defaults defined in defaults.yml with custom logic before another step in the compilation process is executed. Think MutatingWebhook in Kubernetes.

It would be enough to just make this filter work before any Helm template is rendered if such filter can't be implemented generic enough (resp. any "position").

As a side effect (provided a generic approach works), such a filter allows easier migration of deprecated parameters. If a "conversion" filter can be placed before all the other jsonnet files, we might get rid of jsonnet code that deals with deprecated parameters in a special way. The conversion filter would simply transform the deprecated parameters into the new structure.

Alternatives

Lookup tables as described in https://syn.tools/syn/explanations/commodore-components/parameters-logic.html as not flexible enough.

  • It's very hard to completely replace a "tree of values" without maintaining the complete tree all in the table. One might not want to copy-paste all the chart's default values.
  • Complex conditionals with AND or OR become very hard to maintain via tables. Some conditional scenarios are not possible.
@ccremer ccremer added the enhancement New feature or request label Nov 1, 2021
@simu
Copy link
Member

simu commented Nov 11, 2022

Consider switching components which need this to use Kadet + kapicorp/kapitan#875 (once merged and released), that way we could write arbitrary Python to preprocess Helm values.

@simu
Copy link
Member

simu commented Nov 23, 2022

Another alternative might be to render a helm_values.yaml using a similar approach to the one we've taken to render a kustomization.yaml (see e.g. projectsyn/component-kyverno#67), and then pass that file to Kapitan's helm input type as helm_values_file (cf. https://kapitan.dev/compile/#helm)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants