@@ -19,13 +19,15 @@ import (
1919 "fmt"
2020 "os"
2121
22+ "github.com/prometheus/common/version"
2223 "github.com/spf13/pflag"
2324 "sigs.k8s.io/controller-tools/pkg/genall"
2425 "sigs.k8s.io/controller-tools/pkg/genall/help"
2526 prettyhelp "sigs.k8s.io/controller-tools/pkg/genall/help/pretty"
2627 "sigs.k8s.io/controller-tools/pkg/loader"
2728 "sigs.k8s.io/controller-tools/pkg/markers"
2829
30+ "k8s.io/klog/v2"
2931 "k8s.io/kube-state-metrics/v2/exp/metric-gen/generator"
3032)
3133
3941)
4042
4143func main () {
42- var whichMarkersFlag bool
44+ var whichMarkersFlag , versionFlag bool
4345
44- pflag .CommandLine .BoolVarP (& whichMarkersFlag , "which-markers" , "w" , false , "print out all markers available with the requested generators" )
46+ pflag .CommandLine .BoolVarP (& whichMarkersFlag , "which-markers" , "w" , false , "Print out all markers available with the requested generators." )
47+ pflag .CommandLine .BoolVarP (& versionFlag , "version" , "v" , false , "Print verison information." )
4548
4649 pflag .Usage = func () {
4750 fmt .Fprintf (os .Stderr , "Usage of %s:\n \n " , os .Args [0 ])
@@ -53,6 +56,11 @@ func main() {
5356
5457 pflag .Parse ()
5558
59+ if versionFlag {
60+ fmt .Printf ("%s\n " , version .Print ("metric-gen" ))
61+ klog .FlushAndExit (klog .ExitFlushTimeout , 0 )
62+ }
63+
5664 // Register the metric generator itself as marker so genall.FromOptions is able to initialize the runtime properly.
5765 // This also registers the markers inside the optionsRegistry so its available to print the marker docs.
5866 metricGenerator := generator.CustomResourceConfigGenerator {}
0 commit comments