You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Helm模板字符串条件判断不符合预期问题排查

Helm模板字符串条件判断不符合预期的原因

你的问题出在两个关键错误上:

  1. contains函数参数顺序颠倒
    Helm模板中的contains函数语法是contains <子串> <目标字符串>,即第一个参数是要查找的内容,第二个参数是被查找的目标。你原代码里把$.Values.region(值为jp-osa)放在第一个位置,把字符串字面量"storage-plugin.regionEP"放在第二个位置,这相当于检查"storage-plugin.regionEP"这个固定字符串里是否包含jp-osa,显然不成立,所以contains返回false,经过not取反后得到true,触发了警告。

  2. 错误引用配置值
    你直接写"storage-plugin.regionEP"会被当成字面量字符串,而不是引用$.Values里的storage-plugin.regionEP配置项。Helm不会解析引号内的变量,所以实际并没有用到你配置的.au-syd.br-sao.ca-tor.eu-de.eu-fr2.eu-gb.jp-osa.jp-tok.us-east.us-south这个值。

修正后的代码示例

{{- $regionEP := $.Values["storage-plugin"].regionEP }}
{{- if not (contains $.Values.region $regionEP) }}
WARNING: {{ $.Values.region }} do not have regional COS endpoint support, it is recommended to use Cross-Regional Storageclass.
{{- end }}

这里先把storage-plugin.regionEP的配置值赋值给变量$regionEP(因为键名包含横杠,用索引语法$.Values["storage-plugin"].regionEP更稳妥),再把参数顺序调整为contains <子串> <目标字符串>,这样就能正确判断$.Values.region是否存在于storage-plugin.regionEP的配置值中。

内容的提问来源于stack exchange,提问作者ambikanair

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 08:04:53