你使用的是什么版本的 Helm?
GitHub 上的 Kubernetes 存储库中存在类似问题:
Unable to use condition in 'requirements.yaml' #2111
解决方案是将 Helm 升级到 v2.2.0+。在那个版本中,添加了条件支持。
Helm 2 to Helm 3 upgrade note:
Chart apiVersion 因以下规范更改而升至“v2”:
- 动态链接的图表依赖项移至Chart.yaml(requirements.yaml 已删除,需求 --> 依赖项)
- 现在可以将库图表(帮助/常用图表)添加为动态链接的图表依赖项
- 图表具有类型元数据字段,用于将图表定义为应用程序或库图表。默认情况下它是应用程序,这意味着它是可渲染和可安装的
- Helm 2 图表 (apiVersion=v1) 仍可安装
在Helm documentation 或repository 中,有一个条件如何工作的解释:
(我添加了一些 cmets 让阅读更容易)
Condition - 条件字段包含一个或多个 YAML 路径(以逗号分隔)。
标签 - 标签字段是与此图表关联的标签的 YAML 列表。
# parentchart/requirements.yaml
dependencies:
- name: subchart1
repository: http://localhost:10191
version: 0.1.0
condition: subchart1.enabled, global.subchart1.enabled
tags:
- front-end #(chart should be disabled because the tags.front-end is “false” in values.yaml file , but ...)
- subchart1 #(subchart1.enabled condition path is present in values.yaml file and it has "true" value...)
#(this condition, so it overrides tag front-end and this chart will be enabled)
- name: subchart2
repository: http://localhost:10191
version: 0.1.0
condition: subchart2.enabled,global.subchart2.enabled
#(as soon as no one from these paths is exists in values.yaml this condition has ho effect)
tags:
- back-end #(chart should be enabled because the tags.back-end is “true” in values.yaml file)
- subchart2 #(and there is no condition path found in values.yaml to override it)
如果此条件路径存在于顶级父级的values 中并解析为布尔值,则图表将根据该布尔值启用或禁用。
仅评估列表中找到的第一个有效路径,如果不存在路径,则条件无效。
在top parent的values中,所有带有tags的图表都可以通过指定tag和一个布尔值来启用或禁用。
# parentchart/values.yaml
subchart1:
enabled: true #(this could be found from requirements as subchart1.enabled and override tags in this case)
tags:
front-end: false #(this disables charts with tag front-end)
back-end: true #(this enables charts with tag back-end)
条件和标签的逻辑和顺序在Tags and Condition Resolution中描述:
-
条件(在值中设置时)总是覆盖标签。存在的第一个条件路径获胜,该图表的后续条件路径将被忽略。
- 标签被评估为“如果图表的任何标签为真,则启用图表”。
- 标签和条件值必须设置在顶级父级的值中。
- 标签:值中的键必须是顶级键。 全局和嵌套标签:目前不支持表格。
你也可以在命令行中设置标签和条件:
helm install --set tags.front-end=true --set subchart2.enabled=false