Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit 164fc25

Browse files
committed
Add operator version
1 parent 95364e5 commit 164fc25

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Build the manager binary
22
FROM golang:1.16 as builder
3+
ARG VERSION
34

45
WORKDIR /workspace
56
# Copy the Go Modules manifests
@@ -15,7 +16,7 @@ COPY api/ api/
1516
COPY controllers/ controllers/
1617

1718
# Build
18-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
19+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -a -o manager main.go
1920

2021
# Use distroless as minimal base image to package the manager binary
2122
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ test: manifests generate fmt vet ## Run tests.
9494
##@ Build
9595

9696
build: generate fmt vet ## Build manager binary.
97-
go build -o bin/manager main.go
97+
go build -ldflags "-X main.version=${VERSION}" -o bin/manager main.go
9898

9999
run: manifests generate fmt vet ## Run a controller from your host.
100-
go run ./main.go $(ARGS)
100+
go run -ldflags "-X main.version=${VERSION}" ./main.go $(ARGS)
101101

102102
docker-build: test ## Build docker image with the manager.
103-
docker build -t ${IMG} .
103+
docker build -t ${IMG} . --build-arg VERSION=${VERSION}
104104

105105
docker-push: ## Push docker image with the manager.
106106
docker push ${IMG}

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ import (
4545
var (
4646
scheme = runtime.NewScheme()
4747
setupLog = ctrl.Log.WithName("setup")
48+
version string
4849
)
4950

5051
func printVersion() {
51-
// log.Info(fmt.Sprintf("Operator Version: %s", version.Version))
52+
setupLog.Info(fmt.Sprintf("Operator Version: %s", version))
5253
setupLog.Info(fmt.Sprintf("Go Version: %s", runt.Version()))
5354
setupLog.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runt.GOOS, runt.GOARCH))
5455
setupLog.Info(fmt.Sprintf("Version of kubernetes: %v", controllers.RunningK8sVersion))

0 commit comments

Comments
 (0)