mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-05 21:14:56 +00:00
Merge pull request #6635 from 27149chen/skip-subresource
skip subresource in resource discovery
This commit is contained in:
1
changelogs/unreleased/6635-27149chen
Normal file
1
changelogs/unreleased/6635-27149chen
Normal file
@@ -0,0 +1 @@
|
||||
Fixes #6636, skip subresource in resource discovery
|
||||
@@ -18,6 +18,7 @@ package discovery
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -170,7 +171,7 @@ func (h *helper) Refresh() error {
|
||||
}
|
||||
|
||||
h.resources = discovery.FilteredBy(
|
||||
discovery.ResourcePredicateFunc(filterByVerbs),
|
||||
And(filterByVerbs, skipSubresource),
|
||||
serverResources,
|
||||
)
|
||||
|
||||
@@ -240,10 +241,34 @@ func refreshServerGroupsAndResources(discoveryClient serverResourcesInterface, l
|
||||
return serverGroups, serverResources, err
|
||||
}
|
||||
|
||||
// And returns a composite predicate that implements a logical AND of the predicates passed to it.
|
||||
func And(predicates ...discovery.ResourcePredicateFunc) discovery.ResourcePredicate {
|
||||
return and{predicates}
|
||||
}
|
||||
|
||||
type and struct {
|
||||
predicates []discovery.ResourcePredicateFunc
|
||||
}
|
||||
|
||||
func (a and) Match(groupVersion string, r *metav1.APIResource) bool {
|
||||
for _, p := range a.predicates {
|
||||
if !p(groupVersion, r) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func filterByVerbs(groupVersion string, r *metav1.APIResource) bool {
|
||||
return discovery.SupportsAllVerbs{Verbs: []string{"list", "create", "get", "delete"}}.Match(groupVersion, r)
|
||||
}
|
||||
|
||||
func skipSubresource(_ string, r *metav1.APIResource) bool {
|
||||
// if we have a slash, then this is a subresource and we shouldn't include it.
|
||||
return !strings.Contains(r.Name, "/")
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
Reference in New Issue
Block a user