From d63de52458eb75a09641ed5dadbc6553ff78bc6e Mon Sep 17 00:00:00 2001 From: z0mbix Date: Tue, 16 Nov 2021 15:30:33 +0000 Subject: [PATCH 1/3] Add -v to output version number --- .goreleaser.yml | 3 ++- cmd/kubeconform/main.go | 2 ++ pkg/config/config.go | 8 ++++++++ pkg/config/config_test.go | 13 +++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 67481b9..140481a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -20,6 +20,7 @@ builds: - -a ldflags: - -extldflags "-static" + - -X github.com/yannh/kubeconform/pkg/config.version={{.Tag}} archives: - format: tar.gz @@ -58,4 +59,4 @@ changelog: sort: asc filters: exclude: - - '^test:' \ No newline at end of file + - '^test:' diff --git a/cmd/kubeconform/main.go b/cmd/kubeconform/main.go index 6ac0e7e..dd4d813 100644 --- a/cmd/kubeconform/main.go +++ b/cmd/kubeconform/main.go @@ -48,6 +48,8 @@ func realMain() int { cfg, out, err := config.FromFlags(os.Args[0], os.Args[1:]) if cfg.Help { return 0 + } else if cfg.Version { + return 0 } else if out != "" { fmt.Println(out) return 1 diff --git a/pkg/config/config.go b/pkg/config/config.go index d165f07..8bc3599 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -8,6 +8,8 @@ import ( "strings" ) +var version = "development" + type Config struct { Cache string CPUProfileFile string @@ -26,6 +28,7 @@ type Config struct { IgnoreMissingSchemas bool IgnoreFilenamePatterns []string Help bool + Version bool } type arrayParam []string @@ -79,6 +82,7 @@ func FromFlags(progName string, args []string) (Config, string, error) { flags.StringVar(&c.Cache, "cache", "", "cache schemas downloaded via HTTP to this folder") flags.StringVar(&c.CPUProfileFile, "cpu-prof", "", "debug - log CPU profiling to file") flags.BoolVar(&c.Help, "h", false, "show help information") + flags.BoolVar(&c.Version, "v", false, "show version information") flags.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... [FILE OR FOLDER]...\n", progName) @@ -98,5 +102,9 @@ func FromFlags(progName string, args []string) (Config, string, error) { flags.Usage() } + if c.Version { + fmt.Println(version) + } + return c, buf.String(), err } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 78f1ff6..038aa3d 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -70,6 +70,19 @@ func TestFromFlags(t *testing.T) { RejectKinds: map[string]struct{}{}, }, }, + { + []string{"-v"}, + Config{ + Files: []string{}, + Version: true, + KubernetesVersion: "master", + NumberOfWorkers: 4, + OutputFormat: "text", + SchemaLocations: nil, + SkipKinds: map[string]struct{}{}, + RejectKinds: map[string]struct{}{}, + }, + }, { []string{"-skip", "a,b,c"}, Config{ From 941047114211eb536d6d782a278fee47c99453a3 Mon Sep 17 00:00:00 2001 From: z0mbix Date: Tue, 16 Nov 2021 15:33:04 +0000 Subject: [PATCH 2/3] Update README --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index 1067d3d..e9a026f 100644 --- a/Readme.md +++ b/Readme.md @@ -90,6 +90,7 @@ Usage: ./bin/kubeconform [OPTION]... [FILE OR FOLDER]... disallow additional properties not in schema -summary print a summary at the end (ignored for junit output) + -v show version information -verbose print results for all resources (ignored for tap and junit output) ``` From c3e6205f15901457b54ef35bc5f823ab23a2756f Mon Sep 17 00:00:00 2001 From: z0mbix Date: Tue, 16 Nov 2021 17:19:54 +0000 Subject: [PATCH 3/3] Move version to main package --- .goreleaser.yml | 2 +- cmd/kubeconform/main.go | 3 +++ pkg/config/config.go | 6 ------ 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 140481a..00b3f59 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -20,7 +20,7 @@ builds: - -a ldflags: - -extldflags "-static" - - -X github.com/yannh/kubeconform/pkg/config.version={{.Tag}} + - -X main.version={{.Tag}} archives: - format: tar.gz diff --git a/cmd/kubeconform/main.go b/cmd/kubeconform/main.go index dd4d813..af0cbc6 100644 --- a/cmd/kubeconform/main.go +++ b/cmd/kubeconform/main.go @@ -15,6 +15,8 @@ import ( "github.com/yannh/kubeconform/pkg/validator" ) +var version = "development" + func processResults(cancel context.CancelFunc, o output.Output, validationResults <-chan validator.Result, exitOnError bool) <-chan bool { success := true result := make(chan bool) @@ -49,6 +51,7 @@ func realMain() int { if cfg.Help { return 0 } else if cfg.Version { + fmt.Println(version) return 0 } else if out != "" { fmt.Println(out) diff --git a/pkg/config/config.go b/pkg/config/config.go index 8bc3599..22cb76d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -8,8 +8,6 @@ import ( "strings" ) -var version = "development" - type Config struct { Cache string CPUProfileFile string @@ -102,9 +100,5 @@ func FromFlags(progName string, args []string) (Config, string, error) { flags.Usage() } - if c.Version { - fmt.Println(version) - } - return c, buf.String(), err }