helm –set .Values.someProp=false isnt overriding the default true value given in values.yaml

huangapple go评论67阅读模式
英文:

helm --set .Values.someProp=false isnt overriding the default true value given in values.yaml

问题

我有一个Helm Chart,它被用作一个微服务Chart的子Chart或基础Chart,我们称之为common。

当微服务Chart使用common时,它的样子是这样的(每个微服务可以使用x个由其Chart创建的x个部署来部署pod):

apiVersion: v2
name: charts-integration-test
description: testing the common chart integration
dependencies:
  - alias: app-01
    name: common
    repository: file://../../
    version: ~2
  - alias: app-02
    name: common
    repository: file://../../
    version: ~2
  - alias: app-02-internal
    name: common
    repository: file://../../
    version: ~2
  - alias: app-02-internal-bluegreen
    name: common
    repository: file://../../
    version: ~2    

而这个微服务的values.yaml文件如下所示:


global:
  application:
    imageName: foo
    imageTag: bar
    envVariables: {}
    rookout:
      enabled: false
    config:
      logLevel: INFO
      foodb:
        fooDbName: fooDbName
        fooDbHost: fooDbHost

applications:
  - app-01
  - app-02 

app-01:
  config:
    foodb:
      fooDbName: fooDbName2
      fooDbHost: fooDbHost2

在这个common Chart的values.yaml文件中,我有以下值:

commonDefaults:
  rookout:
    enabled: true

在这个Chart的deployment.yaml中,我使用以下代码合并了2个values.yaml的值:

{{- $values := merge (.Values | deepCopy) (.Values.global.application | deepCopy) (.Values.commonDefaults | deepCopy) -}}

重点是,在这个例子中,.Values.commonDefaults被.Values.global.application覆盖,而两者都被.Values覆盖,而.Values在这种情况下是在app-01下的MS values.yaml中设置的值。

问题是,global.application.rookout.enabled=false没有覆盖commonDefaults.rookout.enabled=true。尽管如果我将global.application.rookout.enabled=foobar,它会按预期覆盖。

我使用的helm版本是3.8.2,尽管在3.12.2中也不起作用。

感谢使用Helm。

英文:

I have a helm chart that is used as a subchart\base chart for a microservice chart we call it common.

the microservice chart looks like this when it uses common(each MS can deploy x pods using x deployments created by it's chart):

apiVersion: v2
name: charts-integration-test
description: testing the common chart integration
dependencies:
  - alias: app-01
    name: common
    repository: file://../../
    version: ~2
  - alias: app-02
    name: common
    repository: file://../../
    version: ~2
  - alias: app-02-internal
    name: common
    repository: file://../../
    version: ~2
  - alias: app-02-internal-bluegreen
    name: common
    repository: file://../../
    version: ~2    

and the values.yaml of this microservice looks like this:


global:
  application:
    imageName: foo
    imageTag: bar
    envVariables: {}
    rookout:
      enabled: false
    config:
      logLevel: INFO
      foodb:
        fooDbName: fooDbName
        fooDbHost: fooDbHost

applications:
  - app-01
  - app-02 

app-01:
  config:
    foodb:
      fooDbName: fooDbName2
      fooDbHost: fooDbHost2

in this common chart in my values.yaml file I have the following value:

commonDefaults:
  rookout:
    enabled: true

in my deployment.yaml for this chart I am merging the values of 2 values.yaml using the following code:

{{- $values := merge (.Values | deepCopy) (.Values.global.application | deepCopy) (.Values.commonDefaults | deepCopy) -}}

The point being that in this example, .Values.commonDefaults is being overriden by .Values.global.application and both are overriden by .Values which in this case is values set in the MS values.yaml under app-01.

The thing is that global.application.rookout.enabled=false is not overriding commonDefaults.rookout.enabled=true. Even though it works if I put global.application.rookout.enabled=foobar, in which case it does override as expected.

I am using helm version 3.8.2 although it doesn't work with 3.12.2 as well.

Helm is appreciated.

答案1

得分: 0

对于那些在helm使用案例中遇到困难的人,以下是相关的解答:

这是不可能的。GO Spring模板语言将值someKey: false视为未定义。

因此,如果你有一个默认值someKey: true,并且你试图用一个未定义的值--set someKey=false来覆盖它,那么helm不会更改默认值,因为你不能用一个未定义的值来覆盖一个值。

我的解决方案是将helm图表中的所有逻辑都更改为"true"和"false",所以不再使用{{ if .Values.someKey }},而是使用{{ if eq .Values.someKey "true" }}

当我想在命令行界面中覆盖它时,我使用--set-string someKey=false

这不是很好,但这就是现实。

英文:

For whoever finds this question relevant for the helm use-case they are struggling with here goes:

It's not possible. The GO spring templating language treats the value someKey: false as undefined.

So, if you have a default value someKey: true and you are trying to override it with an undefined value i.e. --set someKey=false then helm will not change the default value because you don't override a value with an undefined value.

My solution was to change all the logic in my helm chart to "true" and "false" so instead of: {{ if .Values.someKey }} I use {{ if eq .Values.someKey "true" }}

And when I want to override it in the cli I do --set-string someKey=false

it's not nice but it's what it is.

huangapple
  • 本文由 发表于 2023年8月8日 21:38:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76860111.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定