我正在尝试整理图表并将所有initContainers
迁移到名为图表_ scripts.tlp的帮助器中。
我在proxy-deployment.yaml中有一个initContainers
步骤,该步骤一直等到我的经纪人服务这样初始化:
# This init container will wait for at least one broker to be ready before proceeding
# with deploying the rest of the proxy service
- name: wait-broker-ready
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["bash", "-c"]
args:
- >-
for i in {0..10}; do
broker_pods="$(nslookup -timeout=10 {{ template "service.fullname" . }}-{{ .Values.broker.component }} | grep Name | wc -l)"
if [[ ${broker_pods} -ge 1 ]]; then
break
fi
sleep 30;
done;
我正在尝试像这样重写它:
# This init container will wait for at least one broker to be ready before proceeding
# with deploying the rest of the proxy service
- name: wait-broker-ready
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["bash", "-c"]
args:
- >-
{{ template "service.waitBrokerReady"}}
我有以下名称模板_ scripts.tlp:
{{/*
Wait until at least one broker instances is initialized
*/}}
{{ define "service.waitBrokerReady" }}
for i in {0..10}; do
broker_pods="$(nslookup -timeout=10 {{ template "service.fullname" . }}-{{ .Values.broker.component }} | grep Name | wc -l)"
if [[ ${broker_pods} -ge 1 ]]; then
break
fi
sleep 30;
done;
{{- end }}
[不幸的是,这是一个多行命令,并且存在空格分隔的事实,我看到了error converting YAML to JSON: yaml
。
我已经尝试过使用printf
进行多种变体,但是不确定如何传递嵌套模板,并且经常看到Error: parse error at (service/templates/_functions.tpl:6): "-p" in command
。
以下解决方案似乎对我有用:
__ scripts.tlp:
{{/*
Wait until at least one broker instances is initialized
*/}}
{{- define "service.waitBrokerReady" }}
- >-
for i in {0..10}; do
broker_pods="$(nslookup -timeout=10 {{ template "service.fullname" . }}-{{ .Values.broker.component }} | grep Name | wc -l)"
if [[ ${broker_pods} -ge 1 ]]; then
break
fi
sleep 30;
done;
{{- end -}}
proxy-deployment.yaml:
# This init container will wait for at least one broker to be ready before proceeding
# with deploying the rest of the proxy service
- name: wait-broker-ready
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["bash", "-c"]
args:
{{- include "pulsar.waitBrokerReady" . | squote | indent 10 | replace "'" "" }}