@@ -10,13 +10,18 @@ import (
1010 "unicode"
1111
1212 "github.com/doitintl/kube-no-trouble/pkg/judge"
13- "github.com/doitintl/kube-no-trouble/pkg/printer"
1413 "k8s.io/client-go/tools/clientcmd"
1514
1615 "github.com/rs/zerolog"
1716 flag "github.com/spf13/pflag"
1817)
1918
19+ const (
20+ JSON = "json"
21+ TEXT = "text"
22+ CSV = "csv"
23+ )
24+
2025type Config struct {
2126 AdditionalKinds []string
2227 AdditionalAnnotations []string
@@ -31,12 +36,18 @@ type Config struct {
3136 OutputFile string
3237 TargetVersion * judge.Version
3338 KubentVersion bool
39+ OptionalFlags * OptionalFlags
40+ }
41+
42+ type OptionalFlags struct {
43+ Labels bool
3444}
3545
3646func NewFromFlags () (* Config , error ) {
3747 config := Config {
3848 LogLevel : ZeroLogLevel (zerolog .InfoLevel ),
3949 TargetVersion : & judge.Version {},
50+ OptionalFlags : & OptionalFlags {},
4051 }
4152
4253 flag .StringSliceVarP (& config .AdditionalKinds , "additional-kind" , "a" , []string {}, "additional kinds of resources to report in Kind.version.group.com format" )
@@ -52,11 +63,12 @@ func NewFromFlags() (*Config, error) {
5263 flag .StringVarP (& config .OutputFile , "output-file" , "O" , "-" , "output file, use - for stdout" )
5364 flag .VarP (& config .LogLevel , "log-level" , "l" , "set log level (trace, debug, info, warn, error, fatal, panic, disabled)" )
5465 flag .VarP (config .TargetVersion , "target-version" , "t" , "target K8s version in SemVer format (autodetected by default)" )
66+ flag .BoolVar (& config .OptionalFlags .Labels , "labels" , false , "print resource labels" )
5567
5668 flag .Parse ()
5769
58- if _ , err := printer . ParsePrinter (config .Output ); err != nil {
59- return nil , fmt .Errorf ("failed to validate argument output: %w " , err )
70+ if ! isValidOutputFormat (config .Output ) {
71+ return nil , fmt .Errorf ("failed to validate argument output: %s " , config . Output )
6072 }
6173
6274 if err := validateOutputFile (config .OutputFile ); err != nil {
@@ -77,6 +89,17 @@ func NewFromFlags() (*Config, error) {
7789 return & config , nil
7890}
7991
92+ // Previuosly this was handled by a printer.go ParsePrinter function
93+ // but we need to avoid cycle imports in order to inject the additional flags
94+ func isValidOutputFormat (format string ) bool {
95+ switch format {
96+ case JSON , TEXT , CSV :
97+ return true
98+ default :
99+ return false
100+ }
101+ }
102+
80103// validateAdditionalResources check that all resources are provided in full form
81104// resource.version.group.com. E.g. managedcertificate.v1beta1.networking.gke.io
82105func validateAdditionalResources (resources []string ) error {
0 commit comments