2

I'm trying to use Kustomize to generate ConfigMaps from files that contain key-value pairs. My kustomization file contains this:

configMapGenerator:
    - name: my-config
      files:
          - environment.properties

The environment.properties file contains this:

FIRST: 1
SECOND: 2
LAST: 3

The generated output contains this:

apiVersion: v1
data:
  environment.properties: |
    FIRST: 1
    SECOND: 2
    LAST: 3
kind: ConfigMap

How can I flatten this data structure? I'd rather have this output instead:

apiVersion: v1
data:
  FIRST: 1
  SECOND: 2
  LAST: 3
kind: ConfigMap
Steven Liekens
  • 13,266
  • 8
  • 59
  • 85

1 Answers1

4

This is not flattening. This will remove file name under which those key=value pairs are present.

If you want simple flat output as you showed, you should use literals:

configMapGenerator: 
- name: the-map 
  literals: 
    - FIRST: 1
    - SECOND: 2
    - LAST: 3

This is explained on # Kustomization.yaml Reference

files []string

List of files to generate ConfigMap data entries from. Each item should be a path to a local file, e.g. path/to/file.config, and the filename will appear as an entry in the ConfigMap data field with its contents as a value.

literals []string

List of literal ConfigMap data entries. Each item should be a key and literal value, e.g. somekey=somevalue, and the key/value will appear as an entry in the ConfigMap data field.

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
# generate a ConfigMap named my-java-server-props-<some-hash> where each file
# in the list appears as a data entry (keyed by base filename).
- name: my-java-server-props
  files:
  - application.properties
  - more.properties
# generate a ConfigMap named my-java-server-env-vars-<some-hash> where each literal
# in the list appears as a data entry (keyed by literal key).
- name: my-java-server-env-vars
  literals:    
  - JAVA_HOME=/opt/java/jdk
  - JAVA_TOOL_OPTIONS=-agentlib:hprof
# generate a ConfigMap named my-system-env-<some-hash> where each key/value pair in the
# env.txt appears as a data entry (separated by \n).
- name: my-system-env
  env: env.txt

EDIT:

As pointed by @Steven Liekens this answers the question:

env string

Single file to generate ConfigMap data entries from. Should be a path to a local env file, e.g. path/to/file.env, where each line of the file is a key=value pair. Each line will appear as an entry in the ConfigMap data field.

Community
  • 1
  • 1
Crou
  • 10,232
  • 2
  • 26
  • 31