From 7991ad5e741692e9b34bce8e28c8f00646b4cd27 Mon Sep 17 00:00:00 2001 From: Ronen Schaffer Date: Mon, 13 Nov 2023 16:43:57 +0200 Subject: [PATCH 1/2] Add build info to logs --- Makefile | 14 +++++++++++++- main.go | 7 +++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a52a4e798..564fbb078 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,7 @@ 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.BuildVersion=$(BUILD_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..6387f18f7 100644 --- a/main.go +++ b/main.go @@ -58,8 +58,10 @@ import ( ) var ( - scheme = runtime.NewScheme() - setupLog = ctrl.Log.WithName("setup") + scheme = runtime.NewScheme() + setupLog = ctrl.Log.WithName("setup") + BuildVersion = "UNKNOWN" + BuildDate = "UNKNOWN" ) func init() { @@ -85,6 +87,7 @@ func main() { zapOptions.BindFlags(flag.CommandLine) ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zapOptions))) + setupLog.Info("Build info", "version", BuildVersion, "date", BuildDate) ctx := ctrl.SetupSignalHandler() From fefbf2d43c4b2e62aad60896a8c089824a767739 Mon Sep 17 00:00:00 2001 From: Ronen Schaffer Date: Tue, 14 Nov 2023 11:53:54 +0200 Subject: [PATCH 2/2] Log MCAD and InstaScale versions --- Makefile | 9 ++++++++- main.go | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 564fbb078..7d647462e 100644 --- a/Makefile +++ b/Makefile @@ -159,7 +159,14 @@ modules: ## Update Go dependencies. .PHONY: build build: modules fmt vet ## Build manager binary. - go build -ldflags "-X 'main.BuildVersion=$(BUILD_VERSION)' -X 'main.BuildDate=$(BUILD_DATE)'" -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 6387f18f7..84827f43c 100644 --- a/main.go +++ b/main.go @@ -58,10 +58,12 @@ import ( ) var ( - scheme = runtime.NewScheme() - setupLog = ctrl.Log.WithName("setup") - BuildVersion = "UNKNOWN" - BuildDate = "UNKNOWN" + scheme = runtime.NewScheme() + setupLog = ctrl.Log.WithName("setup") + OperatorVersion = "UNKNOWN" + McadVersion = "UNKNOWN" + InstaScaleVersion = "UNKNOWN" + BuildDate = "UNKNOWN" ) func init() { @@ -87,7 +89,12 @@ func main() { zapOptions.BindFlags(flag.CommandLine) ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zapOptions))) - setupLog.Info("Build info", "version", BuildVersion, "date", BuildDate) + setupLog.Info("Build info", + "operatorVersion", OperatorVersion, + "mcadVersion", McadVersion, + "instaScaleVersion", InstaScaleVersion, + "date", BuildDate, + ) ctx := ctrl.SetupSignalHandler()