0

I am trying to create ConfigMap in OpenShift by using YAML file.

My YAML is having a list of values as below.

kind: ConfigMap
apiVersion: v1
metadata:
  name: sample-map-json-fields
  namespace: default
data:
  fields:
    - hello
    - world
    - my.test.field

I executed like below -

 oc create -f filename.yaml

Getting exception like below -

Error from server (BadRequest): error when creating "filename.yaml": ConfigMap in version "v1" cannot be handled as a ConfigMap: [pos 42]: json: expect char '"' but got char '['

If I do the same without list content inside data, it works.

Please help how to handle the YAML list for ConfigMap.

Jet
  • 3,018
  • 4
  • 33
  • 48

1 Answers1

1

This is not working because you are providing array whereas Kubernetes expects to receive string .

got "array", expected "string"

Please read more about configMap in Kubernetes API documentation:

data  - _object_   

Data contains the configuration data. Each key must
consist of alphanumeric characters, '-', '_' or '.'. Values with
non-UTF-8 byte sequences must use the BinaryData field. The keys
stored in Data must not overlap with the keys in the BinaryData field,
this is enforced during validation process.

Or in the go docs:

// Data contains the configuration data.
// Each key must consist of alphanumeric characters, '-', '_' or '.'.
// Values with non-UTF-8 byte sequences must use the BinaryData field.
// The keys stored in Data must not overlap with the keys in
// the BinaryData field, this is enforced during validation process.
// +optional


Data map[string]string `json:"data,omitempty" protobuf:"bytes,2,rep,name=data"`
acid_fuji
  • 6,287
  • 7
  • 22
  • So its not possible to use list ? – Jet Sep 18 '20 at 10:16
  • 2
    It it not possible, you have to use [multiline string](https://stackoverflow.com/questions/3790454/how-do-i-break-a-string-over-multiple-lines/21699210#21699210) – acid_fuji Sep 18 '20 at 10:24