Skip to content

Conversation

mattfarina
Copy link
Collaborator

First, some notes about priority and how some code flow works.

For Helm handling values, the expected order of precedence is:

  1. User specified values (e.g CLI)
  2. Imported values
  3. Parent chart values
  4. Subchart values

Helm handles dependency values slightly differently. If there are dependencies in the charts folder that are not marked as dependencies all of the values, including nil values, are pulled in. If those charts are listed as a dependency in the Chart.yaml file than they are processed for import handling. Prior to the changes here, it caused nil values at the top level to NOT remove values specified.

The changes:

  1. The order of priority was changed from the list above. Parent chart values would override specifically imported values. This is due to a change from just over a year ago that introduced a bug. That was undone by changing the precedence when maps were merged.

  2. To handle merging while retaining the nil values, which was causing inconsistent behavior, a new set of Merge functions were introduced. These functions are just like coalesce except that they DO NOT remove nil/null values. The new functions are used in a backward compatible manner meaning some new functions were introduced that called them.

Specific issues fixed (that are known):

Closes #9027

Can now delete subkeys from charts when specified in the parent. This behavior was previously inconsistent. Sometimes they could be deleted and other times it did not work. Now it is consistent.

Closes #10899

Imported values (from library or other subcharts) are now used following the order above.

The previous behavior was inconsistent. import-values using just a string would import them. When named with a child/parent it did not work if the parent already had a value. If string and named were mixed the imports worked if the string happened first but just for the string not the named. If the named parent/child went first then none of them worked for cases where the parent already had a value. It was inconsistent and the tests sometimes mirrored the functionality rather than expected behavior.

Tests for this fall into the sub-packages and are in the template tests to verify it's happening in the output. Including having values passed at the CLI as the ultimate highest priority to be used.

This relates to a fix that went in for #9940. The expected values there don't fit the precedence above where the parent value would override the imported value. That fix/change introduced more bugs.

Closes #10052

This is the case where imported values using the parent/child designation just didn't work right. That has been fixed and there are tests. The underlying issue had to do with the precedence order handling.

Note, a lot of tests were added. Hope we got it more right this time.

What this PR does / why we need it: import-values is broken which is causing a number of bugs (see above).

Special notes for your reviewer:

There have been changes around this code for years which has introduced bugs. Also, some of the old tests check for the wrong values. For example, expecting a value to be overridden but making sure it's the original value instead of the override. The system around import-values has long had issues and those issues have changed over time leading to long term inconsistency.

This change fixes some long standing issues. Some of which come up just under edge conditions (e.g., you use import-values but you use parent/child before using a string value and the parent has an existing value for the import).

If applicable:

  • this PR contains documentation
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 22, 2023
@mattfarina mattfarina added this to the 3.13.0 milestone Jun 22, 2023
@mattfarina mattfarina force-pushed the fix-merge-values-ugh branch 2 times, most recently from dd570de to d0c29d7 Compare June 22, 2023 18:53
Copy link
Contributor

@sabre1041 sabre1041 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattfarina this is really good!

One small removal of debugging

First, some notes about priority and how some code flow works.

For Helm handling values, the expected order of precidence is:
1. User specified values (e.g CLI)
2. Imported values
3. Parent chart values
4. Subchart values

Helm handles dependency values slightly differently. If there are dependencies
in the charts folder that are not marked as dependencies all of the values,
including nil values, are pulled in. If those charts are listed as a
dependency in the Chart.yaml file than they are processed for import handling.
Prior to the changes here, it caused nil values at the top level to NOT remove
values specified.

The changes:

1. The order of priority was chagned from the list above. Parnet chart values
would override specifically imported values. This is due to a change from
just over a year ago that introduced a bug. That was undone by changing the
precidence when maps were merged.

2. To handle merging while retaining the nil values, which was causing
inconsistent behavior, a new set of Merge functions were introduced. These
functions are just like coalesce except that they DO NOT remove nil/null values.
The new functions are used in a backward compatible manner meaning some new
functions were introduced that called them.

Specific issues fixed (that are known):

Closes helm#9027

Can now delete subkeys from charts when specified in the parent. This behavior
was previously inconsistent. Sometimes they could be deleted and other times
it did not work. Now it is consistent.

Closes helm#10899

Imported values (from library or other subcharts) are now used following the
order above.

