Skip to content

Commit

Permalink
Add some useful version info
Browse files Browse the repository at this point in the history
Git version, commit hash and build date

Signed-off-by: Marc Sluiter <[email protected]>
  • Loading branch information
slintes committed Sep 1, 2020
1 parent 3937d3d commit 5453426
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ KUBEVIRTCI_PATH=$$(pwd)/kubevirtci/cluster-up
KUBEVIRTCI_CONFIG_PATH=$$(pwd)/_ci-configs
export KUBEVIRT_NUM_NODES ?= 3

GIT_VERSION=$$(git describe --always --tags)
VERSION=$${CI_UPSTREAM_VERSION:-$(GIT_VERSION)}
GIT_COMMIT=$$(git rev-list -1 HEAD)
COMMIT=$${CI_UPSTREAM_COMMIT:-$(GIT_COMMIT)}
BUILD_DATE=$$(date --utc -Iseconds)

export GINKGO ?= build/_output/bin/ginkgo

# Make does not offer a recursive wildcard function, so here's one:
Expand Down Expand Up @@ -72,7 +78,12 @@ check: shfmt fmt vet generate-all verify-manifests verify-unchanged test

.PHONY: build
build:
mkdir -p _out && GOFLAGS=-mod=vendor CGO_ENABLED=0 GOOS=linux go build -o _out/node-maintenance-operator kubevirt.io/node-maintenance-operator/cmd/manager
mkdir -p _out; \
LDFLAGS="-s -w "; \
LDFLAGS+="-X kubevirt.io/node-maintenance-operator/version.Version=$(VERSION) "; \
LDFLAGS+="-X kubevirt.io/node-maintenance-operator/version.GitCommit=$(COMMIT) "; \
LDFLAGS+="-X kubevirt.io/node-maintenance-operator/version.BuildDate=$(BUILD_DATE) "; \
GOFLAGS=-mod=vendor CGO_ENABLED=0 GOOS=linux go build -ldflags="$$LDFLAGS" -o _out/node-maintenance-operator kubevirt.io/node-maintenance-operator/cmd/manager

.PHONY: container-build
container-build: container-build-operator container-build-bundle container-build-index container-build-must-gather
Expand Down
9 changes: 6 additions & 3 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (
"path/filepath"
"runtime"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/spf13/pflag"

admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
Expand All @@ -32,6 +31,7 @@ import (
"kubevirt.io/node-maintenance-operator/pkg/apis/nodemaintenance/v1beta1"
"kubevirt.io/node-maintenance-operator/pkg/controller"
"kubevirt.io/node-maintenance-operator/pkg/controller/nodemaintenance"
"kubevirt.io/node-maintenance-operator/version"
)

// Change below variables to serve metrics on different host or port.
Expand All @@ -58,6 +58,9 @@ func printVersion() {
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
log.Info(fmt.Sprintf("Version of operator-sdk: %v", sdkVersion.Version))
log.Info(fmt.Sprintf("Operator Version: %s", version.Version))
log.Info(fmt.Sprintf("Git Commit: %s", version.GitCommit))
log.Info(fmt.Sprintf("Build Date: %s", version.BuildDate))
}

func main() {
Expand Down
5 changes: 5 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package version

var (
// Version is the operator version
Version = "0.0.1"
// GitCommit is the current git commit hash
GitCommit = "n/a"
// BuildDate is the build date
BuildDate = "n/a"
)

0 comments on commit 5453426

Please sign in to comment.