0
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-configmap
data:
  {{- range $key, $value := .Values.envVars }}
  {{ $key }}: {{ $value | quote }}
  {{- end }}

Running
helm upgrade my-app --install --set envVars.CREDS='{"key":"val"}'
with the above configmap results in a configmap as follows:

CREDS = ["key":"val"]

So instead of a JSON, it's an array.

What do I need to configure to pass it as a JSON?

itaied
  • 6,827
  • 13
  • 51
  • 86
  • I think [`helm --set`](https://docs.helm.sh/docs/intro/using_helm/#the-format-and-limitations-of---set) can't set keys to an object value, and the escaping is kind of tricky. I'd suggest writing a separate YAML file and passing it with `helm install -f`. – David Maze May 10 '21 at 15:13

1 Answers1

0

That looks fine, based on this answer regarding json objects representation in yamls: https://stackoverflow.com/a/33989696/11874278

If you want to achieve another thing - this key as json string you could do:

apiVersion: v1
kind: ConfigMap
metadata:
  name: app-configmap
data:
  {{- range $key, $value := .Values.envVars }}
  {{ $key }}: >
    {{ $value }}
  {{- end }}
TomerCBR
  • 1
  • 1