我正在研究一个问题,以实现一个自定义configMap的舵机图表,并试图根据环境模式填充configMap。
Values.yaml
externalIPService:
ip: 1.1.1.1
port: 80
emsConfig: "receivers:
otlp:
protocols:
http:
processors:
batch:
exporters:
otlp/ems:
endpoint: {{ .Values.externalIPService.ip }}:{{ .Values.externalIPService.port }}
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp/ems]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [otlp/ems]
logs:
receivers: [otlp]
processors: [batch]
exporters: [otlp/ems]
"
configMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: simple-demo
data:
message: "{{ tpl .Values.emsConfig .}}"
helm模板输出是一个普通字符串,而不是一个yaml内容。我也试过toYaml,但也没有帮助。有人可以帮助找到一种方法来做嵌套渲染,并能够在confiMap
中使用最终输出apiVersion: v1
kind: ConfigMap
metadata:
name: simple-demo
data:
message: "receivers: otlp: protocols: http: processors: batch: exporters: otlp/ems: endpoint: {{ .Values.externalIPService.ip }}:{{ .Values.externalIPService.port }} service: pipelines: traces: receivers: [otlp] processors: [batch] exporters: [otlp/ems] metrics: receivers: [otlp] processors: [batch] exporters: [otlp/ems] logs: receivers: [otlp] processors: [batch] exporters: [otlp/ems] "
在这种情况下,需要使用_halpers.tpl
文件。
首先,将其添加到_halpers.tpl
文件中:
{{- define "appname.emsConfig" -}}
receivers:
otlp:
protocols:
http:
processors:
batch:
exporters:
otlp/ems:
endpoint: {{ .Values.externalIPService.ip }}:{{ .Values.externalIPService.port }}
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp/ems]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [otlp/ems]
logs:
receivers: [otlp]
processors: [batch]
exporters: [otlp/ems]
{{- end }}
values.yaml
文件看起来像这样:
externalIPService:
ip: 1.1.1.1
port: 80
和configMap.yaml
文件,将需要看起来像这样:
apiVersion: v1
kind: ConfigMap
metadata:
name: simple-demo
data:
message: |-
{{ include "appname.emsConfig" . | nindent 4}}