Skip to content

Commit bce10e5

Browse files
Show partial results when fetching of api resources fails (#44)
Show partial results when fetching of api resources fails
2 parents 8fa7944 + 30c7f62 commit bce10e5

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

cmd/root.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,16 @@ func Execute() error {
8686
func init() {
8787
cobra.OnInitialize(initConfig)
8888

89-
rootCmd.PersistentFlags().StringVar(&ketallOptions.CfgFile, "config", "", "config file (default is $HOME/.kube/ketall.yaml)")
90-
rootCmd.PersistentFlags().StringVarP(&v, "verbosity", "v", constants.DefaultLogLevel.String(), "Log level (debug, info, warn, error, fatal, panic)")
91-
92-
rootCmd.Flags().BoolVar(&ketallOptions.UseCache, constants.FlagUseCache, false, "use cached list of server resources")
93-
rootCmd.Flags().StringVar(&ketallOptions.Scope, constants.FlagScope, "", "only resources with scope cluster|namespace")
94-
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)")
89+
rootCmd.PersistentFlags().StringVar(&ketallOptions.CfgFile, "config", "", "Config file (default \"$HOME/.kube/ketall.yaml)\"")
90+
rootCmd.PersistentFlags().StringVarP(&v, "verbosity", "v", constants.DefaultLogLevel.String(), "Log level (debug, info, warn, error, fatal, panic).")
91+
92+
rootCmd.Flags().BoolVar(&ketallOptions.UseCache, constants.FlagUseCache, false, "Use cached list of server resources.")
93+
rootCmd.Flags().BoolVar(&ketallOptions.AllowIncomplete, constants.FlagAllowIncomplete, true, "Show partial results when fetching of API resources fails.")
94+
rootCmd.Flags().StringVar(&ketallOptions.Scope, constants.FlagScope, "", "Only resources with scope cluster|namespace.")
95+
rootCmd.Flags().StringVar(&ketallOptions.Since, constants.FlagSince, "", "Only resources younger than given age.")
96+
rootCmd.Flags().StringVarP(&ketallOptions.Selector, constants.FlagSelector, "l", "", "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2).")
9697
rootCmd.Flags().StringVar(&ketallOptions.FieldSelector, constants.FlagFieldSelector, "", "Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The common field queries for all types are metadata.name and metadata.namespace.")
97-
rootCmd.Flags().StringSliceVar(&ketallOptions.Exclusions, constants.FlagExclude, []string{"events"}, "filter by resource name (plural form or short name)")
98+
rootCmd.Flags().StringSliceVar(&ketallOptions.Exclusions, constants.FlagExclude, []string{"events"}, "Filter by resource name (plural form or short name).")
9899

99100
ketallOptions.GenericCliFlags.AddFlags(rootCmd.Flags())
100101
ketallOptions.PrintFlags.AddFlags(rootCmd)

doc/USAGE.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ kubectl get-all
1616
- `--exclude` will filter out the given resources (either plural names `componentstatuses` or short form `cs`). Defaults to `events` because those are rarely useful.
1717
- ...and many standard `kubectl` options. Have a look at `kubectl get-all --help` for a full list of supported flags.
1818
- `--use-cache` will consider the http cache to determine the server resources to look at. Disabled by default.
19+
- `--allow-incomplete` will show partial results when fetching the list of API resources fails. Enabled by default.
1920
- `--verbosity` set the log level (one of debug, info, warn, error, fatal, panic).
2021

2122
**Hint**: If you do not have access to all resources, bulk fetching needs to be disabled. You can speed things up by explicitly excluding all resources which you may not access.

internal/client/client.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ func fetchAvailableGroupResources(cache bool, scope string, flags *genericcliopt
9494

9595
resources, err := client.ServerPreferredResources()
9696
if err != nil {
97-
return nil, errors.Wrap(err, "get preferred resources")
97+
if resources == nil || !viper.GetBool(constants.FlagAllowIncomplete) {
98+
return nil, errors.Wrap(err, "get preferred resources")
99+
}
100+
logrus.Warnf("Could not fetch complete list of API resources, results will be incomplete: %s", err)
98101
}
99102

100103
var grs []groupResource

internal/constants/constants.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import "github.com/sirupsen/logrus"
2121
const (
2222
DefaultLogLevel = logrus.WarnLevel
2323

24-
FlagExclude = "exclude"
25-
FlagNamespace = "namespace"
26-
FlagScope = "only-scope"
27-
FlagSince = "since"
28-
FlagUseCache = "use-cache"
29-
FlagSelector = "selector"
30-
FlagFieldSelector = "field-selector"
24+
FlagExclude = "exclude"
25+
FlagNamespace = "namespace"
26+
FlagScope = "only-scope"
27+
FlagSince = "since"
28+
FlagUseCache = "use-cache"
29+
FlagAllowIncomplete = "allow-incomplete"
30+
FlagSelector = "selector"
31+
FlagFieldSelector = "field-selector"
3132
)

internal/options/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type KetallOptions struct {
3131
GenericCliFlags *genericclioptions.ConfigFlags
3232
PrintFlags KAPrintFlags
3333
UseCache bool
34+
AllowIncomplete bool
3435
Scope string
3536
Since string
3637
Selector string

0 commit comments

Comments
 (0)