Skip to content

Commit

Permalink
Fix CR cache for GVK all specified case
Browse files Browse the repository at this point in the history
  • Loading branch information
chelseychen committed Dec 5, 2024
1 parent 32e7727 commit 5631601
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
23 changes: 10 additions & 13 deletions internal/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 17 additions & 0 deletions internal/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5631601

Please sign in to comment.