Issue
I have a technical specific issue about Helm Chart. I want to my ConfigMap template import yaml files in my files directory, these yaml files are Java SpringBoot configuration files from my applications, I'm able to import files but they are unformatted.
Java SpringBoot yaml config file example
spring:
jpa:
hibernate:
ddl-auto: none
naming:
implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
#database-platform: org.hibernate.dialect.PostgreSQL95Dialect
datasource:
#### MYSQL ####
url: jdbc:mysql://mysql:3306/database
username: user
password: useabetteruserpassword
driver-class-name: com.mysql.cj.jdbc.Driver
ConfigMap Template
{{- if .Values.configMap.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: configmap-local
data:
{{ (.Files.Glob "files/*").AsConfig | indent 2 }}
{{- end }}
Helm --dry-run output
apiVersion: v1
kind: ConfigMap
metadata:
name: configmap-local
data:
test.yaml: "spring:\r\n jpa:\r\n hibernate:\r\n ddl-auto: none\r\n
\ naming:\r\n implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl\r\n
\ database-platform: org.hibernate.dialect.MySQL5InnoDBDialect\r\n #database-platform:
org.hibernate.dialect.PostgreSQL95Dialect\r\n datasource:\r\n #### MYSQL ####\r\n
\ url: jdbc:mysql://mysql:3306/database\r\n username: user\r\n password:
useabetteruserpassword\r\n driver-class-name: com.mysql.cj.jdbc.Driver\r\n\r\n
\ #### POSTGRES ####\r\n #url: jdbc:postgresql://postgres:5432/ver_infocenter\r\n
\ #username: ver_user\r\n #password: useabetteruserpassword\r\n #driver-class-name:
org.postgresql.Driver\r\n"
Thanks @zer0. I appreciate your answer. I'm using another solution, it's solving my need.
{{- if .Values.configMap.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: configmap-local
data:
info-center-docker.yaml: |-
{{- .Files.Get "files/info-center-docker.yaml" | nindent 4 -}}
info-center-writer-docker.yaml: |-
{{- .Files.Get "files/info-center-writer-docker.yaml" | nindent 4 -}}
topic-configuration-3p.yaml: |-
{{- .Files.Get "files/topic-configuration-3p.yaml" | nindent 4 -}}
{{- end }}
Solution
This is not a problem at all. This is just the way in which Kubernetes handles a given stream of binary data. You will notice that all the \n
and \t
characters have been preserved in the data blob attached to the key test.yaml
in your config map.
I say this is not a problem because when this ConfigMap
will be made available to a pod, the pod will be able to read this value as if from a file, and these literal characters will be translated into whitespace, and the pod will never know that they were stored like this.
Just to check, you can create a pod, and mount this ConfigMap
in it. And then get into the pod and cat
this file, you'll see the output is formatted. So, you can be rest assured your config file to the application will be received in the correct form.
Answered By - zer0
Answer Checked By - Timothy Miller (JavaFixing Admin)