简体   繁体   English

Helm 无法从命令行将双引号传递给 values.yaml?

[英]Helm fails to pass double quotes into values.yaml from the command line?

I have a Helm chart with values.yaml containing:我有一个带有values.yaml的 Helm 图表,其中包含:

# Elided
tolerations: []

I'm trying to pass the tolerations via the command line but it always removes the quotes (or adds double quotes inside single quotes) despite all the below attempts.我试图通过命令行传递容忍度,但它总是删除引号(或在单引号内添加双引号),尽管进行了以下所有尝试。 As a result it fails on install saying it expected a string.结果它在安装时失败,说它需要一个字符串。

# Attempt 0
helm install traefik traefik/traefik --set tolerations[0].key=CriticalAddonsOnly --set tolerations[0].value="true" --set tolerations[0].operator=Equal --set tolerations[0].effect=NoExecute

# Attempt 1
helm install traefik traefik/traefik --set tolerations[0].key=CriticalAddonsOnly --set "tolerations[0].value="true"" --set tolerations[0].operator=Equal --set tolerations[0].effect=NoExecute

# Attempt 2
helm install traefik traefik/traefik --set tolerations[0].key=CriticalAddonsOnly --set "tolerations[0].value=\"true\"" --set tolerations[0].operator=Equal --set tolerations[0].effect=NoExecute

# Attempt 3
helm install traefik traefik/traefik --set tolerations[0].key=CriticalAddonsOnly --set tolerations[0].value="\"true\"" --set tolerations[0].operator=Equal --set tolerations[0].effect=NoExecute

# Attempt 4
helm install traefik traefik/traefik --set tolerations[0].key=CriticalAddonsOnly --set tolerations[0].value='"true"' --set tolerations[0].operator=Equal --set tolerations[0].effect=NoExecute

They all end up creating a yaml with value: true or value: '"true"' , neither of which will install.他们最终都创建了一个 yaml ,其value: truevalue: '"true"'都不会安装。

There appears to be two answers: the exceptionally verbose one that you're trying has a solution, or the more succinct one which doesn't prompt stack overflow questions for future readers to understand:似乎有两个答案:您正在尝试的异常冗长的答案有一个解决方案,或者更简洁的一个不会提示堆栈溢出问题以供未来读者理解:

Helm offers --set-string which is the interpolation-free version of --set Helm 提供--set-string ,它是--set的无插值版本

helm install traefik traefik/traefik \
    --set tolerations[0].key=CriticalAddonsOnly \
    --set-string tolerations[0].value=true \
    --set tolerations[0].operator=Equal \
    --set tolerations[0].effect=NoExecute

However, as you experienced, that --set syntax is designed for the simplest cases only, for more complex cases --values is the correct mechanism.但是,正如您所经历的那样, --set语法仅适用于最简单的情况,对于更复杂的情况--values是正确的机制。 You can read them from stdin if created a temporary yaml file is too much work如果创建临时 yaml 文件工作量太大,您可以从标准输入读取它们

printf 'tolerations: [{key: CriticalAddonsOnly, value: "true", operator: Equal, effect: NoExecute}]\n' | \
  helm install traefik traefik/traefik --values /dev/stdin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM