Skip to content

Commit 790bded

Browse files
author
Cornelius Weig
committed
Add selector flag
1 parent f3ec898 commit 790bded

4 files changed

Lines changed: 10 additions & 1 deletion

File tree

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func init() {
9292
rootCmd.Flags().BoolVar(&ketallOptions.UseCache, constants.FlagUseCache, false, "use cached list of server resources")
9393
rootCmd.Flags().StringVar(&ketallOptions.Scope, constants.FlagScope, "", "only resources with scope cluster|namespace")
9494
rootCmd.Flags().StringVar(&ketallOptions.Since, constants.FlagSince, "", "only resources younger than given age")
95+
rootCmd.Flags().StringVarP(&ketallOptions.Selector, constants.FlagSelector, "l", "", "selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
9596
rootCmd.Flags().StringSliceVar(&ketallOptions.Exclusions, constants.FlagExclude, []string{"events"}, "filter by resource name (plural form or short name)")
9697

9798
ketallOptions.GenericCliFlags.AddFlags(rootCmd.Flags())

pkg/ketall/client/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,21 @@ func fetchResourcesBulk(flags resource.RESTClientGetter, resourceTypes ...groupR
143143

144144
request := resource.NewBuilder(flags).
145145
Unstructured().
146-
SelectAllParam(true).
147146
ResourceTypes(resourceNames...).
148147
Latest()
148+
149149
if ns := viper.GetString(constants.FlagNamespace); ns != "" {
150150
request.NamespaceParam(ns)
151151
} else {
152152
request.AllNamespaces(true)
153153
}
154154

155+
if selector := viper.GetString(constants.FlagSelector); selector != "" {
156+
request.LabelSelectorParam(selector)
157+
} else {
158+
request.SelectAllParam(true)
159+
}
160+
155161
return request.Do().Object()
156162
}
157163

pkg/ketall/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ const (
2626
FlagScope = "only-scope"
2727
FlagSince = "since"
2828
FlagUseCache = "use-cache"
29+
FlagSelector = "selector"
2930
)

pkg/ketall/options/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type KetallOptions struct {
3333
UseCache bool
3434
Scope string
3535
Since string
36+
Selector string
3637
Exclusions []string
3738
Streams *genericclioptions.IOStreams
3839
}

0 commit comments

Comments
 (0)