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
Use Global Values when local values doesn't exist #5676
Comments
I also tried use default from http://masterminds.github.io/sprig/defaults.html with this code
and this:
without lucky, It seems only print local value if global is not defined. |
@mcortinas If I understand it right, you want the local variable to have precedence over the global one. Two things... First, I would be very curious to know your use case so we can better understand the need. We're always curious to understand what people are doing and why they're doing it. Second, you could create a function in the _helpers.tpl file to pick the local one if it has a value or fall back to a global one. This might provide a quick solution you can use now. |
@mattfarina I was thinking about a similar functionality. I have a few standalone charts that can also be grouped together under a parent chart. Two scenarios here...
Deployed with the parent, I could see arguments for expecting a plate of bacon and a plate of sausage, but given the way that helm sets values, you'd end up with 2 plates of sausage. Apologies for the poor example, but tried to keep it simple. |
Also reminds me of #2492 |
@mattfarina , let me explain my use case.... my team develop charts and this is used by other teams teams as a subchart several times in a mega chart with helm dependencies using aliases.
I tried use sprig functions like coalesce or add the in templa a simple if clause but I found this issue with nested values like this:
Finally, I think I'm following applying KISS and apply the solution adding global inside each aliases in the parent chart values.yaml commented in my first comment, I don't like due to the global parent has more priority than the global inside each alias... but is more trustly. |
This could also be usefull to pass the nodeSelector to all dependency, with helm --set global.nodeSelector=… Each dependency would use it, unless dependency.nodeSelector is defined |
Don't know if the question is still valid, but I think I solved this problem by using merge function values.yaml:
And then in any of the subchart templates
which should print
This will make subchart value override global value (this is because we passed local .Values as a first argument to merge which takes higher precedence). |
thanks @flutt13 for the solution. I guess we can consider this resolved. |
I want use local values from alias dependency more priority than a common values. If the local value exist use this instead of global value.
Let me share an example of values.yaml in the parent chart
The only option to do that I think is templating the subchart with this code
Basically, we want use a global values when local values is not set.
I tried the workaround commented on #2076 using the global inside a local valuas from alias (called stable in this example)
This is not a perfect workaround due to the global variables has more priority than local variables, let me define a common section in the same values file but with more priority.
Do you know some go functions in order to be subchart template code more simple???
The text was updated successfully, but these errors were encountered: