Skip to content

Commit dd934c9

Browse files
committed
version/verflag: make program name variable
Instead of hard-coding `Kubernetes` in the output generated when executing a binary using the `version/verflag` feature using `--version`, use a variable `programName` which can be overwritten using the `-X` linker flag, e.g.: ``` go build -ldflags "-X k8s.io/component-base/version/verflag.programName=my-tool" ... ``` This allows to use the package in non-Kubernetes applications. Signed-off-by: Nicolas Trangez <[email protected]> See: kubernetes#90138
1 parent 250884c commit dd934c9

File tree

1 file changed

+2
-1
lines changed
  • staging/src/k8s.io/component-base/version/verflag

1 file changed

+2
-1
lines changed

staging/src/k8s.io/component-base/version/verflag/verflag.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const versionFlagName = "version"
8989

9090
var (
9191
versionFlag = Version(versionFlagName, VersionFalse, "Print version information and quit")
92+
programName = "Kubernetes"
9293
)
9394

9495
// AddFlags registers this package's flags on arbitrary FlagSets, such that they point to the
@@ -104,7 +105,7 @@ func PrintAndExitIfRequested() {
104105
fmt.Printf("%#v\n", version.Get())
105106
os.Exit(0)
106107
} else if *versionFlag == VersionTrue {
107-
fmt.Printf("Kubernetes %s\n", version.Get())
108+
fmt.Printf("%s %s\n", programName, version.Get())
108109
os.Exit(0)
109110
}
110111
}

0 commit comments

Comments
 (0)