HELM template --set a inline key's value

Viewed 49
config:
    temp.yaml: |-
      instances:
        - server: <The value that is going to be passed from helm template --set>
          port: 443

command: --set config."temp\.yaml.instances[0].server"=server_url

I have a helm template like in the above example. As it can be seen temp.yaml is inline but I need to set a value thats in the inline part. Is this somehow possible to do this using only "helm template --set" command?

2 Answers

| declare multi-line strings, You cloud not treat string like struct.

helm yaml doc

In addition, --set is used to overridden value in values.yaml. And the key of the value in values.yaml cannot contain ., so there cannot contain keys such as temp.yaml

helm --set

One possible implementation values.yaml

config:
  temp: |-
    instances:
      - server: 127.0.0.1
        port: 443

templates/configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
  temp.yaml: |-
  {{ $.Values.config.temp }}

cmd:

helm template --debug test .

output:

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
  temp.yaml: |-
  instances:
  - server: 127.0.0.1
    port: 443

cmd 2:

helm --debug template test . --set config2.temp=\
'  instances:
     - server: 1.2.3.4
       port: 443'

output 2:

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
  temp.yaml: |-
    instances:
     - server: 1.2.3.4
       port: 443

You can only helm install --set (or --set-string) an entire string value; you can't selectively replace things inside a string or tell Helm that a string value is actually YAML.

It looks like you're trying to expose an entire ConfigMap data structure as configurable settings. You might be able to restructure your application so most of the ConfigMap is generated in Helm template code, and only the things that need to be configured are exposed as Helm values. For example, if your ConfigMap looks like

# templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "mychart.name" . }}
  labels:
{{ include "mychart.labels" . | indent 4 }}
data:
  temp.yaml: |-
    instances:
{{ .Values.instances | toYaml | indent 6 }}

Now your values.yaml file contains the "instances" data as a YAML structure, not a string

# values.yaml, or some `helm install -f` file
instances:
  - server: 127.0.0.1
    port: 443

and the ... | toYaml | indent sequence will convert that structure back to YAML text and indent it appropriately for the ConfigMap output.

If you do this then you can use helm install --set in pretty much exactly the way you describe initially.

Related