Skip to content
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

added display version, hash and dirty in logs #149

Merged
merged 11 commits into from
Jul 8, 2024
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ COPY controllers/ controllers/
COPY pkg/ pkg/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
ARG VERSION
ARG COMMIT
ARG DIRTY

ENV VERSION=${VERSION:-unknown}
ENV COMMIT=${COMMIT:-unknown}
ENV DIRTY=${DIRTY:-unknown}
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
30 changes: 23 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,29 @@ SHELL = /usr/bin/env bash -o pipefail
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))

# VERSION defines the project version for the bundle.
# Update this value when you upgrade the version of your project.
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
# Check for dirty.
define check_dirty
GIT_SHA=$$(git rev-parse HEAD) || { \
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved
GIT_HASH=$${GIT_SHA:-NO_SHA}; \
}; \
if [ -z "$$GIT_HASH" ]; then \
GIT_DIRTY=$$(git diff --stat); \
if [ -n "$$GIT_DIRTY" ]; then \
DIRTY="true"; \
else \
DIRTY="false"; \
fi; \
fi; \
echo $$DIRTY
endef

VERSION ?= 0.0.0

# ldflag variables
VERSION_LIMITADOR_OPERATOR=0.10.0-dev # change this when version increases
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved
COMMIT=$(shell git rev-parse HEAD)
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved
DIRTY=$(shell $(check_dirty))

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
Expand Down Expand Up @@ -269,15 +285,15 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests.
##@ Build

build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
go build -ldflags "-X main.version=${VERSION_LIMITADOR_OPERATOR} -X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager main.go

run: export LOG_LEVEL = debug
run: export LOG_MODE = development
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

docker-build: ## Build docker image with the manager.
docker build -t $(IMG) .
docker build --build-arg VERSION=$(VERSION_LIMITADOR_OPERATOR) --build-arg COMMIT=$(COMMIT) --build-arg DIRTY=$(DIRTY) -t $(IMG) .

docker-push: ## Push docker image with the manager.
docker push $(IMG)
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ var (
scheme = k8sruntime.NewScheme()
logLevel = env.GetString("LOG_LEVEL", "info")
logMode = env.GetString("LOG_MODE", "production")
version string
commit string
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved
dirty string
)

func init() {
Expand All @@ -67,6 +70,7 @@ func printControllerMetaInfo() {
setupLog.Info(fmt.Sprintf("go version: %s", runtime.Version()))
setupLog.Info(fmt.Sprintf("go os/arch: %s/%s", runtime.GOOS, runtime.GOARCH))
setupLog.Info("base logger", "log level", logLevel, "log mode", logMode)
setupLog.Info("booting up limitador-operator", "version", version, "commit", commit, "dirty", dirty)
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved
}

func main() {
Expand Down
Loading