Skip to content

Consider full GroupVersionKind when matching resources#12581

Merged
scottrigby merged 2 commits intohelm:mainfrom
Nordix:considerAllGroupVersionKind
Jun 3, 2025
Merged

Consider full GroupVersionKind when matching resources#12581
scottrigby merged 2 commits intohelm:mainfrom
Nordix:considerAllGroupVersionKind

Conversation

@MichaelMorrisEst
Copy link
Contributor

What this PR does / why we need it:
This change shall take Group, Version and Kind from GroupVersionKind into consideration instead of the current behavior of only considering the Kind when matching resources.
This is needed as resources with different apiVersion are being considered the same.

Closes: #12578

Special notes for your reviewer:

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/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Nov 20, 2023
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.

Funnily enough, back in 2017, it was determined that Helm should ignore the API Group/Version when comparing objects: #2976

From a through read of that PR (and related issues), I didn't find any reason that made sense to me to make that change (in fact #2976 (comment) IMHO was correct, then and today)

I think this PR makes the logic more correct. But given Helm has been like this for a (very) long time, it is probably worth proceeding with (a lot of) caution (my 2c).

@jnonino
Copy link

jnonino commented Nov 21, 2023

Hi, the comment #2976 (comment makes sense, the issue is that when you upgrade a chart that have resources with API group and/or version changes the old resource is not removed but it is not managed by Helm anymore.

The old resource is left orphaned in Kubernetes, we found that when we upgraded Traefik chart and they changed the API group from traefik.containo.us to traefik.io, at some point we started seeing weird errors and they were caused by orphaned IngressRoutes that were still active with the old API group.

So, I get that if the API group/version is different Helm mus recognise them as different resources, but if a resource was being managed by Helm and in an upgrade operation a resource is not there anymore because it was replaced with a new resource with new API group/version, Helm should do something with the old resource it was managing, right now it just leave it orphaned as it was never part of the chart.

@MichaelMorrisEst
Copy link
Contributor Author

I believe the solution of considering resources to be different if the apiVersion is different is consistent with the behaviour of 'kubectl apply', 'kubectl diff'
The change proposed results in the old resource that was being left orphaned, now being deleted

@jnonino
Copy link

jnonino commented Nov 21, 2023

For our use case that would be the expected behaviour, the old resource being deleted rather that left orphaned. You can always know if something like this is going to happen by running the commands with dry run and analyse the result.

@gjenkins8 gjenkins8 added the v4.x Issues and Pull Requests related to the major version v4 label Jan 17, 2024
@gjenkins8
Copy link
Member

gjenkins8 commented Jan 17, 2024

I labeled this as Helm v4, so at least it won't get forgotten. IMHO it probably should be merged into Helm v3 as a bug fix, but that needs maintainer attention/thought

@gjenkins8
Copy link
Member

@MichaelMorrisEst -- could you please e.g. rebase to kick CI off (again). We should merge this for Helm 4

Copy link
Member

@scottrigby scottrigby left a comment

Choose a reason for hiding this comment

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

@MichaelMorrisEst -- could you please e.g. rebase to kick CI off (again). We should merge this for Helm 4

Overall I agree comparing GroupVersionKind is a good idea now. #13583 added group since this PR, so you can remove that too after the rebase.

Can you also update/write a test to check these conditions? This test function hasn't been updated in many years:

func TestResourceList(t *testing.T) {

@scottrigby scottrigby added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 13, 2025
This change shall take Group, Version and Kind from GroupVersionKind
into consideration instead of the current behavior of only considering
the Kind

Closes: helm#12578

Signed-off-by: MichaelMorris <michael.morris@est.tech>
Signed-off-by: MichaelMorris <michael.morris@est.tech>
@MichaelMorrisEst MichaelMorrisEst force-pushed the considerAllGroupVersionKind branch from ab248d3 to 1460ebd Compare May 13, 2025 22:14
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 13, 2025
@MichaelMorrisEst
Copy link
Contributor Author

Hi @gjenkins8 , @scottrigby
Rebase done and test case added

@gjenkins8 gjenkins8 added Has One Approval This PR has one approval. It still needs a second approval to be merged. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 14, 2025
@gjenkins8
Copy link
Member

nice, thanks!

Copy link
Member

@scottrigby scottrigby left a comment

Choose a reason for hiding this comment

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

LGTM

@scottrigby scottrigby removed the Has One Approval This PR has one approval. It still needs a second approval to be merged. label Jun 3, 2025
@scottrigby scottrigby merged commit de745ea into helm:main Jun 3, 2025
5 checks passed
@scottrigby scottrigby added the bug Categorizes issue or PR as related to a bug. label Jul 1, 2025
@matheuscscp
Copy link
Contributor

Funnily enough, back in 2017, it was determined that Helm should ignore the API Group/Version when comparing objects: #2976

From a through read of that PR (and related issues), I didn't find any reason that made sense to me to make that change (in fact #2976 (comment) IMHO was correct, then and today)

I think this PR makes the logic more correct. But given Helm has been like this for a (very) long time, it is probably worth proceeding with (a lot of) caution (my 2c).

Well, this has now grave consequences in Helm 4. The right choice was indeed not to take the API version in consideration all along. Because of this PR, Helm now deletes the "old" resource (old API version) and keeps waiting forever on the "new" resource (new API version), which never happens, because the object was the same in etcd all along. We need to revert this PR ASAP

This PR is actually the root cause for this issue: #31768

@MichaelMorrisEst @gjenkins8 @scottrigby @stefanprodan

@scottrigby
Copy link
Member

@matheuscscp I was wrong earlier in my review of this PR. Glad we discussed in today's dev meeting and you got it sorted in #31772. Thanks!

@scottrigby
Copy link
Member

@matheuscscp I was wrong earlier in my review of this PR. Glad we discussed in today's dev meeting and you got it sorted in #31772. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. v4.x Issues and Pull Requests related to the major version v4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Helm does not remove old resource when switching to a new apiVersion

5 participants