From e761ab01b4c479d02259b6ee59be786088d6cc83 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Thu, 17 Feb 2022 12:51:02 -0500 Subject: [PATCH 1/2] Remove non used version folder Signed-off-by: Carlos Eduardo Arango Gutierrez --- version/version.go | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 version/version.go diff --git a/version/version.go b/version/version.go deleted file mode 100644 index 980a59c6..00000000 --- a/version/version.go +++ /dev/null @@ -1,22 +0,0 @@ -/* -Copyright 2020 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 - -var ( - // Version tracks the NFD operator release - Version = "0.0.1" -) From a06710a8a29530d80f8ed132e0ff2fbf8878f95b Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Thu, 17 Feb 2022 12:58:31 -0500 Subject: [PATCH 2/2] Version add a proper way to bake in version into the bin Signed-off-by: Carlos Eduardo Arango Gutierrez --- Makefile | 3 ++- main.go | 2 +- pkg/version/version.go | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 pkg/version/version.go diff --git a/Makefile b/Makefile index 67818f02..c5706d6f 100644 --- a/Makefile +++ b/Makefile @@ -84,6 +84,7 @@ GOOS=linux PACKAGE=sigs.k8s.io/node-feature-discovery-operator MAIN_PACKAGE=main.go BIN=node-feature-discovery-operator +LDFLAGS = -ldflags "-s -w -X sigs.k8s.io/node-feature-discovery-operator/pkg/version.version=$(VERSION)" PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) @@ -100,7 +101,7 @@ go_mod: # Build binary build: go_mod - @GOOS=$(GOOS) GO111MODULE=on CGO_ENABLED=0 $(GO_CMD) build -o $(BIN) $(MAIN_PACKAGE) + @GOOS=$(GOOS) GO111MODULE=on CGO_ENABLED=0 $(GO_CMD) build -o $(BIN) $(LDFLAGS) $(MAIN_PACKAGE) # Run against the configured Kubernetes cluster in ~/.kube/config run: generate fmt vet manifests diff --git a/main.go b/main.go index 02016d63..71b9c02d 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,6 @@ import ( "os" _ "k8s.io/client-go/plugin/pkg/client/auth" - "k8s.io/component-base/version" "k8s.io/klog/v2" "k8s.io/apimachinery/pkg/runtime" @@ -34,6 +33,7 @@ import ( nfdkubernetesiov1 "sigs.k8s.io/node-feature-discovery-operator/api/v1" "sigs.k8s.io/node-feature-discovery-operator/controllers" "sigs.k8s.io/node-feature-discovery-operator/pkg/utils" + "sigs.k8s.io/node-feature-discovery-operator/pkg/version" // +kubebuilder:scaffold:imports ) diff --git a/pkg/version/version.go b/pkg/version/version.go new file mode 100644 index 00000000..cd3e86dc --- /dev/null +++ b/pkg/version/version.go @@ -0,0 +1,32 @@ +/* +Copyright 2022 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 + +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 +}