Reputation: 49
I am trying to leverage a multiline variable injected into a multiline key in a helm chart configmap, but the formatting is all wonky.
For instance, the variable I'm trying to set looks like this:
plugin: |
Foo "example" {
plugin_data {
foo = "bar"
foz = "baz"
}
}
And the existing configmap I'm trying to pass this to looks like this:
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "chart.fullname" . }}
labels:
{{ include "chart.labels" . | indent 4 }}
data:
server.conf: |
server {
bind_address = "{{ .Values.config.bindAddress }}"
bind_port = "{{ .Values.config.bindPort }}"
log_level = "{{ .Values.config.logLevel }}"
plugins {
DataStore "sql" {
plugin_data {
database_type = "sqlite3"
}
}
{{- if .Values.config.plugin -}}
{{- toYaml .Values.config.plugin | nindent 4 -}}
{{- end -}}
}
The templated configmap comes out looking like this, which is obviously not valid YAML. Note the |
before the templated plugin var:
apiVersion: v1
kind: ConfigMap
metadata:
name: example
labels:
data:
server.conf: |
server {
bind_address = "0.0.0.0"
bind_port = "8081"
log_level = "DEBUG"
plugins {
DataStore "sql" {
plugin_data {
database_type = "sqlite3"
}
}
|
Foo "example" {
plugin_data {
foo = "bar"
foz = "baz"
}
}
But what I'm looking for is this, without the additional |
apiVersion: v1
kind: ConfigMap
metadata:
name: example
labels:
data:
server.conf: |
server {
bind_address = "0.0.0.0"
bind_port = "8081"
log_level = "DEBUG"
plugins {
DataStore "sql" {
plugin_data {
database_type = "sqlite3"
}
}
Foo "example" {
plugin_data {
foo = "bar"
foz = "baz"
}
Is this possible? These are not my helm charts, I am merely trying to add functionality to an open-source repo, so changing up the server.config isn't possible.
Upvotes: 0
Views: 5309
Reputation: 2517
ToYaml
is redundant
values.yaml
config:
bindAddress: 127.0.0.1
bindPort: 8080
logLevel: info
plugin: |
Foo "example" {
plugin_data {
foo = "bar"
foz = "baz"
}
}
cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: test
data:
server.conf: |
server {
bind_address = "{{ .Values.config.bindAddress }}"
bind_port = "{{ .Values.config.bindPort }}"
log_level = "{{ .Values.config.logLevel }}"
plugins {
DataStore "sql" {
plugin_data {
database_type = "sqlite3"
}
}
{{- if .Values.config.plugin }}
{{- .Values.config.plugin | nindent 6 }}
{{- end }}
}
output
apiVersion: v1
kind: ConfigMap
metadata:
name: test
data:
server.conf: |
server {
bind_address = "127.0.0.1"
bind_port = "8080"
log_level = "info"
plugins {
DataStore "sql" {
plugin_data {
database_type = "sqlite3"
}
}
Foo "example" {
plugin_data {
foo = "bar"
foz = "baz"
}
}
}
Upvotes: 1