Skip to content

Commit

Permalink
Expand required resource verbs with get and delete
Browse files Browse the repository at this point in the history
Some resources use GET for listing, which resulted in errors.

Signed-off-by: Nolan Brubaker <[email protected]>
  • Loading branch information
Nolan Brubaker committed May 14, 2018
1 parent 5bfd4f6 commit 6b59fde
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/discovery/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ func (h *helper) Refresh() error {
}

h.resources = discovery.FilteredBy(
discovery.ResourcePredicateFunc(func(groupVersion string, r *metav1.APIResource) bool {
return discovery.SupportsAllVerbs{Verbs: []string{"list", "create"}}.Match(groupVersion, r)
}),
discovery.ResourcePredicateFunc(filterByVerbs),
preferredResources,
)

Expand All @@ -132,6 +130,10 @@ func (h *helper) Refresh() error {
return nil
}

func filterByVerbs(groupVersion string, r *metav1.APIResource) bool {
return discovery.SupportsAllVerbs{Verbs: []string{"list", "create", "get", "delete"}}.Match(groupVersion, r)
}

// sortResources sources resources by moving extensions to the end of the slice. The order of all
// the other resources is preserved.
func sortResources(resources []*metav1.APIResourceList) {
Expand Down
41 changes: 41 additions & 0 deletions pkg/discovery/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,44 @@ func TestSortResources(t *testing.T) {
})
}
}

func TestFilteringByVerbs(t *testing.T) {
tests := []struct {
name string
groupVersion string
res *metav1.APIResource
expected bool
}{
{
name: "resource that supports list, create, get, delete",
groupVersion: "v1",
res: &metav1.APIResource{
Verbs: metav1.Verbs{"list", "create", "get", "delete"},
},
expected: true,
},
{
name: "resource that supports list and create",
groupVersion: "v1",
res: &metav1.APIResource{
Verbs: metav1.Verbs{"list", "create"},
},
expected: false,
},
{
name: "resource that supports get and delete",
groupVersion: "v1",
res: &metav1.APIResource{
Verbs: metav1.Verbs{"get", "delete"},
},
expected: false,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
out := filterByVerbs(test.groupVersion, test.res)
assert.Equal(t, test.expected, out)
})
}
}

0 comments on commit 6b59fde

Please sign in to comment.