feat: accept strings that evaluates to bool in release condition#840
Conversation
|
@PatrykKlimowicz Please fix DCO issue. |
3b60198 to
cf74c5d
Compare
|
Why not use installed field? |
|
Hey @PatrykKlimowicz! Thanks for your contribution.
Every non-all environment seem to inherit missing values from the Sorry if I lost memory or missed something. Thanks in advance for your help! |
Correct me if I'm wrong, but releases marked with |
Sorry, I do not have the possiblity to provide the full description now. However, there is no inheritance between envs, they are still independent. I will update later today/tomorrow morning with the examples. |
Ok, found some time to sit in front of my laptop. Right now there is a need to specify the envs as following: environments:
foo:
values:
- foo:
enabled: true
- boo:
enabled: false
- bar:
enabled: false
boo:
values:
- foo:
enabled: false
- boo:
enabled: true
- bar:
enabled: false
bar:
values:
- foo:
enabled: false
- boo:
enabled: false
- bar:
enabled: trueand this is because of how releases:
- name: foo
chart: ./foo
condition: 'foo.enabled'
values:
- ./foo/values-extra.yaml
- name: boo
chart: ./boo
condition: 'boo.enabled'
values:
- ./boo/values-extra.yaml
- name: bar
chart: ./bar
condition: 'bar.enabled'
values:
- ./bar/values-extra.yamlso if we ran the This PR gives us possibility to minimize the code duplication in the environments:
foo:
values:
- foo:
enabled: true
boo:
values:
- boo:
enabled: true
bar:
values
- bar:
enabled: trueHowever, to avoid panic in the ---
releases:
- name: foo
chart: ./foo
condition: '{{ .Values | get "foo.enabled" "false" }}' # obtain value or fallback
values:
- ./foo/values-extra.yaml
- name: boo
chart: ./boo
condition: '{{ .Values | get "boo.enabled" "false" }}' # obtain value or fallback
values:
- ./boo/values-extra.yaml
- name: bar
chart: ./bar
condition: '{{ .Values | get "bar.enabled" "false" }}' # obtain value or fallback
values:
- ./bar/values-extra.yamlAfter we ran the In the current approach of helmfile, we have to specify the default values in the each environment. This PR does not impact the helmfiles that people has created already. It also does not change the default helmfile behavior. It adds possibility to use the "special" strings as the value for Why this is important to have this possibility?
With this PR we can achieve # releases / # loc in whole environments section:
Happy to answer some more questions 😄 |
|
To give you some insights how exactly the code change is working:
|
|
@PatrykKlimowicz Thanks for clarifying! Ah gotcha! So the key idea in this pull request is that you define default values in Presuming that's correct, how about implementing some kind of "inheritance" to environments instead, like we've done for templates/releases in #606? It could be implemented to look like this: or to avoid mixing "template" environments (like "all", which is not supposed to be used directly via or more simply, introduce some defaults like |
|
@mumoshu The key idea is to make the hardcoded nature of
The proposals you've made are kind of interesting! I'd say I really like the clean nature of Anyway, the idea from this PR can be independent from the To sum up, it would be really nice to have this |
This adds more flexibility to helmfile conditioning by:
- Adding: strconv.ParseBool() allows evaluating strings to booleans
which gives possibility to extend the conditioning
functionality
- Changing: the error message displayed on the terminal when value
for the condition field is neither in 'foo.enabled' format
nor a string that can be evaluated to bool value
- Removing: -
Resolves: helmfile#837
Signed-off-by: Patryk Klimowicz <[email protected]>
cf74c5d to
c77736f
Compare
|
@mumoshu any decisions? 😄 |
Yes! That is to make the condition field look very similar to helm's Chart.yaml |
Ok, I'll propose this |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
@PatrykKlimowicz any updates? |
|
you could define "default" values to false and only the overrides in environments: |
Sorry, got stuck with other work. I'll open PR tomorrow |
|
I suggest to extend it not only for bools, but also for other types - see my topic in discussions: #926 |
|
@JuryA Hey! Please also see this one #913 (comment) In short, I'm doubting that we are about to outgrow yaml + go template based solution.... |
| conditionSplit := strings.Split(r.Condition, ".") | ||
| if len(conditionSplit) != 2 { | ||
| return false, fmt.Errorf("Condition value must be in the form 'foo.enabled' where 'foo' can be modified as necessary") | ||
| return false, fmt.Errorf("condition value must be either in the form 'foo.enabled' where 'foo' can be modified as necessary or string that can be evaluated to bool") |
There was a problem hiding this comment.
I contend that introducing unnecessary complexity serves no purpose. The issue at hand aptly demonstrates this point. My reasoning is influenced by Helm's elegant handling of its dependencies[].condition parameter in the Chart.yaml file. This parameter singularly points to another key in $.Values, without any concern for the data type—be it boolean, string, or map. To elaborate, I often employ a key named enabled, which can take on a variety of values—true, "true", or more specialized values like "manual" or "auto". Such values are evaluated as true for dependency conditions for the simple reason that they are not null. Any deviation from this approach would be excessive. The condition is met when the targeted key is present and its value is not empty; otherwise, the condition remains unfulfilled. The choice of how to manage this rests solely with the Helm chart developer.
In the same vein, I propose the following criteria for this case, which negates the need for type-specific considerations:
- Existence of Key
- Contains a non-empty value? ➜ Condition: True
- Lacks value? ➜ Condition: False
- Absence of Key ➜ Condition: False
Greetings. Apologies for the delayed response. I've taken some time to evaluate the benefits of both Jsonnet and CUE. Both have their unique advantages and optimally, supporting both would be beneficial. However, I understand this might complicate the codebase. The immediate issue to address is the unavailability of some key fundamental information. Currently, obtaining this data requires cumbersome, less-than-ideal methods. This problem is magnified when considering cross-platform compatibility, affecting Windows, Linux, and macOS. Fortunately, one can rely on Git for this purpose. For example, on Windows, we can use: git -c 'alias.cmd=!<some command> <its_args>' cmdIt's a somewhat inelegant and hacky solution, isn't it? 😬 But it ensures that the command will execute in Git Bash on Windows and in a suitable shell on other POSIX platforms. It would be advantageous to directly provide some well-known information at runtime by Helmfile itself among other objects. For example: Helmfile Root Directory:values:
- Helmfile:
Paths:
helmfileRoot: !!str {{ exec "git" (list "-c" "alias.pwd=!pwd" pwd) | trim | osClean }}PWD:{{ $PWD := env "PWD" | osClean }}Pertinent Paths:{{ $Helmfile := .Values | get "Helmfile" (dict) }}
{{ $Self := $Helmfile | get "Self" (dict) }}
{{ $helmfilePath := $Self | getOrNil "helmfilePath" }}
{{ $helmfileDir := $helmfilePath | osDir }}
{{ if not $helmfilePath }}
{{ print "\n\n.Values.Helmfile.Self.helmfilePath not defined!\n\n" | fail }}
{{ end }}Other Paths: - Helmfile:
Self:
helmfileDir: &helmfileDir {{ $helmfileDir | osClean | quote }}
helmfilePath: &helmfilePath {{ $helmfilePath | osClean | quote }}
helmfileName: {{ $helmfilePath | osBase | quote }}
Paths:
helmfileDir: *helmfileDir
helmfilePath: *helmfilePath... and many others... |
This adds more flexibility to helmfile conditioning by:
Resolves: #837
With this PR the following configuration:
can be minimized to:
and then in the
helmfile.yamlthis can be specified:and the following commands will work just fine:
What are cons here?
Users will have to chose the way of defining the conditions and stick to it. The 'string to bool' (the one proposed in this PR) and 'variable path to bool' (the one that is currently in use) approaches cannot be mixed. Mixing of these two approaches will result in panic:
panic: environment values does not contain field 'sampleFieldName'Hope you will find this useful and accept this PR! 😄
P.S. I did not add the docs yet, as I do not know if you will accept this PR. If there will be a green light, then I'm more than happy to update the documentation.