【发布时间】:2021-05-27 18:11:56
【问题描述】:
我想检查tolerations 是否在global 中可用,然后将其用于所有 pod(带有子图表的父图表),如果每个子模块/子图表都有自己的 tolerations,然后使用它而不是全局一。所以我是这样定义的:
{{/* Set tolerations from global if available and if not set it from each module */}}
{{- define "helper.tolerations" }}
{{- if .globalTolerations.tolerations }}
tolerations:
{{toYaml .globalTolerations.tolerations | indent 2}}
{{- else if (.localTolerations.tolerations) }}
tolerations:
{{toYaml .localTolerations.tolerations | indent 2}}
{{- end }}
{{- end }}
在每个子图表中,我都有这个:
spec:
template:
spec:
containers:
- name: my-container-name
{{toYaml (include "helper.tolerations" (dict "globalTolerations" .Values.global "localTolerations" (index .Values "ui-log-collector"))) | indent 6}}
values.yaml 中的默认值定义如下:
global:
tolerations: []
ui-log-collector:
image: a.b.c
tolerations: []
some-other-sub-charts:
image: x.y.z
tolerations: []
现在,当我想使用 helm 部署堆栈时,我通过 values.yaml 覆盖 tolerations,如下所示:
global:
tolerations:
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoSchedule"
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoExecute"
ui-log-collector:
tolerations:
- key: "key2"
operator: "Equal"
value: "value2"
effect: "NoSchedule"
- key: "key2"
operator: "Equal"
value: "value2"
effect: "NoExecute"
使用此设置,我目前收到此错误:
error converting YAML to JSON: yaml: line 34: could not find expected ':'
我尝试了不同的方法,但没有toYaml 我得到了:
Error: UPGRADE FAILED: error validating "": error validating data: ValidationError(Deployment.spec.template.spec.tolerations): invalid type for io.k8s.api.core.v1.PodSpec.tolerations: got "string", expected "array"
【问题讨论】:
标签: kubernetes-helm