kubernetes-helm - 检查 Helm 中嵌套对象的存在
问题描述
我在 YAML 文件中有这些值:
configuration:
files:
- from: "foo.yml"
to: "bar.yml"
我想检查是否configuration
和files
存在这样的:
{{- if and .Values.configuration .Values.configuration.files -}}
volumeMounts:
{{- range .Values.configuration.files -}}
- name: "config"
mountPath: {{ .to }}
{{- end -}}
{{- end -}}
它在何时存在时工作得很好configuration
,files
但是当两者都被省略时,我在渲染 Helm 模板时收到此错误:
错误:在“chart/templates/deployment.yaml”中呈现错误:模板:chart/templates/deployment.yaml:62:48:在 <.Values.configuration.files> 处执行“chart/templates/deployment.yaml”:nil指针评估接口 {}.files
如何在不嵌套两个if
子句的情况下检查两者是否存在?
解决方案
推荐阅读
- aws-lambda - 如何修复 AWS 设备场 SDK 错误在参数中发现意外的键“类型”
- electron - 如何在 Electron 应用程序的 NSIS 安装程序中包含一个 14GB 以上的巨大文件夹?
- java - 从 Ibatis 迁移到 MyBatis
- python-3.x - 将 numpy 数据集转换为 netCDF
- python - 带有字符串和浮点值的 pandas DataFrame 到 .txt
- python - TensorFlow中如何清除tf.Tensor的形状信息?
- android - 在android studio中从网络获取图像的问题
- javascript - 给定两个变量在 Js 数组中搜索
- r - 使用 tidyeval 在自制函数中选择函数
- java - NoSuchElementException 等