kubernetes-helm

Set helm chart array value leveraging --set command with unquoted string value


helm gurus I'm seeking an appropriate helm set option than can synthesize the equivalent of the values.yaml seen below - in particular the array entry unquoted string.

$ cat values.yaml

sftp:
  ipAddresses:
    - ip: 10.0.40.83

I've tried various helm --set / --set-literal // --set-string options, but the result is that the string always gets wrapped in quotes. Does anyone know a way to prevent the quotes from being added?

--set 'sftp.ipAddresses[0]'=ip:\ 10.0.40.83

see below the quotes were added

sftp:
  ipAddresses:
    - 'ip: 10.0.40.83'

unfortunately the template that consumes this value breaks when the string is quoted - and I can't change the template

kind: Endpoints
apiVersion: v1
metadata:
  name: "sftp-server-endpoint-service"
subsets:
  - addresses:
{{- with .Values.sftp.ipAddresses }}
{{ toYaml . | indent 6 }}
{{- end }}
    ports:
      - port: 22

My workaround at the moment is to create a small values.yaml with the content and pass this via the --values option. But would prefer a mechanism using --set.

thanks


Solution

  • When you're using --set at the array element itself (sftp.ipAddresses[0]) and feeding it the whole fragment ip: 10.0.40.83, Helm treats it as one big string and its YAML serializer wraps it in quotes. You'll need to point --set at the key and quote the brackets so Helm renders a map instead of a quoted string:

    $ helm template ./mychart \
      --set 'sftp.ipAddresses[0].ip=10.0.40.83' \
      --dry-run --debug
    
    ---
    # Source: mychart/templates/sftp-endpoints.yaml
    kind: Endpoints
    apiVersion: v1
    metadata:
      name: "sftp-server-endpoint-service"
    subsets:
      - addresses:
          - ip: 10.0.40.83
        ports:
          - port: 22