Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit f03e9b0

Browse files
uniemimumadalazar
authored andcommitted
add build version information logging
This adds build version information to the binary and logs it. Signed-off-by: Ukri Niemimuukko <ukri.niemimuukko@intel.com>
1 parent 3973ef8 commit f03e9b0

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

gpu-aware-scheduling/Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ IMAGE_TAG=:$(TAG)
33
endif
44

55
GOLICENSES_VERSION?=v1.5.0
6+
BUILD_OUTPUT_DIR?=./bin
67

78
ifneq ("$(wildcard licenses/)","")
89
LOCAL_LICENSES=TRUE
910
endif
1011

12+
GOVERSION=$(shell go version | sed 's/^[^0-9]*//' | cut -d' ' -f1)
13+
BUILDDATE=$(shell date "+%Y%m%d-%T")
14+
VERSION=$(shell git describe --tags --long --match gpu-aware-scheduling/v*)
15+
16+
LDFLAGS = \
17+
-s -w \
18+
-X main.version=$(VERSION) \
19+
-X main.buildDate=$(BUILDDATE) \
20+
-X main.goVersion=$(GOVERSION)
21+
22+
1123
.PHONY: test all build image release-image format clean licenses mock e2e lint
1224

1325
test:
@@ -19,7 +31,7 @@ lint: format build
1931
golangci-lint run
2032

2133
build:
22-
CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -o ./bin/extender ./cmd/gas-scheduler-extender
34+
CGO_ENABLED=0 GO111MODULE=on go build -ldflags="$(LDFLAGS)" -o $(BUILD_OUTPUT_DIR)/extender ./cmd/gas-scheduler-extender
2335

2436
#note: you can speed up subsequent docker builds by doing "go mod vendor"
2537
#note: you can further speed up subsequent docker builds by doing "make licenses"

gpu-aware-scheduling/cmd/gas-scheduler-extender/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ import (
1212
"k8s.io/klog/v2"
1313
)
1414

15+
// build variables need to be globals
16+
//
17+
//nolint:gochecknoglobals
18+
var (
19+
goVersion = "value is set during build"
20+
buildDate = "value is set during build"
21+
version = "value is set during build"
22+
)
23+
24+
const (
25+
l1 = klog.Level(1)
26+
)
27+
1528
func main() {
1629
var (
1730
kubeConfig, port, certFile, keyFile, caFile, balancedRes string
@@ -29,6 +42,8 @@ func main() {
2942
klog.InitFlags(nil)
3043
flag.Parse()
3144

45+
klog.V(l1).Infof("%s built on %s with go %s", version, buildDate, goVersion)
46+
3247
kubeClient, _, err := extender.GetKubeClient(kubeConfig)
3348
if err != nil {
3449
klog.Error("couldn't get kube client, cannot continue: ", err.Error())

gpu-aware-scheduling/deploy/images/Dockerfile_gpu-extender

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ARG LOCAL_LICENSES
77
COPY . /src_root
88
WORKDIR /src_root/gpu-aware-scheduling
99
RUN mkdir -p /install_root/etc && adduser --disabled-password --quiet --gecos "" -u 10001 gas && tail -1 /etc/passwd > /install_root/etc/passwd \
10-
&& CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -o /install_root/extender ./cmd/gas-scheduler-extender \
10+
&& BUILD_OUTPUT_DIR=/install_root make build \
1111
&& if [ -z "$LOCAL_LICENSES" ] ; then \
1212
GO111MODULE=on go run github.com/google/go-licenses@${GOLICENSES_VERSION} save "./cmd/gas-scheduler-extender" --save_path /install_root/licenses ; \
1313
else cp -r licenses /install_root/ ; fi

0 commit comments

Comments
 (0)