@@ -22,6 +22,7 @@ import (
2222 "errors"
2323 "fmt"
2424 "io"
25+ "path/filepath"
2526 "sort"
2627 "strings"
2728
@@ -46,6 +47,8 @@ type VerifyGCOptions struct {
4647 Output string
4748 Stderr io.Writer
4849 Stdout io.Writer
50+ Namespace string
51+ Groups []string
4952}
5053
5154// Validate ensures the specified options are valid
@@ -106,6 +109,20 @@ func (v *VerifyGCOptions) Run() error {
106109 return err
107110 }
108111 gcResources := discovery .FilteredBy (discovery.SupportsAllVerbs {Verbs : []string {"list" , "get" , "delete" }}, preferredResources )
112+ if len (v .Groups ) > 0 {
113+ gcResources = discovery .FilteredBy (discovery .ResourcePredicateFunc (func (groupVersion string , r * metav1.APIResource ) bool {
114+ for _ , g := range v .Groups {
115+ match , _ := filepath .Match (g , groupVersion )
116+ if match {
117+ return true
118+ }
119+ }
120+ if klog .V (2 ).Enabled () {
121+ fmt .Fprintf (v .Stderr , "skipping: %s\n " , groupVersion )
122+ }
123+ return false
124+ }), gcResources )
125+ }
109126 gvrMap , err := discovery .GroupVersionResources (gcResources )
110127 if err != nil {
111128 return err
@@ -138,7 +155,7 @@ func (v *VerifyGCOptions) Run() error {
138155 fmt .Fprintf (v .Stderr , "fetching %v, %v\n " , gvr .GroupVersion ().String (), gvr .Resource )
139156 }
140157 pager .New (func (ctx context.Context , opts metav1.ListOptions ) (runtime.Object , error ) {
141- list , err := v .MetadataClient .Resource (gvr ).List (ctx , opts )
158+ list , err := v .MetadataClient .Resource (gvr ).Namespace ( v . Namespace ). List (ctx , opts )
142159 if err != nil {
143160 warningCount ++
144161 fmt .Fprintf (v .Stderr , "warning: could not list %v: %v\n " , gvr , err .Error ())
0 commit comments