kubernetesenvironment-variablesconfigmapkustomize

configMapGenerator doesn't create integer value


Here it is my kustomization.yaml

kind: Kustomization
configMapGenerator:
- name: app-cm
  literals:
  - foo=bar
  - var1=1

after kustomize build . I see var1 value in double quotes:

apiVersion: v1
data:
  foo: bar
  var1: "1"
kind: ConfigMap
metadata:
  name: app-cm-ghtd2cb8m9

How should I compose kustomization.yaml the file to get the value of the variable without the quotes?

I expect var1 value without quotation as:

apiVersion: v1
data:
  foo: bar
  var1: 1
kind: ConfigMap
metadata:
  name: app-cm-ghtd2cb8m9

Solution

  • What you expect can not be done. Kustomize did it right. The schema for a ConfigMap, in kubernetes, expects data do be a dict, whose values should be strings.

    If we were to omit those quotes, while this yaml would still be "valid": when converted into json and posted to Kubernetes API, your value would be sent as an integer. This would violate ConfigMaps schema. Adding those quotes makes sure proper type would be used.

    Maybe you can cast this value as integer in your application, or whatever you're trying to use this with.