From 8c964b9dafdc5ddb04494efbb374e437632d2b36 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Fri, 20 Mar 2020 07:21:43 +0200 Subject: [PATCH] version: allow undefined version Just print a warning instead of exiting with an error if no version has been specified at build-time. This was pointless and just annoying at development time when doing builds with go directly. --- cmd/nfd-master/main.go | 4 ++-- cmd/nfd-worker/main.go | 4 ++-- pkg/version/version.go | 12 ++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/nfd-master/main.go b/cmd/nfd-master/main.go index 161f3d83c..cfe4aa0ef 100644 --- a/cmd/nfd-master/main.go +++ b/cmd/nfd-master/main.go @@ -35,8 +35,8 @@ const ( func main() { // Assert that the version is known - if version.Get() == "undefined" { - log.Fatalf("version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run.") + if version.Undefined() { + log.Print("WARNING: version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run.") } // Parse command-line arguments. diff --git a/cmd/nfd-worker/main.go b/cmd/nfd-worker/main.go index b11b2f4c9..b015bf8d6 100644 --- a/cmd/nfd-worker/main.go +++ b/cmd/nfd-worker/main.go @@ -34,8 +34,8 @@ const ( func main() { // Assert that the version is known - if version.Get() == "undefined" { - log.Fatalf("version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run.") + if version.Undefined() { + log.Printf("WARNING: version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run.") } // Parse command-line arguments. diff --git a/pkg/version/version.go b/pkg/version/version.go index 0520c4cc4..51ded9851 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -16,9 +16,17 @@ limitations under the License. package version -// Must not be const, supposed to be set using ldflags at build time -var version = "undefined" +const undefinedVersion string = "undefined" +// Must not be const, supposed to be set using ldflags at build time +var version = undefinedVersion + +// Get returns the version as a string func Get() string { return version } + +// Undefined returns if version is at it's default value +func Undefined() bool { + return version == undefinedVersion +}