The previous behavior was inconsistent. import-values using just a string
would import them. When named with a child/parent it did not work if the
parent already had a value. If string and named were mixed the imports
worked if the string happened first but just for the string not the named.
If the named parent/child went first then none of them worked for cases
where the parent already had a value. It was inconsistent and the tests
sometimes mirrored the functionality rather than expected behavior.

Tests for this fall into the sub-packages and are in the template tests
to verify it's happening in the output. Including having values passed
at the CLI as the ultimate highest priority to be used.

This relates to a fix that went in for helm#9940. The expected values there don't
fit the precedence above where the parent value would override the imported
value. That fix/change introduced more bugs.

Closes helm#10052

This is the case where imported values using the parent/child designation
just didn't work right. That has been fixed and there are tests. The underlying
issue had to do with the precedence order handling.

Note, a lot of tests were added. Hope we got it more right this time.

Signed-off-by: Matt Farina <matt.farina@suse.com>
@mattfarina mattfarina force-pushed the fix-merge-values-ugh branch from d0c29d7 to 0a5148f Compare June 26, 2023 15:37
@mattfarina
Copy link
Collaborator Author

@sabre1041 can you please re-review it?

@jamoflaw
Copy link

Thanks for jumping on this @mattfarina @sabre1041! 🚀

@jamoflaw
Copy link

Interestingly with this one I can get a situation where a null appears in the resulting template
image

This situation has:

Child values.yaml

resources:
  limits:
    cpu: 1000m
    memory: 2Gi
  requests:
    cpu: 1000m
    memory: 2Gi

Parent values.yaml

resources:
  requests:
    cpu: 1000m
    memory: 2Gi
  limits:
    memory: 2Gi
    cpu: null

CLI passed in values:

  resources:
    requests:
      cpu: 100m
      memory: 6Gi
    limits:
      memory: 32Gi

So in this case the null is being persisted rather than trimmed from the final result - is that desired?

@jamoflaw
Copy link

Minimal repro is:

Chart.yaml with

dependencies:
  - name: elasticsearch
    version: 7.16.3
    repository: https://helm.elastic.co

chart values.yaml as

elasticsearch:
  resources:
    limits:
      cpu: null

The null will persist through into the template

@mattfarina
Copy link
Collaborator Author

