New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default function treats boolean false as not defined, and applies default #3308
Comments
You have the arguments flipped in the wrong direction. It should be |
@bacongobbler apologies, i noticed this too but it's still incorrect the other way.... I also tried You would expect that to be false however: |
Ah, I forgot that "empty value" is It's probably better to use |
Ahh that clarifies, how annoying! |
Hi @bacongobbler , What if I'd like to use this in a block
and I want the |
This is still open, istn't it? |
This is the workaround I use:
Obviously, if the dictionary you're checking is something like
The reason I'm using Obviously, the only works if |
Why this is closed? Issue still exists |
What issue are you seeing @marcinma? What's your recommendation for a fix? |
That's wrong. There's a bug here and this needs to reopened. |
The issue has been reported in Sprig. |
Lets start with obvious test: $> cat values.yaml
bugExists: false
$> cat templates/bug.yaml
defaul result oposite: {{ default .Values.bugExists true }}
default result normal: {{ default true .Values.bugExists }}
real value: {{ .Values.bugExists }}
$> helm template --output-dir=out .
wrote out/test/templates/bug.yaml
$> cat out/test/templates/bug.yaml
---
# Source: test/templates/bug.yaml
defaul result oposite: true
default result normal: true
real value: false
Although false is defined it is not used in any case. Not sure how this can be fixed yet this bug shouldn't be closed. |
@tw0517tw Did you found any solution to this? |
@gabordk No I didn't find any. |
sad to see this does not work: |
@bacongobbler If this is working as intended (that you cannot use |
Similarly, an integer value of 0 is always replaced by the default. |
@gabordk and anyone else that my encounter this issue, this is my workaround that I am using is a few templates:
in action:
|
cf. helm/helm#3308 Signed-off-by: Yong Wen Chua <lawliet89@users.noreply.github.com>
…2391) cf. helm/helm#3308 Signed-off-by: Yong Wen Chua <lawliet89@users.noreply.github.com>
…lm#22391) cf. helm/helm#3308 Signed-off-by: Yong Wen Chua <lawliet89@users.noreply.github.com>
…lm#22391) cf. helm/helm#3308 Signed-off-by: Yong Wen Chua <lawliet89@users.noreply.github.com>
…lm#22391) cf. helm/helm#3308 Signed-off-by: Yong Wen Chua <lawliet89@users.noreply.github.com>
…lm#22391) cf. helm/helm#3308 Signed-off-by: Yong Wen Chua <lawliet89@users.noreply.github.com> Signed-off-by: Adrien Loiseau <adrien.loiseau@logic-immo.com>
I had same issue with I solved it by using and explicit
|
In some cases it may be useful to also add the
|
I do:
Which looks in .Values for the key, "somekey". If it's there, it uses that value. If it's not, it uses (in the above example) true as the default. |
…e details please see: helm/helm#3308 (#55) Co-authored-by: Eugene Furmanyk <eugene.furmanyk@ringcentral.com>
For anyone stumbling here from doing a google search on this issue, it is indeed still an issue but the real hero is @cosimps whose workaround works beautifully. Much appreciated! |
It works. But can you explain why the bracket can work it? |
How is this not re-opened or fixed? This is a really helpful thread with some workarounds, but we shouldn't need it. This functionality with |
I'm going to put this solution to my problem here in case it helps anyone: I wanted to render part of a template (a deployment label) by default unless the values.yaml explicitly stated that a value was false:
Here is the explanation of using the parenthesis on my evaluated value > https://stackoverflow.com/questions/59795596/how-to-make-nested-variables-optional-in-helm/68807258#68807258 And I am simply use a "not equals" which fits the logic very nicely. The users of my chart will have to explicitly state the specific value as |
five years later and i fall into the same hole now, this issue should be fixed |
IMO the solution from @joejulian that is using the "dig" function is the most elegant, readable and simple solution. Update: it is indeed mentioned in the documentation |
The use of the `default` function had the unintended side-effect of never allowing the value to be `false`. See the following for more details: - [helm/helm#3308](helm/helm#3308) - [Masterminds/sprig#111](Masterminds/sprig#111) - [Default Functions](http://masterminds.github.io/sprig/defaults.html)
* Allow services to be exposed via HTTP. The use of the `default` function had the unintended side-effect of never allowing the value to be `false`. See the following for more details: - [helm/helm#3308](helm/helm#3308) - [Masterminds/sprig#111](Masterminds/sprig#111) - [Default Functions](http://masterminds.github.io/sprig/defaults.html) * Release info: v1.0.2-r6
The use of the `default` function had the unintended side-effect of never allowing the value to be `false`. See the following for more details: - [helm/helm#3308](helm/helm#3308) - [Masterminds/sprig#111](Masterminds/sprig#111) - [Default Functions](http://masterminds.github.io/sprig/defaults.html)
Almost six years and it is still an issue. I want to explicitly change default- |
What I'm trying to do is: if my So:
It thought either of these would work:
...but they don't. After a lot of trial and error, this is the simplest workaround I could find:
This works because "toString" on an undefined boolean returns But still, having an undefined boolean always return Please re-open this issue, until the "default" function can be used with boolean values without these workarounds. |
I not found simple way to resolve case with set False when default value is True.
template.yaml ---
flag1: {{ .Values.flag1 | default (eq (toString .Values.flag1) "<nil>" | ternary true false) }}
flag2: {{ .Values.flag2 | default (eq (toString .Values.flag2) "<nil>" | ternary true false) }}
flag3: {{ .Values.flag3 | default (eq (toString .Values.flag3) "<nil>" | ternary true false) }}
flag4: {{ .Values.flag4 | default (eq (toString .Values.flag4) "<nil>" | ternary true false) }}
flag5: {{ .Values.flag5 | default (eq (toString .Values.flag5) "<nil>" | ternary true false) }} values.yaml ---
flag1: test
flag2: true
flag3: false
flag4:
# flag5: output ---
flag1: test
flag2: true
flag3: false
flag4: true
flag5: true |
@tgolly I have exactly your used case and I have not been able to workaround it. Did you manage to find a workaround at the end? |
@michelefa1988 No. 😢 This issue really needs to be re-opened. |
The issue has to be reopened. The root of the issue boils down to the coalescing of Given that making a change to the And for ppl that go around down-voting comments: please grow up. |
I suspect some comments are downvoted because they either don't bring anything to the discussion, or are not respectful. I've just unsubscribed 🙂 Good luck everybody! |
I think you are right @pawamoy . |
We just hit this too, kind of silly that this hasn't been fixed yet |
It turns out that the `default` function in Helm doesn't work as expected for `boolean` types (which you would expect it to work for at the bare minimum), but this is because of a technicality in Helm's design: helm/helm#3308 Also, we had to add code to handle legacy storage configuration in the new StorageEnv code for the storage service.
It turns out that the `default` function in Helm doesn't work as expected for `boolean` types (which you would expect it to work for at the bare minimum), but this is because of a technicality in Helm's design: helm/helm#3308 Also, we had to add code to handle legacy storage configuration in the new StorageEnv code for the storage service.
It turns out that the `default` function in Helm doesn't work as expected for `boolean` types (which you would expect it to work for at the bare minimum), but this is because of a technicality in Helm's design: helm/helm#3308 Also, we had to add code to handle legacy storage configuration in the new StorageEnv code for the storage service.
values.yaml:
in template:
I would expect this to return
false
, assomeKey
is defined, and its value is false, however it returns true.The text was updated successfully, but these errors were encountered: