-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Allow deletion of a previous values file key #2648
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
Conversation
@scottrigby I think that you added the right logic in the wrong place. When I specify
The function you modified only is merging user supplied values, not the |
cmd/helm/install.go
Outdated
// If the new value is literally the string "null", remove the value's key. | ||
// This allows helm's multiple value sources (value files or --set) to | ||
// remove incompatible keys from the previous values. | ||
if v == "null" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Note that "null" is only one of the values that the YAML specification projects to null.
There is also "Null," "NULL," and "~."
cmd/helm/install.go
Outdated
@@ -273,6 +273,14 @@ func (i *installCmd) run() error { | |||
// Merges source and destination map, preferring values from the source map | |||
func mergeValues(dest map[string]interface{}, src map[string]interface{}) map[string]interface{} { | |||
for k, v := range src { | |||
// If the new value is literally the string "null", remove the value's key. | |||
// This allows helm's multiple value sources (value files or --set) to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- s/helm's/Helm's/
- s/multiple value sources/various sources of values/
@thomastaylor312 @seh I just updated this to cover earlier feedback. Thanks @rabellamy for pairing on Golang syntax. |
I'm trusting @thomastaylor312 that the accommodation is in the right place now. Reviewed 2 of 2 files at r2. pkg/chartutil/values.go, line 281 at r2 (raw file):
This reads strangely. How about "is the YAML null value?" pkg/chartutil/values.go, line 286 at r2 (raw file):
You can instead write the following: case "null", "Null", "NULL", "~": Alternately, use a regular expression. Comments from Reviewable |
Reviewed 1 of 1 files at r3. pkg/chartutil/values.go, line 286 at r2 (raw file): Previously, seh (Steven E. Harris) wrote…
I like the regular expression approach because it allows you to write the following: if stringIsYAMLNull(val) {
delete(v, key)
continue
} The single-case Comments from Reviewable |
@seh I'd be OK with adding the regex check. Honestly that does feel cleaner (and more reusable) to me too. I'll ping you on Slack to make sure I'm 100% clear on how and where you'd like organized in the codebase. |
@seh I changed the switch case to a simple in-place version of |
@thomastaylor312 OK, I changed to nil comparison. Thanks for checking that this is the case 💯 If this needs a test, can you point me in the right direction of where to look for the existing tests here? Also, could a test be a follow-up PR, or should it be the same one? |
@thomastaylor312 How do these tests look? |
pkg/chartutil/values_test.go
Outdated
@@ -316,6 +322,8 @@ func TestCoalesceValues(t *testing.T) { | |||
expect string | |||
}{ | |||
{"{{.top}}", "yup"}, | |||
// The keys bottom, right, left, front, and back should not be present. | |||
{"{{.side}}", ""}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look great, we do need to test that all of the other keys are unset. This was a learning experience for me too, but I found out it should look like this: {"{{.bottom}}", "<no value>"},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that, but doesn't that signify the key is present but the value is empty? Is there currently a test method available that checks if a key is not present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely a good point. We are talking about this now in Slack to get some ideas
I manually tested this and it is good to go as soon as we have those last unit test cases. Thanks for all the hard work @scottrigby! |
@thomastaylor312 OK I updated the PR with the check to ensure keys are not present in the Values map. I just defined an array of the keys that should have null value properly recognized (and converted to Also, thanks for helping me find what type |
7a09ebc
to
2918e0c
Compare
Note that the documentation is the only clear example I can think of now, because it's from a PR I have worked on helm/charts#1375, but that PR is not yet merged. However, it clearly explains the functionality, and I tried to make it match the rhetorical style of the rest of the doc (except I added a header for clarity). If there is another, better example, we can use that. But it does feel like an example helps. Thoughts? |
The docs look good to me. Because circle isn't running the unit tests, I am running those locally and validating that they pass |
…is nil. - Note that this covers all YAML null syntax options: ref: http://yaml.org/type/null.html - Note that we do a nil comparison because the encoding/yaml package parses YAML properly and any variation of null, Null, NULL, or ~ is converted to nil by the time we get here.
…tax options, but not for empty string
0b2161c
to
8be9bb5
Compare
Rebased against |
Ok, I checked that the tests are passing, so this should be good to go. Thanks for the contribution @scottrigby! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed the merge here, but thought it was still worth noting these suggestions.
@@ -281,6 +281,13 @@ func coalesceValues(c *chart.Chart, v map[string]interface{}) (map[string]interf | |||
if _, ok := v[key]; !ok { | |||
// If the key is not in v, copy it from nv. | |||
v[key] = val | |||
} else if ok && v[key] == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Here, we could have avoided a second map lookup by binding the mapped value to a variable at line 281 above:
if value, ok := v[key]; ! ok {
// ...
} else if ok && value == nil {
// When the YAML ...
}
I'd consider then turning the conditional around:
if value, ok := v[key]; ok {
if value == nil {
// When the YAML ...
} else if dest, ok := value.(map[string]interface{}); ok {
// If v[key] is a table ...
}
} else {
// If the key is not in v ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seh If you create an issue and assign it to me, I can make these small changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That became #2663.
// When the YAML value is null, we remove the value's key. | ||
// This allows Helm's various sources of values (value files or --set) to | ||
// remove incompatible keys from any previous chart, file, or set values. | ||
// ref: http://www.yaml.org/spec/1.2/spec.html#id2803362 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'd prefer to move this reference over into the pertinent test function in file values_test.go (around line 280 there).
By the way, the |
Since #1656 Helm deep-merges multiple values files. However, this also means there is currently no way to delete an existing key that may be incompatible with a newly added one.
This PR addresses option 2 in #1966. My Golang fu is not top notch yet, but that said let me know if this is wrong so I can fix it (PS Thanks to @rabellamy for sending me Go map documentation).