From 43989a9c60e34a5f2c5edaf485cd452d010074f7 Mon Sep 17 00:00:00 2001 From: Artur Dzmitryieu Date: Wed, 12 Apr 2023 13:42:26 -0400 Subject: [PATCH] Add version info into log --- Dockerfile | 6 +++++- main.go | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 646f9040..7e11ca7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,12 @@ COPY controllers/ controllers/ COPY common/ common/ COPY utils/ utils/ +ARG VERSION_LABEL=1.0.0 +ARG RELEASE_LABEL=XX +ARG VCS_REF=0123456789012345678901234567890123456789 + # Build -RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-s -w" -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-s -w -X 'main.Version=$VERSION_LABEL' -X 'main.VCS_REF=$VCS_REF' -X 'main.BuildDate=$(date)'" -a -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 diff --git a/main.go b/main.go index 571bdfc0..4dfcf84a 100644 --- a/main.go +++ b/main.go @@ -20,9 +20,10 @@ import ( "flag" "fmt" "os" + "runtime" "time" - "k8s.io/apimachinery/pkg/runtime" + k8sruntime "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" @@ -43,8 +44,11 @@ import ( ) var ( - scheme = runtime.NewScheme() - setupLog = ctrl.Log.WithName("setup") + scheme = k8sruntime.NewScheme() + setupLog = ctrl.Log.WithName("setup") + Version = "1.0.0" + BuildDate = "" + VCS_REF = "0123456789012345678901234567890123456789" ) func init() { @@ -77,6 +81,8 @@ func main() { ctrl.SetLogger(zap.New(zap.UseDevMode(true))) + setupLog.Info("Version Info", "Version", Version, "Runtime", runtime.Version(), + "Platform", runtime.GOOS+"/"+runtime.GOARCH, "VCS_REF", VCS_REF, "BuildDate", BuildDate) // see https://github.com/operator-framework/operator-sdk/issues/1813 leaseDuration := 30 * time.Second renewDeadline := 20 * time.Second