How can I add the ability to provide arbitrary Helm values using the KOTS config?

Problem

Whether it’s for debugging, development, expert, or advanced purposes/uses, sometimes it’s desired to provide arbitrary Helm values via the KOTS config for a particular Helm chart. Maybe those Helm values have not necessarily been mapped to configuration options yet.

Solution

You can basically define a generic config item that accepts arbitrary YAML to be merged with the existing Helm values and passed down to the Helm chart.

Here’s an example:

In your KOTS config, add the following two config items:

        - name: enable_custom_helm_overrides
          title: Enable Custom Helm Overrides
          help_text: Enable Custom Helm Overrides
          type: bool 
          default: "0"
        - name: custom_helm_overrides
          title: Custom Helm Value Overrides
          type: textarea
          default: ""
          when: "repl{{ ConfigOptionEquals `enable_custom_helm_overrides` `1`}}"

Then, in the HelmChart custom resource, add the following as the last entry in the optionalValues field:

  optionalValues:
    # ... other/previous entries go here (if any) ... #
    - when: "repl{{ ConfigOptionEquals `enable_custom_helm_overrides` `1`}}"
      recursiveMerge: true
      values: repl{{if ConfigOptionEquals "custom_helm_overrides" ""}}{}repl{{ else }}repl{{ ConfigOption "custom_helm_overrides" | nindent 8 }}repl{{ end }}

Make sure to include the recursiveMerge: true from the snippet above as to not override top-level sub-fields.

With that, you have a KOTS configuration item that accepts arbitrary Helm values to be passed down to the Helm chart, and those values are recursively merged with the other values.

When using the KOTS CLI to install, those values would have to be included in the config values file that is passed to the install command, and cannot be provided separately. But, you can for example have a go/bash script that merges those Helm values from another file into the config values files before running the KOTS install command.