diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index 7e1f16290..d2c5af728 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 1466ce299..3097e72ef 100644 --- a/internal/discovery/discovery_test.go +++ b/internal/discovery/discovery_test.go @@ -163,6 +163,74 @@ 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, + }, + { + desc: "variable version, no matching cache entry", + gvkmaps: &CRDiscoverer{ + Map: map[string]map[string][]kindPlural{ + "testgroup-1": { + "v1alpha1": { + kindPlural{ + Kind: "TestObject1", + Plural: "testobjects1", + }, + }, + }, + }, + }, + gvk: schema.GroupVersionKind{Group: "testgroup", Version: "*", Kind: "TestObject1"}, + want: nil, + }, + { + desc: "variable kind, no matching cache entry", + gvkmaps: &CRDiscoverer{ + Map: map[string]map[string][]kindPlural{ + "testgroup": { + "v1alpha1": { + kindPlural{ + Kind: "TestObject1", + Plural: "testobjects1", + }, + }, + }, + }, + }, + gvk: schema.GroupVersionKind{Group: "testgroup", Version: "v1", Kind: "*"}, + want: nil, + }, + { + desc: "variable version and kind, no matching cache entry", + gvkmaps: &CRDiscoverer{ + Map: map[string]map[string][]kindPlural{ + "testgroup-1": { + "v1alpha1": { + kindPlural{ + Kind: "TestObject1", + Plural: "testobjects1", + }, + }, + }, + }, + }, + gvk: schema.GroupVersionKind{Group: "testgroup", Version: "*", Kind: "*"}, + want: nil, + }, } for _, tc := range testcases { got, err := tc.gvkmaps.ResolveGVKToGVKPs(tc.gvk)