Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ func main() {
output := ""
burst := 100
qps := 25
var groups []string
pflag.StringVarP(&output, "output", "o", output, "Output format. May be '' or 'json'.")
pflag.IntVar(&burst, "burst", burst, "API requests allowed per second (burst).")
pflag.IntVar(&qps, "qps", qps, "API requests allowed per second (steady state). Set to -1 to disable rate limiter.")
pflag.StringSliceVarP(&groups, "groups", "g", nil, "list of API groups")

// set up logging
klog.InitFlags(nil)
Expand Down Expand Up @@ -104,6 +106,8 @@ func main() {
Output: output,
Stderr: os.Stderr,
Stdout: os.Stdout,
Namespace: *configFlags.Namespace,
Groups: groups,
}
checkErr(opts.Validate())
checkErr(opts.Run())
Expand Down
19 changes: 18 additions & 1 deletion pkg/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"io"
"path/filepath"
"sort"
"strings"

Expand All @@ -46,6 +47,8 @@ type VerifyGCOptions struct {
Output string
Stderr io.Writer
Stdout io.Writer
Namespace string
Groups []string
}

// Validate ensures the specified options are valid
Expand Down Expand Up @@ -106,6 +109,20 @@ func (v *VerifyGCOptions) Run() error {
return err
}
gcResources := discovery.FilteredBy(discovery.SupportsAllVerbs{Verbs: []string{"list", "get", "delete"}}, preferredResources)
if len(v.Groups) > 0 {
gcResources = discovery.FilteredBy(discovery.ResourcePredicateFunc(func(groupVersion string, r *metav1.APIResource) bool {
for _, g := range v.Groups {
match, _ := filepath.Match(g, groupVersion)
if match {
return true
}
}
if klog.V(2).Enabled() {
fmt.Fprintf(v.Stderr, "skipping: %s\n", groupVersion)
}
return false
}), gcResources)
}
gvrMap, err := discovery.GroupVersionResources(gcResources)
if err != nil {
return err
Expand Down Expand Up @@ -138,7 +155,7 @@ func (v *VerifyGCOptions) Run() error {
fmt.Fprintf(v.Stderr, "fetching %v, %v\n", gvr.GroupVersion().String(), gvr.Resource)
}
pager.New(func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
list, err := v.MetadataClient.Resource(gvr).List(ctx, opts)
list, err := v.MetadataClient.Resource(gvr).Namespace(v.Namespace).List(ctx, opts)
if err != nil {
warningCount++
fmt.Fprintf(v.Stderr, "warning: could not list %v: %v\n", gvr, err.Error())
Expand Down