Merge pull request #2648 from scottrigby/allow-delete-key

Allow deletion of a previous values file key
pull/2662/head
Taylor Thomas 8 years ago committed by GitHub
commit 97818b1fce

@ -98,4 +98,35 @@ data:
While structuring data this way is possible, the recommendation is that you keep your values trees shallow, favoring flatness. When we look at assigning values to subcharts, we'll see how values are named using a tree structure.
## Deleting a default key
If you need to delete a key from the default values, you may override the value of the key to be `null`, in which case Helm will remove the key from the overridden values merge.
For example, the stable Drupal chart allows configuring the liveness probe, in case you configure a custom image. Here are the default values:
```yaml
livenessProbe:
httpGet:
path: /user/login
port: http
initialDelaySeconds: 120
```
If you try to override the livenessProbe handler to `exec` instead of `httpGet` using `--set livenessProbe.exec.command=[cat,docroot/CHANGELOG.txt]`, Helm will coalesce the default and overridden keys together, resulting in the following YAML:
```yaml
livenessProbe:
httpGet:
path: /user/login
port: http
exec:
command:
- cat
- docroot/CHANGELOG.txt
initialDelaySeconds: 120
```
However, Kubernetes would then fail because you can not declare more than one livenessProbe handler. To overcome this, you may instruct Helm to delete the `livenessProbe.httpGet` by setting it to null:
```sh
helm install stable/drupal --set image=my-registry/drupal:0.1.0 --set livenessProbe.exec.command=[cat,docroot/CHANGELOG.txt] --set livenessProbe.httpGet=null
```
At this point, we've seen several built-in objects, and used them to inject information into a template. Now we will take a look at another aspect of the template engine: functions and pipelines.

@ -2,3 +2,8 @@ scope: moby
name: moby
override: bad
top: nope
bottom: exists
right: exists
left: exists
front: exists
back: exists

@ -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 {
// 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
delete(v, key)
continue
} else if dest, ok := v[key].(map[string]interface{}); ok {
// if v[key] is a table, merge nv's val table into v[key].
src, ok := val.(map[string]interface{})

@ -277,6 +277,11 @@ func ttpl(tpl string, v map[string]interface{}) (string, error) {
var testCoalesceValuesYaml = `
top: yup
bottom: null
right: Null
left: NULL
front: ~
back: ""
global:
name: Ishmael
@ -316,6 +321,7 @@ func TestCoalesceValues(t *testing.T) {
expect string
}{
{"{{.top}}", "yup"},
{"{{.back}}", ""},
{"{{.name}}", "moby"},
{"{{.global.name}}", "Ishmael"},
{"{{.global.subject}}", "Queequeg"},
@ -343,6 +349,13 @@ func TestCoalesceValues(t *testing.T) {
t.Errorf("Expected %q to expand to %q, got %q", tt.tpl, tt.expect, o)
}
}
nullKeys := []string{"bottom", "right", "left", "front"}
for _, nullKey := range nullKeys {
if _, ok := v[nullKey]; ok {
t.Errorf("Expected key %q to be removed, still present", nullKey)
}
}
}
func TestCoalesceTables(t *testing.T) {

Loading…
Cancel
Save