From 56316019cdd617be560ef2ec164b7bfc16f91a6f Mon Sep 17 00:00:00 2001 From: Chelsey Chen Date: Thu, 5 Dec 2024 03:23:04 +0000 Subject: [PATCH] Fix CR cache for GVK all specified case --- internal/discovery/discovery.go | 23 ++++++++++------------- internal/discovery/discovery_test.go | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index 7e1f162909..d2c5af7288 100644 --- a/internal/discovery/discovery.go +++ b/internal/discovery/discovery.go @@ -127,23 +127,20 @@ func (r *CRDiscoverer) ResolveGVKToGVKPs(gvk schema.GroupVersionKind) (resolvedG hasKind := k != "" && k != "*" // No need to resolve, return. if hasVersion && hasKind { - var p string for _, el := range r.Map[g][v] { if el.Kind == k { - p = el.Plural - break + return []groupVersionKindPlural{ + { + GroupVersionKind: schema.GroupVersionKind{ + Group: g, + Version: v, + Kind: k, + }, + Plural: el.Plural, + }, + }, nil } } - return []groupVersionKindPlural{ - { - GroupVersionKind: schema.GroupVersionKind{ - Group: g, - Version: v, - Kind: k, - }, - Plural: p, - }, - }, nil } if hasVersion && !hasKind { kinds := r.Map[g][v] diff --git a/internal/discovery/discovery_test.go b/internal/discovery/discovery_test.go index 1466ce2995..9ebf631bec 100644 --- a/internal/discovery/discovery_test.go +++ b/internal/discovery/discovery_test.go @@ -163,6 +163,23 @@ func TestGVKMapsResolveGVK(t *testing.T) { }, }, }, + { + desc: "fixed version and kind, no matching cache entry", + gvkmaps: &CRDiscoverer{ + Map: map[string]map[string][]kindPlural{ + "testgroup": { + "v1": { + kindPlural{ + Kind: "TestObject2", + Plural: "testobjects2", + }, + }, + }, + }, + }, + gvk: schema.GroupVersionKind{Group: "testgroup", Version: "v1", Kind: "TestObject1"}, + want: nil, + }, } for _, tc := range testcases { got, err := tc.gvkmaps.ResolveGVKToGVKPs(tc.gvk)