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 2, 2024
1 parent 32e7727 commit d8fb76d
Show file tree
Hide file tree
Showing 2 changed files with 78 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
68 changes: 68 additions & 0 deletions internal/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d8fb76d

Please sign in to comment.