From 689a1f5f4fd60cdb8a285d39875b0328923a5cc6 Mon Sep 17 00:00:00 2001 From: Benjamin Jorand Date: Wed, 18 Jan 2023 21:21:11 +0100 Subject: [PATCH 1/4] fix --version flag --- internal/wrapper.go | 6 ++++ pkg/version/version.go | 64 ------------------------------------------ 2 files changed, 6 insertions(+), 64 deletions(-) delete mode 100644 pkg/version/version.go diff --git a/internal/wrapper.go b/internal/wrapper.go index b83f74651a..88dde17004 100644 --- a/internal/wrapper.go +++ b/internal/wrapper.go @@ -19,11 +19,13 @@ package internal import ( "context" "errors" + "fmt" "os" "path/filepath" "time" "github.com/fsnotify/fsnotify" + "github.com/prometheus/common/version" "github.com/spf13/viper" "gopkg.in/yaml.v3" "k8s.io/klog/v2" @@ -34,6 +36,10 @@ import ( // RunKubeStateMetricsWrapper is a wrapper around KSM, delegated to the root command. func RunKubeStateMetricsWrapper(opts *options.Options) { + if opts.Version { + fmt.Printf("%s\n", version.Print("kube-state-metrics")) + klog.FlushAndExit(klog.ExitFlushTimeout, 0) + } KSMRunOrDie := func(ctx context.Context) { if err := app.RunKubeStateMetricsWrapper(ctx, opts); err != nil { diff --git a/pkg/version/version.go b/pkg/version/version.go deleted file mode 100644 index b6c42b07c3..0000000000 --- a/pkg/version/version.go +++ /dev/null @@ -1,64 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package version - -import ( - "fmt" - "os" - "path/filepath" - "runtime" -) - -var ( - // Release returns the release version - Release = "UNKNOWN" - // Commit returns the short sha from git - Commit = "UNKNOWN" - // BuildDate is the build date - BuildDate = "" -) - -// Version is the current version of kube-state-metrics. -// Update this whenever making a new release. -// The version is of the format Major.Minor.Patch -// -// Increment major number for new feature additions and behavioral changes. -// Increment minor number for bug fixes and performance enhancements. -// Increment patch number for critical fixes to existing releases. -type Version struct { - GitCommit string - BuildDate string - Release string - GoVersion string - Compiler string - Platform string -} - -func (v Version) String() string { - return fmt.Sprintf("%s/%s (%s/%s) kube-state-metrics/%s", - filepath.Base(os.Args[0]), v.Release, - runtime.GOOS, runtime.GOARCH, v.GitCommit) -} - -// GetVersion returns the kube-state-metrics version. -func GetVersion() Version { - return Version{ - GitCommit: Commit, - BuildDate: BuildDate, - Release: Release, - GoVersion: runtime.Version(), - Compiler: runtime.Compiler, - Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), - } -} From ca7bc253b033383ea2ca0cb7780b5ff5da646769 Mon Sep 17 00:00:00 2001 From: Benjamin Jorand Date: Mon, 23 Jan 2023 13:24:01 +0100 Subject: [PATCH 2/4] clean broken --version flag --- internal/wrapper.go | 7 ------- pkg/options/options.go | 2 -- 2 files changed, 9 deletions(-) diff --git a/internal/wrapper.go b/internal/wrapper.go index 88dde17004..1a63fde534 100644 --- a/internal/wrapper.go +++ b/internal/wrapper.go @@ -19,13 +19,11 @@ package internal import ( "context" "errors" - "fmt" "os" "path/filepath" "time" "github.com/fsnotify/fsnotify" - "github.com/prometheus/common/version" "github.com/spf13/viper" "gopkg.in/yaml.v3" "k8s.io/klog/v2" @@ -36,11 +34,6 @@ import ( // RunKubeStateMetricsWrapper is a wrapper around KSM, delegated to the root command. func RunKubeStateMetricsWrapper(opts *options.Options) { - if opts.Version { - fmt.Printf("%s\n", version.Print("kube-state-metrics")) - klog.FlushAndExit(klog.ExitFlushTimeout, 0) - } - KSMRunOrDie := func(ctx context.Context) { if err := app.RunKubeStateMetricsWrapper(ctx, opts); err != nil { klog.ErrorS(err, "Failed to run kube-state-metrics") diff --git a/pkg/options/options.go b/pkg/options/options.go index bb26ef21ff..0f55785e96 100644 --- a/pkg/options/options.go +++ b/pkg/options/options.go @@ -55,7 +55,6 @@ type Options struct { TelemetryPort int `yaml:"telemetry_port"` TotalShards int `yaml:"total_shards"` UseAPIServerCache bool `yaml:"use_api_server_cache"` - Version bool `yaml:"version"` Config string @@ -123,7 +122,6 @@ func (o *Options) AddFlags(cmd *cobra.Command) { o.cmd.Flags().BoolVar(&o.EnableGZIPEncoding, "enable-gzip-encoding", false, "Gzip responses when requested by clients via 'Accept-Encoding: gzip' header.") o.cmd.Flags().BoolVarP(&o.Help, "help", "h", false, "Print Help text") o.cmd.Flags().BoolVarP(&o.UseAPIServerCache, "use-apiserver-cache", "", false, "Sets resourceVersion=0 for ListWatch requests, using cached resources from the apiserver instead of an etcd quorum read.") - o.cmd.Flags().BoolVarP(&o.Version, "version", "", false, "kube-state-metrics build version information") o.cmd.Flags().Int32Var(&o.Shard, "shard", int32(0), "The instances shard nominal (zero indexed) within the total number of shards. (default 0)") o.cmd.Flags().IntVar(&o.Port, "port", 8080, `Port to expose metrics on.`) o.cmd.Flags().IntVar(&o.TelemetryPort, "telemetry-port", 8081, `Port to expose kube-state-metrics self metrics on.`) From d72db6921cd42679e4de4fed4ad8f038dc842fc6 Mon Sep 17 00:00:00 2001 From: Benjamin Jorand Date: Mon, 23 Jan 2023 13:25:07 +0100 Subject: [PATCH 3/4] remove unwanted change --- internal/wrapper.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/wrapper.go b/internal/wrapper.go index 1a63fde534..b83f74651a 100644 --- a/internal/wrapper.go +++ b/internal/wrapper.go @@ -34,6 +34,7 @@ import ( // RunKubeStateMetricsWrapper is a wrapper around KSM, delegated to the root command. func RunKubeStateMetricsWrapper(opts *options.Options) { + KSMRunOrDie := func(ctx context.Context) { if err := app.RunKubeStateMetricsWrapper(ctx, opts); err != nil { klog.ErrorS(err, "Failed to run kube-state-metrics") From 57a196b56c64984a1cea8a56647f4e10385f9b50 Mon Sep 17 00:00:00 2001 From: Benjamin Jorand Date: Mon, 23 Jan 2023 13:51:29 +0100 Subject: [PATCH 4/4] update doc --- docs/cli-arguments.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/cli-arguments.md b/docs/cli-arguments.md index 67190c66b5..0b812011b7 100644 --- a/docs/cli-arguments.md +++ b/docs/cli-arguments.md @@ -75,7 +75,6 @@ Flags: --total-shards int The total number of shards. Sharding is disabled when total shards is set to 1. (default 1) --use-apiserver-cache Sets resourceVersion=0 for ListWatch requests, using cached resources from the apiserver instead of an etcd quorum read. -v, --v Level number for the log level verbosity - --version kube-state-metrics build version information --vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging Use "kube-state-metrics [command] --help" for more information about a command.