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
{{ message }}
Repository navigation
--three-way-merge produces useless diff on meta.helm.sh annotations #326
Running diff upgrade --three-way-merge added via #304 on an unchanged release produces diffs on meta.helm.sh/release-name and meta.helm.sh/release-namespace. I guess this should be omitted from the diff as it's added automatically by helm AND running helm upgrade won't actually remove those annotations.
It's not game-breaking, but it's a bit of a wart. I guess we could explicitly strip those two annotations from objects fetched from the cluster. Although then if someone has included them in the chart templates by-hand (unlikely, but not impossible, nor invalid), I guess they'd show up in the merge again, as 'drift'.
So stripping them from all three sets of resources (source, current, target) is probably feasible, and doesn't immediately jump out with any downsides.
Worth noting, the app.kubernetes.io/managed-by: Helm label is handled the same way, but because it predates the auto-added metadata, it's present in most people's Helm templates, which is why you're not seeing it in this test-case.
So handling all three of these Helm-added metadata items in one fix is a good way to observe and validate both cases.
@TBBle Thank you so much for your feedback! I've enhanced helm-diff to ignore diff on meta.helm.sh annotations #331.
I didn't actually see any unnecessary diff on app.kubernetes.io/managed-by: Helm perhaps due to the chart I used for testing didn't have app.kubernetes.io/managed-by templates in it.
I'd definitely do the same care on the label as soon as I or anyone have seen the real instance of the problem.
I think you aren't seeing it in the envoy chart (assuming this is the same one you tested with) because it does include explicit app.kubernetes.io/managed-by: {{ .Release.Service }} in its envoy.labels named template, so ends up in all its generated manifests, and the code I linked becomes a no-op on that annotation.
If you removed that line from the template, the resulting objects from helm install or helm upgrade would be identical, but you'd see in helm-diff that it's no longer present in the generated manifests.
However, the documented Helm best practice is still to explicitly include that label in your template, which keeps back-compatiblity with charts that predate the newer meta.helm.sh annotations. That's also what helm create outputs, so any charts created from that flow will have this annotation in their templates.
I also ran helm template valheim-server valheim-k8s/valheim-k8s and helm get release valheim-server and saw there's no managed-by label in any resources in the outputs.
The diff was okay even if I reverted #331. This seems to imply that there's a slightly different edge-case than we've discussed so far.
With that and before #331, helm-diff + three-way-merge detected diff on the service only even though there are other resources like deployment and a configmap!
After rereading templates in the envoy chart, I realized that the service was the only resource that had non-empty annotations rendered by the template:
What I can guess from this example is that any template has non-empty annotations results in unintended diff on meta.helm.sh annotations only. On the other hand, non-empty labels in the template doesn't result in such diff, which is odd.
Huh, that is interesting. Clearly it's not as simple as I'd assumed, and since you didn't see the behaviour I expected, I'm making a faulty assumption somewhere. Thank you for confirming that.
This might be an aspect of the three-way merge logic, where if the annotations section is completely missing in the template, the patch logic doesn't even look inside it, as it won't touch it anyway, and so it's not seen by helm-diff.
But I'm still guessing here, so if it's doing the right thing with #331 applied, that's the best outcome. ^_^
For posterity's sake, we're going to remove deployment.kubernetes.io/revision annotation and metadata.generation as well from the diff. Please see issue #349 and PR #359 for more information.
Activity
TBBle commentedon Jan 9, 2022
It's not game-breaking, but it's a bit of a wart. I guess we could explicitly strip those two annotations from objects fetched from the cluster. Although then if someone has included them in the chart templates by-hand (unlikely, but not impossible, nor invalid), I guess they'd show up in the merge again, as 'drift'.
So stripping them from all three sets of resources (source, current, target) is probably feasible, and doesn't immediately jump out with any downsides.
Worth noting, the
app.kubernetes.io/managed-by: Helmlabel is handled the same way, but because it predates the auto-added metadata, it's present in most people's Helm templates, which is why you're not seeing it in this test-case.So handling all three of these Helm-added metadata items in one fix is a good way to observe and validate both cases.
Fix --three-way-merge to not show diff on meta.helm.sh annotations
mumoshu commentedon Jan 9, 2022
@TBBle Thank you so much for your feedback! I've enhanced helm-diff to ignore diff on meta.helm.sh annotations #331.
I didn't actually see any unnecessary diff on
app.kubernetes.io/managed-by: Helmperhaps due to the chart I used for testing didn't haveapp.kubernetes.io/managed-bytemplates in it.I'd definitely do the same care on the label as soon as I or anyone have seen the real instance of the problem.
Fix --three-way-merge to not show diff on meta.helm.sh annotations (#331
TBBle commentedon Jan 9, 2022
You're very welcome.
I think you aren't seeing it in the envoy chart (assuming this is the same one you tested with) because it does include explicit
app.kubernetes.io/managed-by: {{ .Release.Service }}in itsenvoy.labelsnamed template, so ends up in all its generated manifests, and the code I linked becomes a no-op on that annotation.If you removed that line from the template, the resulting objects from
helm installorhelm upgradewould be identical, but you'd see in helm-diff that it's no longer present in the generated manifests.However, the documented Helm best practice is still to explicitly include that label in your template, which keeps back-compatiblity with charts that predate the newer
meta.helm.shannotations. That's also whathelm createoutputs, so any charts created from that flow will have this annotation in their templates.This means you probably won't see charts in the wild that lack this annotation very often, but I have encountered a few, such as https://github.com/Addyvan/valheim-k8s/tree/main/chart. It's not incorrect to not have those standard annotations, just unusual.
mumoshu commentedon Jan 9, 2022
@TBBle I appreciate your detailed response very much! Good to know- so it was the opposite of what I was thinking.
FWIW, I tried running diff with the three-way-merge option against
valheim-k8sand surprisingly it didn't show diff on the managed-by label:I also ran
helm template valheim-server valheim-k8s/valheim-k8sandhelm get release valheim-serverand saw there's nomanaged-bylabel in any resources in the outputs.The diff was okay even if I reverted #331. This seems to imply that there's a slightly different edge-case than we've discussed so far.
mumoshu commentedon Jan 9, 2022
FWIW, the envoy chart I used when testing is https://github.com/helm/charts/blob/master/stable/envoy.
With that and before #331, helm-diff + three-way-merge detected diff on the service only even though there are other resources like deployment and a configmap!
After rereading templates in the envoy chart, I realized that the service was the only resource that had non-empty annotations rendered by the template:
where templates for the other resources lacked the whole
annotations:What I can guess from this example is that any template has non-empty annotations results in unintended diff on meta.helm.sh annotations only. On the other hand, non-empty labels in the template doesn't result in such diff, which is odd.
TBBle commentedon Jan 9, 2022
Huh, that is interesting. Clearly it's not as simple as I'd assumed, and since you didn't see the behaviour I expected, I'm making a faulty assumption somewhere. Thank you for confirming that.
This might be an aspect of the three-way merge logic, where if the
annotationssection is completely missing in the template, the patch logic doesn't even look inside it, as it won't touch it anyway, and so it's not seen by helm-diff.But I'm still guessing here, so if it's doing the right thing with #331 applied, that's the best outcome. ^_^
mumoshu commentedon Jan 23, 2022
For posterity's sake, we're going to remove
deployment.kubernetes.io/revisionannotation andmetadata.generationas well from the diff. Please see issue #349 and PR #359 for more information.