@jamoflaw You bring up a good point. Thanks for providing a good example. Here are my thoughts...

  1. "is that desired?" I don't know that it is desired. But, I was not trying to build the fully desired system for values handling. That system is built and in wide use. We won't want to break anything. Helm places a high priority on backwards compatibility. This PR makes enough changes I'm almost not comfortable and I will widely share this change, if it lands, to get people testing it.
  2. Older versions of Helm (I tested multiple) preserve the null you see in your examples.
  3. The goal of this PR was to make null delete a key everywhere consistently and to fix the import-values bugs. Those 2 problems were in the same code. Removing all null values was not part of this (and I didn't see a bug on it).

Before removing all null values we would need a lot of backwards compatibility testing. I think that should be a separate change.

Signed-off-by: Matt Farina <matt.farina@suse.com>
@mattfarina
Copy link
Collaborator Author

@gjenkins8 @sabre1041 can you please re-review

Copy link
Member

@gjenkins8 gjenkins8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM from me

Copy link
Member

@yxxhero yxxhero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mattfarina mattfarina merged commit 3433898 into helm:main Jul 26, 2023
@mattfarina mattfarina deleted the fix-merge-values-ugh branch July 26, 2023 13:30
@benjaminjb
Copy link

@mattfarina Have you tested unsetting subchart keys with a parent->child->grandchild setup? I've only started to experiment, so maybe I'm doing something wrong, but I'm not seeing keys being unset:

Parent-to-child unset works: helm template . --set parent.child.key=null --> child.key is null
Parent-to-grandchild unset doesn't work: helm template . --set parent.child.grandchild.key=null --> grandchild.key is the non-null default.

@alice-sawatzky
Copy link

@benjaminjb I can reproduce this, but there's an additional nuance that's even more problematic. This doesn't just not fix the issue, it also introduces a new bug. I've attached a test script below, it:

  • sets up a minimal parent, child, and grandchild chart
  • configures the child chart values.yaml to override a key in the grandchild chart values.yaml
  • configures the parent chart values.yaml to override a key in the child chart values.yaml

for clarity, in this comment I'll be using the words "parent", "child", and "grandchild" in the absolute sense, as the names of the charts, not as relative terms to a prior reference.

  • ./test.sh helm template .:
    • ✔️ grandchild chart value is correctly overridden by value from child chart's values.yaml
    • ✔️ child chart value is correctly overridden by the parent chart's values.yaml
  • ./test.sh helm template --set child.key=null .:
    • ✔️ grandchild chart value is correctly overridden by the child chart's values.yaml
    • ❌ child chart value is not unset (as @benjaminjb observed)
    • ❗ child chart value is reverted to its own values.yaml file's value, despite being overridden by the parent chart's values.yaml
  • ./test.sh helm template --set child.grandchild.key=null:
    • ✔️ child chart value is correctly overridden by value from parent chart's values,yaml
    • ❌ grandchild chart value is not unset (as @benjaminjb observed)
    • ❗ grandchild chart value is reverted to its own values.yaml file's value, despite being overridden by the parent chart's values.yaml
#!/bin/bash
# Usage: ./test.sh <helm command>
set -eou pipefail

HELM="$1"
shift

TESTDIR="${TESTDIR:-"/tmp/helmtest"}"

function chartYaml {
    echo -e "apiVersion: v2\nname: $1\nversion: 0.1.0"
}

function makeChart {
    NAME="$(basename "$1")"
    mkdir -p "$1/templates" "$1/charts"
    touch "$1/templates/placeholder.txt"
    touch "$1/values.yaml"
    chartYaml "$NAME" > "$1/Chart.yaml"
}

PARENT_DIR="$TESTDIR/parent"
CHILD_DIR="$PARENT_DIR/charts/child"
GRANDCHILD_DIR="$CHILD_DIR/charts/grandchild"
rm -rf "$PARENT_DIR"
# Parent Chart Stetup
makeChart "$PARENT_DIR"
echo -e "# Parent Chart's view of values:\n{{ toYaml .Values }}" > "$PARENT_DIR/templates/testcase.yaml"
cat <<EOF > "$PARENT_DIR/values.yaml"
key: "Value for parent chart, from parent chart values.yaml"
child:
  key: "Value for child chart, overridden from parent chart values.yaml"
EOF

# Child Chart Setup
makeChart "$CHILD_DIR"
echo -e "# Child Chart's view of values:\n{{ toYaml .Values }}" > "$CHILD_DIR/templates/testcase.yaml"
cat <<EOF > "$CHILD_DIR/values.yaml"
key: "Value for childChart, from childChart values.yaml"
grandchild:
  key: "Value for grandchild chart, overridden from child chart values.yaml"
EOF

# Granchild Chart Setup
makeChart "$GRANDCHILD_DIR"
echo -e "# Grandchild Chart's view of values:\n{{ toYaml .Values }}" > "$GRANDCHILD_DIR/templates/testcase.yaml"
cat <<EOF > "$GRANDCHILD_DIR/values.yaml"
key: "Value for grandchild chart, from grandchild values.yaml"
EOF

set -x; cd "$PARENT_DIR" && "$HELM" template "$@"

@alice-sawatzky
Copy link

@mattfarina should I move my comment to a new issue? For my use case this is a serious regression

@Laurens-W
Copy link

Adding to what @alice-sawatzky wrote:
A work around that was known to me was to explicitly pass a values file: helm template . -f values.yaml
This no longer works as of 3.13.0 and now seems to behave the same as helm template . did pre 3.13

So from my tests:
3.12.3
helm template . : doesn't handle null values correctly
helm template . -f values.yaml : does handle null values correctly

3.13.0
helm template . : does handle null values correctly
helm template . -f values.yaml : doesn't handle null values correctly

@zegerius
Copy link
Contributor

zegerius commented Oct 2, 2023

The fix introduced together with my colleague @ankitabhopatkar13 in the above referenced #9940 is now reverted and broke our charts. I don't think it's wise to change these rather complex things and add it as an (unreferenced!) footnote in a release.

For reference, this is now (again) broken: https://github.com/ankitabhopatkar13/helm-values-issue. Very curious if I am misinterpreting this.

@mattfarina

@rehevkor5
Copy link

I am still seeing this issue in 3.15.2. Setting a value to null has no effect, the subchart default still takes priority even though it shouldn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
10 participants