Skip to content
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

Fix bug checksum chart values will not consider about order of key-value #676

Conversation

longquan0104
Copy link
Contributor

Fixing this issue #675
Helm upgrade always happens without any changes

@longquan0104 longquan0104 force-pushed the bugfix/checksum-chart-values-order-on-key-value branch from eb8f0ce to 45c9623 Compare April 20, 2023 09:55
@longquan0104
Copy link
Contributor Author

Hello @stefanprodan,
Please help me to look at this.
Thank you.

@longquan0104
Copy link
Contributor Author

Hello @hiddeco,
Please review this. Thank you.

Makefile Outdated
cd api; rm -f go.sum; go mod tidy -compat=1.20
rm -f go.sum; go mod tidy -compat=1.20
cd api; rm -f go.sum; go mod tidy -compat=1.19
rm -f go.sum; go mod tidy -compat=1.19
Copy link
Member

Choose a reason for hiding this comment

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

This should not be changed.

case string:
return v
default:
return fmt.Sprintf("%v", v)
Copy link
Member

Choose a reason for hiding this comment

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

The result of this would be that everything becomes a string type. This may have other undesirable effects, e.g. the change of an integer type to a string (or vice-versa) causing an upgrade to not be triggered.

// Marshal
s, err = goyaml.Marshal(msValues)
if err != nil {
panic(err)
Copy link
Member

Choose a reason for hiding this comment

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

Panics based on arbitrary input with little guarantee it may only occur due to programmatic errors (and not based on user-input) make me feel uncomfortable.

@longquan0104 longquan0104 force-pushed the bugfix/checksum-chart-values-order-on-key-value branch 2 times, most recently from fd1e042 to 984f4a9 Compare May 2, 2023 18:13
@longquan0104 longquan0104 force-pushed the bugfix/checksum-chart-values-order-on-key-value branch from 984f4a9 to bf7a308 Compare May 2, 2023 18:14

goyaml "gopkg.in/yaml.v2"
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for not using v3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the v2 which is being used in "sigs.k8s.io/yaml" and in the v2, they support MapSlice structure which is easy to handle to me.

@hiddeco
Copy link
Member

hiddeco commented May 3, 2023

Have been thinking some more about this, and while I do think that it would theoretically be better to order keys to prevent unnecessary upgrades. The current way this is structured would cause any existing HelmRelease to upgrade when the values are ordered, even if there hasn't been a change.

Given this, I think this needs changing in such a way that this doesn't happen. For example, by calculating the checksum without ordering first, and then only calculate the version with ordering if this causes a mismatch (or when an upgrade is triggered, to then take note of the ordered value).

@longquan0104
Copy link
Contributor Author

So you mean that the key still should be ordered but there should not break the running resources and force them to upgrade?

@hiddeco
Copy link
Member

hiddeco commented May 3, 2023

  1. Calculate checksum of ordered and unordered values.
  2. If the checksum as recorded in the Status matches one of those values, there isn't a change.
  3. If there is a change, take note of the ordered values checksum.

This would allow us to eventually stop calculating the unordered checksum, but without triggering an upgrade right now (after upgrading to patched controller with this change).

@longquan0104
Copy link
Contributor Author

I updated the code, please let me know if there are anything need to be done @hiddeco

@hiddeco
Copy link
Member

hiddeco commented May 8, 2023

You do not seem to have allowed for us maintainers to push changes to your branch, but please see a332735 for further review reference.

func cleanUpInterfaceMap(in map[interface{}]interface{}) map[string]interface{} {
result := make(map[string]interface{})
for k, v := range in {
result[fmt.Sprintf("%T.%v", k, k)] = cleanUpMapValue(v)
Copy link
Member

Choose a reason for hiding this comment

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

Why are we taking note of the type here? It should take the checksum of an ordered map, without making any modifications to the map itself besides ordering.

@longquan0104
Copy link
Contributor Author

Hello @hiddeco, I migrate this to PR #684 which the maintainer can make commits to

@hiddeco hiddeco closed this May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants