From 5ba8d14b8603a13686ce505e0fde5e8aa567f9ab Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Mon, 7 Aug 2023 11:56:58 +0300 Subject: [PATCH] topology-updater: make -version always runnable Make it possible to run -version in an environment whithout the NODE_ADDRESS environment variable set. --- cmd/nfd-topology-updater/main.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/nfd-topology-updater/main.go b/cmd/nfd-topology-updater/main.go index f187f4df47..bedc375198 100644 --- a/cmd/nfd-topology-updater/main.go +++ b/cmd/nfd-topology-updater/main.go @@ -43,15 +43,8 @@ var DefaultKubeletStateDir = path.Join(string(hostpath.VarDir), "lib", "kubelet" func main() { flags := flag.NewFlagSet(ProgramName, flag.ExitOnError) - printVersion := flags.Bool("version", false, "Print version and exit.") - args, resourcemonitorArgs := parseArgs(flags, os.Args[1:]...) - if *printVersion { - fmt.Println(ProgramName, version.Get()) - os.Exit(0) - } - // Assert that the version is known if version.Undefined() { klog.InfoS("version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run.") @@ -75,6 +68,7 @@ func main() { func parseArgs(flags *flag.FlagSet, osArgs ...string) (*topology.Args, *resourcemonitor.Args) { args, resourcemonitorArgs := initFlags(flags) + printVersion := flags.Bool("version", false, "Print version and exit.") _ = flags.Parse(osArgs) if len(flags.Args()) > 0 { @@ -83,6 +77,11 @@ func parseArgs(flags *flag.FlagSet, osArgs ...string) (*topology.Args, *resource os.Exit(2) } + if *printVersion { + fmt.Println(ProgramName, version.Get()) + os.Exit(0) + } + if len(resourcemonitorArgs.KubeletConfigURI) == 0 { nodeAddress := os.Getenv("NODE_ADDRESS") if len(nodeAddress) == 0 {