I want to have the specific configMap structure
apiVersion: v1
kind: ConfigMap
metadata:
name: config-map-router1
labels:
name: nc1
data:
object.properties: |
address: "1"
port: ""
How to represent the indentation with
object.properties:
We have to develop little more this part of code
Map<String, String> data = new HashMap<>();
data.put("address","");
//...
V1ConfigMap configMap= new V1ConfigMap();
configMap.apiVersion("v1");
configMap.kind("ConfigMap");
configMap.metadata(meta);
configMap.data(data);
I assume you are using the Java client.
The object.properties indentation appears when you create a configmap from a file. Example: kubectl create configmap myapp-config --from-file=object.properties
.
From what I have researched the Java client seems to only support <string, string>
as values for data. As your file object.properties only has UTF-8 characters, you can try:data.put("object.properties","address: \"1\"\nport: \"\"")
or creating a file like the following and opening in Java as a String:
address: "1"
port: ""
you can also open the file and add to the configmap as a binary, using binaryData instead of data