Repository navigation
Conversation
|
@jamoflaw I attempted the following test: subchart with values resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Michart that uses subchart as a dependency: subchart:
resources:
requests:
cpu: 1000m
memory: 2Gi
limits:
cpu: null
memory: 2GiResulted in the following to be rendered: resources:
limits:
cpu: 100m
memory: 2Gi
requests:
cpu: 1000m
memory: 2GiUnfortunately, the original value remains |
|
@sabre1041 do you happen to have the chart you tested it on available? I tested this PR on one of my internal ones and it was able to remove mapping values which were set in the subchart from a values file. (ie So my testing was effectively the equivalent of sub chart with values: Then in the parent chart - nothing above is set Then I am passing in (with Which results in: |
|
@jamoflaw this is unfortunately a large issue where there are multiple scenarios that need to be accounted for. My test did not explicitly reference an external values file but were referenced in the parent chart that used the chart as a dependency |
|
Agreed! I've written another unit test which covers that scenario and I'll have a look at seeing whats going on |
|
OK yeah I've replicated it - the same case works in the current unit tests though, which isn't ideal!! I'll update the PR with a fix and write a unit test which triggers it. Thanks @sabre1041 |
|
So this update fixes it for parent chart overrides too. The issue seems to be that CoalesceValues isn't idempotent when it comes to null removal behaviour and it is called a LOT throughout the rendering pipeline basically removing nulls on the first call then remerging values back in from subcharts on subsequent calls. What I did here was split the CoalesceValues into two (keeping the old names pointing back at the new variant which shares its old behaviour) so it is clear what each variant does, and then delay the removal of null keys even further than previous (basically at the end of the rendering pipeline) The two variants are *KeepNil and *TrimNil which as their names suggest either keep nils around or trim them. Where possible the Trim variant is used to make sure behaviour isn't needlessly changed, but during initial dependency gathering its changed to the KeepNil variant to avoid early stripping of null keys. |
the values. Creating new public function TrimNilValues which does the final nil value removal. This is called in ToRenderValues before final schema validation. Signed-off-by: James Payne <[email protected]>
|
@sabre1041 as an alternative to this PR I have also prepared main...jamoflaw:helm:fix-null-removal-in-nested-subcharts-alt. Both the current state of this PR and this new alternative branch now handle my original case (where overrides in files provided with Personally I feel the alternative branch above is a simpler and more effective solution but unlike this PR it means that the current behaviour of CoalesceValues changes slightly. The current behaviour is inconsistently buggy around null removal whereas in my alternative branch above it is always consistently now not removing null keys. Instead this is delegated to a new public method I have purposely not yet raised this as a new PR as wanted to get some feedback on if this approach is viable given it alters the CoalesceValues behaviour slightly. |
|
@jamoflaw can confirm that the PR above does work as expected with the use case that I brought up. I'll look more into the implementation and any potential implication of the change in functionality within the |
|
Any hope of this one getting pushed through for the 11/09 release? Any way I can upvote it? |
|
@Vermyndax I can take a look again later on this week |
|
For my 2c on the issue: I prefer this implementation main...jamoflaw:helm:fix-null-removal-in-nested-subcharts-alt as its significantly cleaner IMHO, but replaces a buggy behaviour - where null keys are removed inconsistently, with a consistent behaviour where null keys are instead retained and returned by that function. Internally then keys are removed with a second dedicated function. I'm happy to rewrite as required to get this one working, maybe taking the alternative approach PR and making it backward compatible, splitting new behaviour into new functions? This does hit us quite a bit as we use nested helm charts a lot, but would like some guidance on the approach just so I don't rewrite it in the wrong direction. |
|
...longingly came by to check on all of you... hope you're well... :) Is there anything I can do to help push this along? |
|
Hey, is there anything to help expedite this, it'll be super useful for our work and the sooner the better for us! |
Just a follow up on this comment - I will have time to look at it this weekend - does it seem like something which would be worth following up on as I wouldn't want this issue to become stale |
|
@jamoflaw I'd like to move this forward. please take a look at it at your convenience and we can push forward as it is an issue that does need to be addressed |
|
+1 i follow this PR, useful in scenario when we want to remove (default) resources.limits of |
|
can someone please give this a look? As of 2 weeks ago it's been LGTM'd, it's passing CI, and it still missed another release window |
|
Any chance that this is ready for 3.12.0? This fix would be great to finally remove workarounds. |
|
Any progress on getting this merged in? I just hit this issue with multiple of our Helm charts. |
|
Is there anything I need to do at this stage? Do we need additional approvers given the size/L tag @sabre1041? |
| // the values destined for its dependencies. | ||
| // | ||
| // Note that CoalesceValues automatically removes nil values | ||
| func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) { |
There was a problem hiding this comment.
Couldn't CoalesceValues be written like? (or did I miss something)
func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) {
return TrimNilValues(MergeValues(chrt, vals))
}
There was a problem hiding this comment.
I think it could actually - currently TrimNilValues doesn't return the err on line 96 which I think could be improved as well, if that was done the sigatures should be compatible.
Ill give this a go tomorrow and test it out
There was a problem hiding this comment.
So it works out as:
func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) {
valsCopy, err := MergeValues(chrt, vals)
if err != nil {
return vals, err
}
return TrimNilValues(valsCopy)
}
to avoid passing the error down into TrimNilValues - I'll run against my larger charts which show the original error tomorrow morning
There was a problem hiding this comment.
Since the bulk of CoalesceValues is MergeValues can we have the code updated to this.
| if val, ok := values["top"]; !ok || val != "exists" { | ||
| t.Errorf("Key top was expected to be 'exists' but it is %s", val) | ||
| } | ||
| if val, ok := values["bottom"]; !ok || val != "exists" { | ||
| t.Errorf("Key bottom was expected to be 'exists' but it is %s", val) | ||
| } | ||
| if val, ok := values["left"]; ok || val != nil { | ||
| t.Errorf("Key left was expected to be missing but it is %s", val) | ||
| } | ||
| if val, ok := values["right"]; !ok || val != "exists" { | ||
| t.Errorf("Key right was expected to be 'exists' but it is %s", val) | ||
| } | ||
|
|
||
| nested := values["nested"].(map[string]interface{}) | ||
| if val, ok := nested["left"]; !ok || val != true { | ||
| t.Errorf("Key nested.left was expected to be true but it is %s", val) | ||
| } | ||
| if val, ok := nested["right"]; ok || val != nil { | ||
| t.Errorf("Key nested.right was expected to be missing but it is %s", val) | ||
| } |
There was a problem hiding this comment.
somewhat stylistic, but perhaps a deep equal would be more concise here?
expectedValues := map[string]interface{}{
"top": "exists",
"bottom": "exists",
"right": "exists",
"nested": map[string]interface{}{
"left": true,
},
}
assert.Equal(t, expectedValues, values) # https://pkg.go.dev/github.com/stretchr/testify/assert#Equal
I think (would need to be vetted) that the deep-equal comparison provided by https://pkg.go.dev/github.com/stretchr/testify/assert#Equal would do the expected behavior here
| // We could change that. For now, though, we retain that strategy, and thus can | ||
| // coalesce tables (like reuse-values does) instead of doing the full chart | ||
| // CoalesceValues | ||
| // MergeValues |
| t.Fatal(err) | ||
| } | ||
| j, _ := json.MarshalIndent(v, "", " ") | ||
| t.Logf("Coalesced Values: %s", string(j)) |
There was a problem hiding this comment.
| t.Logf("Coalesced Values: %s", string(j)) | |
| t.Logf("Merged Values: %s", string(j)) |
| } | ||
|
|
||
| // Remove nil values from the coalesced map | ||
| vals = TrimNilValues(vals) |
There was a problem hiding this comment.
I suppose this is now what removes nil values from the "defaults"?
https://helm.sh/docs/chart_template_guide/values_files/#deleting-a-default-key
There was a problem hiding this comment.
Yup its basically done last as the previous issue was due to CoalesceValues basically being non-idempotent but being called as if it was. This delays that call to the last moment before its needed
mattfarina
left a comment
There was a problem hiding this comment.
Thanks for the PR and for putting work into this, @jamoflaw
I did a brief run though and have some questions (and one comment). A big thing is to look at all the consequences of the change. Including how output changes.
I'll circle back with more feedback asap but wanted to get these questions added before I walk away from the PR for the day.
| // the values destined for its dependencies. | ||
| // Note that MergeValues does NOT automatically remove nil values, it is up | ||
| // to the caller to ensure that TrimNilValues is called at the appropriate time | ||
| func MergeValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) { |
There was a problem hiding this comment.
Helm is both a client (as in the CLI - the helm tool) and an SDK. Other applications can use the public functions in their own code. CoalesceValues is an example of a function used by others. I'm reviewing CoalesceValues and MergeValues with that in mind.
MergeValues is the exact same code as CoalesceValues was before this change. Is that because you think trimming should be part of the exported code used by other applications? CoalesceValues is no longer used by Helm itself.
There was a problem hiding this comment.
Its the opposite so MergeValues is called internally but leaves null values as is - CoalesceValues maintains exactly the same external behaviour - in that nulls are removed albeit maintaining that incorrect behaviour if its called multiple times such as how Helm internally does it
| // - Scalar values and arrays are replaced, maps are merged | ||
| // - A chart has access to all of the variables for it, as well as all of | ||
| // the values destined for its dependencies. | ||
| // Note that MergeValues does NOT automatically remove nil values, it is up |
There was a problem hiding this comment.
Can you put a blank link before the Note. So that it appears separately from the final bullet.
| // TrimNilValues removes nil/null values from maps. | ||
| // | ||
| // To be used after CoalesceValues to remove keys as needed |
There was a problem hiding this comment.
The function comment is a little unclear here. These comments are for external users of the SDK.
CoalesceValues uses TrimNilValues. If an end user uses CoalesceValues there is no need to use TrimNilValues.
Can you please update the comment for clarity.
There was a problem hiding this comment.
Ah this is true it should mention MergeValues here instead
| // the values destined for its dependencies. | ||
| // | ||
| // Note that CoalesceValues automatically removes nil values | ||
| func CoalesceValues(chrt *chart.Chart, vals map[string]interface{}) (Values, error) { |
There was a problem hiding this comment.
Since the bulk of CoalesceValues is MergeValues can we have the code updated to this.
| fmt.Fprintln(out) | ||
|
|
||
| cfg, err := chartutil.CoalesceValues(s.release.Chart, s.release.Config) | ||
| cfg, err := chartutil.MergeValues(s.release.Chart, s.release.Config) |
There was a problem hiding this comment.
This section of code is used by helm get all, helm --debug install, and possibly other places. Before this change values that were null were not displayed in the output. After this change they are displayed with a value of null in the computed values. Is this intentional?
There was a problem hiding this comment.
Imo that is what the output should explicitly show, because that is the whole purpose of this pr. Nill values should be propagated. So any result output should list that this is what is happening. Explicitly.
There was a problem hiding this comment.
This is what I was mentioning here #11440 (comment)
Basically the original behaviour of the public function CoalesceValues is maintained in this PR and a new public function MergeValues is also created which does not trim nil values from the resulting output. This is to allow those nils to persist until the last call to TrimNilValues where they will be removed.
In short:
- MergeValues is effectively a "fixed" CoalesceValues - but it leaves nulls in place and returns them
- CoalesceValues maintains its previous potentially buggy behaviour but doesn't return null ever - I say potentially as its only when its called in succession as helm does internally - externally this behaviour may not have been seen
I have made the assumtion in the original comment that CoalesceValues should never return null - this may not be the case and in which case we could simplify this PR and the potential annoyance of wording between Merge and Coalesce - but it is potentially changing external behaviour which this current PR fixes albeit with the aforementioned naming challenges.
Before I make additional changes its probably worth clearing up if my assumption is valid or if we can make CoalesceValues return nulls
|
any updates? @jamoflaw if you're burned out on the back and forth i'd be happy to pick this up |
|
@alice-sawatzky you should take over as this is 3 years old now and we still can't "remove" value in a subchart... :/ |
I'm happy to move this forward but was waiting on feedback from the questions I've asked a couple times #11440 (comment) Specifically on direction - do we need to split these functions or can this PR be simplified as we could return null from the original function? |
basically I don't want to unnecessarily make this PR more complex than it needs to be - specifically changing the language used for the function names - its an annoying change to have to make - and I'm seeking advice on if that is wanted |
|
I have a few things to add here... First, we can't change the behavior of a public function. If it removed null values before and that behavior is removed from it, that's a problem because it breaks SemVer. People use the Helm SDK and we need to avoid breaking changes until Helm v4 comes out. It appears that means the "simpler change" won't work. I'm skipping the second question because I was looking at #9027 and found the difference is in where |
Yeah that does make sense Ref to ensure it works with a copy and it didn't seem to make any difference. I did notice though that the chart.Values value gets worked on a lot in those calls via a ptr and that passes through the same CoalesceValues functions multiple times. It seems that some of those calls are intended to mutate that object though? |
|
@jamoflaw I'm fairly deep into this one now. I might have a fix. More testing required. I found two problems...
I'm testing some ideas out right now to better deal with the 2 issues. Also need to make the changes in a backward compatible manner. I'll have more to share soon. |
|
Thanks @mattfarina - should this PR be closed up with a link to the new one in that case? |
|
When will this be released? This has been an issue since december 2020.... |
|
Based on my tests, the issues attached have both been fixed by #12162. Closing. |
|
@shazada a fix for this problem is scheduled for release on September 13th. |
closes #9136
closes #9027
This PR contains two commits, the first replicates the behaviour described in #9136 and the second resolves it.
The original unit-tests did have a case for the subchart values and it was passing, so I spent some time trying to work out why there is a difference between the behaviour of the unit-tests and real world usage. It seems that the bug is related to the way the chart object is mutated by chartutil.ProcessDependencies. During that call the chart objects values are merged with its subcharts leading to a situation where all values are merged together into the parent chart's values.
To replicate this behaviour in the unit tests I just added the following to the parent charts definition:
Since
baris now defined in that parent chart object, when the call tocoalesceValues(printf, ch, dest, prefix)was made, the dest object was mutated and null keys were removed from both the parent chart and subchart values. The subsequent call tocoalesceDeps(printf, ch, dest, prefix)then has no more null keys anymore so the subcharts no longer have any keys removed, which causes the subcharts values to be merged back into the parent chart (undo-ing the null removal from the previous call to coalesceValues).The changes made effectively delay the removal of the null keys until after both the
coalesceValuesandcoalesceDepscalls are completed.