Skip to content

Commit

Permalink
Merge pull request #154 from mshitrit/log-version
Browse files Browse the repository at this point in the history
print versions
  • Loading branch information
openshift-ci[bot] authored Oct 30, 2023
2 parents 6786790 + 948d50b commit 7373617
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build the manager binary
FROM quay.io/centos/centos:stream8 AS builder
RUN yum install golang -y && yum clean all
RUN yum install git golang -y && yum clean all

# Ensure correct Go version
ENV GO_VERSION=1.20
Expand All @@ -13,23 +13,25 @@ WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY vendor/ vendor/
COPY version/ version/
COPY main.go main.go
COPY hack/ hack/
COPY api/ api/
COPY controllers/ controllers/
# for getting version info
COPY .git/ .git/
COPY pkg/ pkg/
COPY install/ install/
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
RUN ./hack/build.sh

FROM registry.access.redhat.com/ubi8/ubi:latest

WORKDIR /
COPY --from=builder /workspace/install/ install/
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/bin/manager .

ENTRYPOINT ["/manager"]
16 changes: 16 additions & 0 deletions hack/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -ex

GIT_VERSION=$(git describe --always --tags || true)
VERSION=${CI_UPSTREAM_VERSION:-${GIT_VERSION}}
GIT_COMMIT=$(git rev-list -1 HEAD || true)
COMMIT=${CI_UPSTREAM_COMMIT:-${GIT_COMMIT}}
BUILD_DATE=$(date --utc -Iseconds)

mkdir -p bin

LDFLAGS="-s -w "
LDFLAGS+="-X github.com/medik8s/self-node-remediation/version.Version=${VERSION} "
LDFLAGS+="-X github.com/medik8s/self-node-remediation/version.GitCommit=${COMMIT} "
LDFLAGS+="-X github.com/medik8s/self-node-remediation/version.BuildDate=${BUILD_DATE} "
GOFLAGS=-mod=vendor CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o bin/manager main.go
17 changes: 15 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ package main
import (
"crypto/tls"
"flag"
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"time"

"github.com/pkg/errors"
"go.uber.org/zap/zapcore"

"k8s.io/apimachinery/pkg/runtime"
pkgruntime "k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"

Expand All @@ -53,6 +55,7 @@ import (
"github.com/medik8s/self-node-remediation/pkg/template"
"github.com/medik8s/self-node-remediation/pkg/utils"
"github.com/medik8s/self-node-remediation/pkg/watchdog"
"github.com/medik8s/self-node-remediation/version"
//+kubebuilder:scaffold:imports
)

Expand All @@ -65,7 +68,7 @@ const (
)

var (
scheme = runtime.NewScheme()
scheme = pkgruntime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)

Expand Down Expand Up @@ -101,6 +104,8 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

printVersion()

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
// HEADS UP: once controller runtime is updated and this changes to metrics.Options{},
Expand Down Expand Up @@ -400,3 +405,11 @@ func configureWebhookServer(mgr ctrl.Manager, enableHTTP2 bool) {
}

}

func printVersion() {
setupLog.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
setupLog.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
setupLog.Info(fmt.Sprintf("Operator Version: %s", version.Version))
setupLog.Info(fmt.Sprintf("Git Commit: %s", version.GitCommit))
setupLog.Info(fmt.Sprintf("Build Date: %s", version.BuildDate))
}
10 changes: 10 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package version

var (
// Version is the operator version
Version = "0.0.1"
// GitCommit is the current git commit hash
GitCommit = "n/a"
// BuildDate is the build date
BuildDate = "n/a"
)

0 comments on commit 7373617

Please sign in to comment.