How to create Kubernets object using arrays

# cat test.yaml
---
apiVersion: v1
kind: ConfigMap
data:
  test:
    - "1"
    - "2"
metadata:
  name: test-config

# helm install --dry-run --debug ./helm-chart/ --generate-name
install.go:173: [debug] Original chart version: ""

Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(ConfigMap.data.test): invalid type for io.k8s.api.core.v1.ConfigMap.data: got "array", expected "string"
helm.go:88: [debug] error validating "": error validating data: ValidationError(ConfigMap.data.test): invalid type for io.k8s.api.core.v1.ConfigMap.data: got "array", expected "string"

The data field is a map from string->string - you are providing a list. What value do you want in that string?

data: "1 2 3"

or

data: "[1, 2, 3]"

or something else? You have to spell out the formatting. It’s just a string.

Thanks for response.
I like to store strings into vec

---
apiVersion: v1
kind: ConfigMap
data:
  test:
    - "string1"     
    - "string2"
    - "string3"
metadata:
  name: test-config

//Below code parses and fills vec<String> perfectly, but helm install --dry-run --debug ./helm-chart/ --generate-name fails with above error message. It means serde is able to parse yaml file correctly but kubernets is not allowing arrays to create object.

pub struct AConfig {
    test: Vec<String>,
}
pub struct ConfigData {
    pub data: AConfig,
}

    let Configdata = match serde_yaml::from_str(&yaml_file_path) {
        Ok(config) => config,
        Err(e) => {
            println!("\nfailed in serde_yaml ConfigData {:?}\n\n", e);
        }
    };

This is not a string. It’s a list.

The schema for ConfigMap says data is a map of string->string. Your local code can parse that YAML into a Vec, but it’s still structurally invalid as a ConfigMap. When you feed it to k8s tools, we validate it and tell you exactly what is wrong: got "array", expected "string".

So regardless of what structure you want to store, you HAVE TO encode it as a string, because that’s what the schema says.

Thanks

  1. I don’t find where explicitly mentioned configmap is map of string:stringConfigMaps | Kubernetes

  2. Also are configmap & values object in helm values.yaml(Helm | Values Files) are different? Because we can specify a list in values object while not in configmap.
    Below is value values.yaml which is successfully parsed by helm.

replicaCount: 1

userFW:
  path: /etc/test/test.config
srxConfig:
  a: 10
  test:
    - "test1"
    - "test2"

I’ll propose a fix to the website. The API reference for ConfigMap is here: ConfigMap | Kubernetes

ConfigMap is a totally different thing than Helm’s files.

Appreciated, Thanks