diff --git a/Makefile b/Makefile index a52a4e798..7d647462e 100644 --- a/Makefile +++ b/Makefile @@ -97,6 +97,18 @@ endif SHELL = /usr/bin/env bash -o pipefail .SHELLFLAGS = -ec +BUILD_DATE := $(shell date +%Y-%m-%d\ %H:%M) +BUILD_TAG_SHA := $(shell git rev-list --abbrev-commit --tags --max-count=1) +BUILD_TAG_NAME := $(shell git describe --abbrev=0 --tags ${BUILD_TAG_SHA} 2>/dev/null || true) +BUILD_SHA := $(shell git rev-parse --short HEAD) +BUILD_VERSION := $(BUILD_TAG_NAME:v%=%) +ifneq ($(BUILD_SHA), $(BUILD_TAG_SHA)) + BUILD_VERSION := $(BUILD_VERSION)-$(BUILD_SHA) +endif +ifneq ($(shell git status --porcelain),) + BUILD_VERSION := $(BUILD_VERSION)-dirty +endif + .PHONY: all all: build @@ -147,7 +159,14 @@ modules: ## Update Go dependencies. .PHONY: build build: modules fmt vet ## Build manager binary. - go build -o bin/manager main.go + go build \ + -ldflags " \ + -X 'main.OperatorVersion=$(BUILD_VERSION)' \ + -X 'main.McadVersion=$(MCAD_VERSION)' \ + -X 'main.InstaScaleVersion=$(INSTASCALE_VERSION)' \ + -X 'main.BuildDate=$(BUILD_DATE)' \ + " \ + -o bin/manager main.go .PHONY: run run: modules manifests fmt vet ## Run a controller from your host. diff --git a/main.go b/main.go index 5e7065766..84827f43c 100644 --- a/main.go +++ b/main.go @@ -58,8 +58,12 @@ import ( ) var ( - scheme = runtime.NewScheme() - setupLog = ctrl.Log.WithName("setup") + scheme = runtime.NewScheme() + setupLog = ctrl.Log.WithName("setup") + OperatorVersion = "UNKNOWN" + McadVersion = "UNKNOWN" + InstaScaleVersion = "UNKNOWN" + BuildDate = "UNKNOWN" ) func init() { @@ -85,6 +89,12 @@ func main() { zapOptions.BindFlags(flag.CommandLine) ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zapOptions))) + setupLog.Info("Build info", + "operatorVersion", OperatorVersion, + "mcadVersion", McadVersion, + "instaScaleVersion", InstaScaleVersion, + "date", BuildDate, + ) ctx := ctrl.SetupSignalHandler()