Skip to content

Commit e685076

Browse files
authored
Merge pull request helm#31772 from matheuscscp/revert-12581
Revert "Consider GroupVersionKind when matching resources"
2 parents 75880fa + 787b61c commit e685076

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

pkg/kube/resource.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@ func (r ResourceList) Intersect(rs ResourceList) ResourceList {
7979
return r.Filter(rs.Contains)
8080
}
8181

82-
// isMatchingInfo returns true if infos match on Name and GroupVersionKind.
82+
// isMatchingInfo returns true if infos match on Name, Namespace, Group and Kind.
83+
//
84+
// IMPORTANT: Version is intentionally excluded from the comparison. Resources
85+
// served by the same CRD at different API versions (e.g. v2beta1 vs v2beta2)
86+
// share the same underlying storage in the Kubernetes API server. Comparing
87+
// the full GroupVersionKind causes Difference() to treat a version change as
88+
// a resource removal + addition, which makes Helm delete the resource it just
89+
// created during upgrades. See https://github.com/helm/helm/issues/31768
8390
func isMatchingInfo(a, b *resource.Info) bool {
84-
return a.Name == b.Name && a.Namespace == b.Namespace && a.Mapping.GroupVersionKind == b.Mapping.GroupVersionKind
91+
return a.Name == b.Name && a.Namespace == b.Namespace && a.Mapping.GroupVersionKind.GroupKind() == b.Mapping.GroupVersionKind.GroupKind()
8592
}

pkg/kube/resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func TestIsMatchingInfo(t *testing.T) {
7272

7373
gvkDiffVersion := schema.GroupVersionKind{Group: "group1", Version: "diff", Kind: "pod"}
7474
resourceInfoDiffVersion := resource.Info{Name: "name1", Namespace: "namespace1", Mapping: &meta.RESTMapping{GroupVersionKind: gvkDiffVersion}}
75-
if isMatchingInfo(&resourceInfo, &resourceInfoDiffVersion) {
76-
t.Error("expected resources not equal")
75+
if !isMatchingInfo(&resourceInfo, &resourceInfoDiffVersion) {
76+
t.Error("expected resources with different versions but same group and kind to be equal")
7777
}
7878

7979
gvkDiffKind := schema.GroupVersionKind{Group: "group1", Version: "version1", Kind: "deployment"}

0 commit comments

Comments
 (0)