You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
At the moment, if you make any manual changes to resources (not via helm) helm diff will not reflect these changes.
I suggest that the output should reflect the desired vs actual state of the resources, just like running terraform plan.
Reacted by Maxim Samoilov, Tommy McNeely, Ilya Shaisultanov, Artem Yarmoliuk, Braden Wright, Max Williams, Chad Ostler, mbeckDWRE, Daniel Lytkin, dudicoco and 41 more
Reacted by Luis Davim, Mohsen, Clement Chevalier and Max Williams
That would be nice but its not straightforward. The problem is that Kubernetes controllers/operators add a lot of fields when working with the resources. For example the common metadata section alone is modified a lot. Also a lot of fields in the Spec section of almost all resources are filled with default values (e.g. spec.revisionHistoryLimit of Deployments)
So its not easy to create a meaningful diff. You would always see a lot of noise that would hide the actual changes.
what about using kubectl-diff behind the scenes after rendering the templates?
Not sure I follow you. What do you mean by that? Against what would you diff the rendered templates? The actual state from the cluster is littered with dozens of default values that are not in the rendered templates. This would in almost all cases create a huge diff that has no meaning.
I tested this using kubectl diff and was able to get a simple diff rendering. Here's what I did...
Installed 6 helm charts using helmfile.
Manually patched the image field on 1 of the deployments of 1 helm chart.
Output the manifest templates from our helmfile using helmfile template > test.yaml.
Ran kubectl diff -f test.yaml
The results were to show only 2 differences:
An increment of the generation field of the deployment.
The image field change as expected.
Seems to me that this suggestion could be a viable solution.
(btw - thank you for this package!)
Reacted by Maxim Samoilov, dudicoco, Ilya Shaisultanov, Thomas O'Donnell, Tommy McNeely, Braden Wright, Krish, R-omk, red8888, Dmitriy Vatsuro and 2 more
For what its worth, I tried what @corradomatt mentioned above, but had pages of output, likely due to everything not being in one namespace. Apparently, to do this I would have to separate the comparison by namespace (somehow?).
# using helmfile
helmfile -e myenv template | kubectl diff -f - | bat -l diff -
# using helm directly
helm template releaseName chart | kubectl diff -f - | bat -l diff -
You could easily apply your namespace flags to these commands and/or supply a selector to helmfile to limit the output. This also uses the bat utility (which is amazing btw).
I would just like to also mention the importance of having this feature 🙂
Before, with Helm2, showing a diff excluding manual changes in the cluster was fine because Helm2 would also ignore these. But now, with Helm3 and the new 3-way merge, we can't really be sure of what will be applied to the cluster when using this plugin. If the upgrade is going to revert some manual changes then this plugin won't show them.
Reacted by Ben Mathews, Chad Ostler, Hagen Kuehn, Nick Maltsev, Tommy McNeely, Kyrylo Lebediev, Denys Suievalov, R-omk and VonUniGE
To support helm/helm#7649, it'd be handy if the "actual state" diff side in this feature could be one not provided by Helm. Obviously, in such a case, only objects created by the Helm release would be considered, although it might be handy to explicitly flag objects that exist but are missing the appropriate annotations (although they'd show up in the diff anyway).
Same issue is impacting helmsman (and i believe helmfile) which used to use helm-diff plugin to decide if a "helm upgrade" will trigger any changes or not. And if helmsman doesnt see any changes to be applied it just skips the "helm upgrade" step. But in case of any out-of-helm changes are involved, it becomes blind due to the fact that helm-diff calculates the diff against "latest deployed version of a release". You can see some more context in mkubaczyk/helmsman#487 (comment)
Here the issue is not how helmsman or helmfile uses helm-diff, its actually the users' expectation when they are using the helm-diff plugin. Most of the cases they do care about "which actual changes to be applied", rather than "what would be the change if there has been no manual changes in the cluster". But either may be confusing for the helm-diff users, so maybe introducing a new flag and providing both functionality is the best path forward.
I've just looked into helm diff command usage a bit.
helm diff upgrade is designed in a way to imitate helm upgrade, most of the time i just add a diff keyword in between to see if helm upgrade will introduce changes or not. I know this is not really how the helm-diff is actually designed, but in most cases this will be the expectation.
So here is a sample case that helm diff upgrade command is clearly reporting a misleading output if we just forget the fact that helm-diff checks only against "latest deployed version of a release" rather than the "actual state". The current behaviour of helm-diff was aligned with helm 2's behaviour, but in helm 3 they implemented a 3-way-merge and not it works more like "kubectl apply". I believe "helm diff upgrade" subcommand should follow this design change in helm upstream.
Prepare a test environment
cd /tmp
kubectl create ns test
helm create test
helm install test ./test
kubectl delete deploy test
Now, here is what helm diff reports (it clearly reports as if no action will be taken by helm upgrade, true for helm 2, not for helm 3):
/tmp $ helm diff upgrade test ./test
/tmp $
And now, lets see if that's true (helm diff reported me a misleading update result):
/tmp $ helm upgrade test ./test --debug
upgrade.go:121: [debug] preparing upgrade for test
upgrade.go:129: [debug] performing update for test
upgrade.go:308: [debug] creating upgraded release for test
client.go:173: [debug] checking 3 resources for changes
client.go:436: [debug] Looks like there are no changes for ServiceAccount "test"
client.go:436: [debug] Looks like there are no changes for Service "test"
client.go:194: [debug] Created a new Deployment called "test" in bekir-test -----------> Helm actually created the missing Deployment
upgrade.go:136: [debug] updating status for upgraded release for test
...
@max-rocket-internet I think that's intended behavior / that's how three-way merge works. Annotations will be merged by keys among the current state, the latest manifest stored in the helm release, and the desired manifests rendered.
That means helm won't revert changes on test-annotation as long as you don't have test-annotation in your helm template.
If you think something isn't working perhaps it is best to open a separate issue with your scenario. I find folks are sometimes confused with how Helm three-way merge works as in the comment above. #176 (comment)
If Helm 3 is not going to revert your manual change on apply (which often it will not), it shouldn't show in the output of helm diff. At least if working as I understand was intended.
Are you sure your manual change is something Helm is going to revert if applied?
Activity
databus23 commentedon Jan 10, 2020
That would be nice but its not straightforward. The problem is that Kubernetes controllers/operators add a lot of fields when working with the resources. For example the common
metadatasection alone is modified a lot. Also a lot of fields in theSpecsection of almost all resources are filled with default values (e.g.spec.revisionHistoryLimitof Deployments)So its not easy to create a meaningful diff. You would always see a lot of noise that would hide the actual changes.
dudicoco commentedon Jan 20, 2020
@databus23 what about using kubectl-diff behind the scenes after rendering the templates?
databus23 commentedon Jan 20, 2020
Not sure I follow you. What do you mean by that? Against what would you diff the rendered templates? The actual state from the cluster is littered with dozens of default values that are not in the rendered templates. This would in almost all cases create a huge diff that has no meaning.
dudicoco commentedon Jan 20, 2020
What I mean is that when running helm-diff the following will happen:
kubectl diff package.yamlExample of output which includes the diff from the actual state of the clustered:
corradomatt commentedon Jan 29, 2020
I tested this using
kubectl diffand was able to get a simple diff rendering. Here's what I did...imagefield on 1 of the deployments of 1 helm chart.helmfile template > test.yaml.kubectl diff -f test.yamlThe results were to show only 2 differences:
generationfield of the deployment.Seems to me that this suggestion could be a viable solution.
(btw - thank you for this package!)
TJM commentedon Mar 2, 2020
helm/helm-www#521 <-- I filed this in the wrong place, guess you already know about this :)
TJM commentedon Mar 2, 2020
For what its worth, I tried what @corradomatt mentioned above, but had pages of output, likely due to everything not being in one namespace. Apparently, to do this I would have to separate the comparison by namespace (somehow?).
corradomatt commentedon Mar 3, 2020
I've been using the following to run diffs now...
You could easily apply your namespace flags to these commands and/or supply a selector to helmfile to limit the output. This also uses the bat utility (which is amazing btw).
sstarcher commentedon Mar 3, 2020
On this note now that helm 3 is doing a 3 way merge could we not look at the code they are using for the merge.
max-rocket-internet commentedon Apr 22, 2020
I would just like to also mention the importance of having this feature 🙂
Before, with Helm2, showing a diff excluding manual changes in the cluster was fine because Helm2 would also ignore these. But now, with Helm3 and the new 3-way merge, we can't really be sure of what will be applied to the cluster when using this plugin. If the upgrade is going to revert some manual changes then this plugin won't show them.
sstarcher commentedon Apr 22, 2020
Agreed this is much more important now. It is also needed to help debug why a 3 way merges in helm maybe not acting as we expect.
TBBle commentedon Jun 15, 2020
To support helm/helm#7649, it'd be handy if the "actual state" diff side in this feature could be one not provided by Helm. Obviously, in such a case, only objects created by the Helm release would be considered, although it might be handy to explicitly flag objects that exist but are missing the appropriate annotations (although they'd show up in the diff anyway).
max-rocket-internet commentedon Aug 17, 2020
@mumoshu any thoughts on this issue? Is it hard to fix? Or impossible?
bergerx commentedon Sep 8, 2020
Same issue is impacting helmsman (and i believe helmfile) which used to use helm-diff plugin to decide if a "helm upgrade" will trigger any changes or not. And if helmsman doesnt see any changes to be applied it just skips the "helm upgrade" step. But in case of any out-of-helm changes are involved, it becomes blind due to the fact that helm-diff calculates the diff against "latest deployed version of a release". You can see some more context in mkubaczyk/helmsman#487 (comment)
Here the issue is not how helmsman or helmfile uses helm-diff, its actually the users' expectation when they are using the helm-diff plugin. Most of the cases they do care about "which actual changes to be applied", rather than "what would be the change if there has been no manual changes in the cluster". But either may be confusing for the helm-diff users, so maybe introducing a new flag and providing both functionality is the best path forward.
bergerx commentedon Sep 9, 2020
I've just looked into helm diff command usage a bit.
helm diff upgradeis designed in a way to imitatehelm upgrade, most of the time i just add adiffkeyword in between to see if helm upgrade will introduce changes or not. I know this is not really how the helm-diff is actually designed, but in most cases this will be the expectation.So here is a sample case that
helm diff upgradecommand is clearly reporting a misleading output if we just forget the fact that helm-diff checks only against "latest deployed version of a release" rather than the "actual state". The current behaviour of helm-diff was aligned with helm 2's behaviour, but in helm 3 they implemented a 3-way-merge and not it works more like "kubectl apply". I believe "helm diff upgrade" subcommand should follow this design change in helm upstream.Prepare a test environment
Now, here is what
helm diffreports (it clearly reports as if no action will be taken by helm upgrade, true for helm 2, not for helm 3):And now, lets see if that's true (helm diff reported me a misleading update result):
25 remaining items
colearendt commentedon Nov 9, 2021
Bump
bilenkis commentedon Dec 16, 2021
Please, any updates on this?
max-rocket-internet commentedon Jan 10, 2022
@mumoshu thanks for your work here.
I just have one question after testing with latest helm-diff release though: are annotations ignored?
I can install a random chart:
Make a manual change:
And helm-diff shows the change now 🎉
... - -config - /home/toxiproxy/proxies/config.json - image: shopify/toxiproxy:2.1.3 + image: shopify/toxiproxy:2.1.4 imagePullPolicy: IfNotPresent livenessProbe: failureThreshold: 2 ...But if I add a manual annotation:
It is not shown in the diff output 🤔
mumoshu commentedon Jan 10, 2022
@max-rocket-internet I think that's intended behavior / that's how three-way merge works. Annotations will be merged by keys among the current state, the latest manifest stored in the helm release, and the desired manifests rendered.
That means helm won't revert changes on
test-annotationas long as you don't havetest-annotationin your helm template.max-rocket-internet commentedon Jan 10, 2022
OK yes, you are right.
Thanks again @mumoshu 💖
jimbali commentedon Aug 23, 2022
Was there ever any actual practical solution or workaround to this?
chadlwilson commentedon Aug 23, 2022
@jimbali
--three-way-mergeinv3.3.0+of the plugin I believe? https://github.com/databus23/helm-diff#usagejimbali commentedon Aug 23, 2022
thanks @chadlwilson
jimbali commentedon Aug 23, 2022
Still doesn't seem to pick up manual changes for me though! 🤷♂️
chadlwilson commentedon Aug 23, 2022
If you think something isn't working perhaps it is best to open a separate issue with your scenario. I find folks are sometimes confused with how Helm three-way merge works as in the comment above. #176 (comment)
If Helm 3 is not going to revert your manual change on apply (which often it will not), it shouldn't show in the output of helm diff. At least if working as I understand was intended.
Are you sure your manual change is something Helm is going to revert if applied?
jimbali commentedon Aug 23, 2022
I'd have thought that it would do, as the liveness and readiness probes were deleted manually, and they are explicitly present in the chart.
chadlwilson commentedon Aug 23, 2022
Test it with Helm. I think you will find it will not reinstate such manual changes with Helm 3s default 3 way merge behavior.