Skip to content

Commit da2aaca

Browse files
author
Cornelius Weig
committed
Add option to control server resource caching (off by default)
1 parent dff278f commit da2aaca

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

cmd/root.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ ketall retrieves all resources which allow to be fetched. This complements the
3939
usual "kubectl get all" command, which does not list cluster-level resources.
4040
4141
For example:
42-
List all resources
42+
Get all resources
4343
$ ketall
4444
45-
List all resources and do not use cached results
46-
$ ketall --no-cache
45+
Get all resources and use list of cached server resources
46+
$ ketall --cache
4747
`
4848
)
4949

@@ -68,6 +68,8 @@ func init() {
6868
rootCmd.PersistentFlags().StringVar(&ketallOptions.CfgFile, "config", "", "config file (default is $HOME/.kube/ketall.yaml)")
6969
rootCmd.PersistentFlags().StringVarP(&v, "verbosity", "v", pkg.DefaultLogLevel.String(), "Log level (debug, info, warn, error, fatal, panic)")
7070

71+
rootCmd.Flags().BoolVar(&ketallOptions.UseCache, "cache", false, "use cached list of server resources")
72+
7173
ketallOptions.GenericCliFlags.AddFlags(rootCmd.Flags())
7274
ketallOptions.PrintFlags.AddFlags(rootCmd)
7375

pkg/client/client.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type groupResource struct {
2424
func GetAllServerResources(ketallOptions *options.KetallOptions) (runtime.Object, error) {
2525
flags := ketallOptions.GenericCliFlags
2626

27-
resNames, err := FetchAvailableResourceNames(flags)
27+
resNames, err := FetchAvailableResourceNames(ketallOptions.UseCache, flags)
2828
if err != nil {
2929
return nil, errors.Wrap(err, "fetch available resources")
3030
}
@@ -53,20 +53,17 @@ func GetAllServerResources(ketallOptions *options.KetallOptions) (runtime.Object
5353
return response.Object()
5454
}
5555

56-
// TODO add flag to disable cache: --no-cache
5756
// TODO add flag to list only namespaced resources: --scope-namespace
5857
// TODO add flag to list only cluster resources: --scope-cluster
59-
func FetchAvailableResourceNames(flags *genericclioptions.ConfigFlags) ([]string, error) {
58+
func FetchAvailableResourceNames(cache bool, flags *genericclioptions.ConfigFlags) ([]string, error) {
6059
client, err := flags.ToDiscoveryClient()
6160
if err != nil {
6261
return nil, errors.Wrap(err, "discovery client")
6362
}
6463

65-
// TODO add option to disable caching
66-
/*if !o.Cached {
67-
// Always request fresh data from the server
68-
discoveryclient.Invalidate()
69-
}*/
64+
if !cache {
65+
client.Invalidate()
66+
}
7067

7168
resources, err := client.ServerPreferredResources()
7269
if err != nil {

pkg/options/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type KetallOptions struct {
1010
CfgFile string
1111
GenericCliFlags *genericclioptions.ConfigFlags
1212
PrintFlags KAPrintFlags
13+
UseCache bool
1314
}
1415

1516
func NewCmdOptions() *KetallOptions {

0 commit comments

Comments
 (0)