Skip to content

Add build info to logs #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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()

Expand Down