diff --git a/gpu-aware-scheduling/Makefile b/gpu-aware-scheduling/Makefile index 1ef3f20d..5c2f708e 100644 --- a/gpu-aware-scheduling/Makefile +++ b/gpu-aware-scheduling/Makefile @@ -3,11 +3,23 @@ IMAGE_TAG=:$(TAG) endif GOLICENSES_VERSION?=v1.5.0 +BUILD_OUTPUT_DIR?=./bin ifneq ("$(wildcard licenses/)","") LOCAL_LICENSES=TRUE endif +GOVERSION=$(shell go version | sed 's/^[^0-9]*//' | cut -d' ' -f1) +BUILDDATE=$(shell date "+%Y%m%d-%T") +VERSION=$(shell git describe --tags --long --match gpu-aware-scheduling/v*) + +LDFLAGS = \ +-s -w \ +-X main.version=$(VERSION) \ +-X main.buildDate=$(BUILDDATE) \ +-X main.goVersion=$(GOVERSION) + + .PHONY: test all build image release-image format clean licenses mock e2e lint test: @@ -19,7 +31,7 @@ lint: format build golangci-lint run build: - CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -o ./bin/extender ./cmd/gas-scheduler-extender + CGO_ENABLED=0 GO111MODULE=on go build -ldflags="$(LDFLAGS)" -o $(BUILD_OUTPUT_DIR)/extender ./cmd/gas-scheduler-extender #note: you can speed up subsequent docker builds by doing "go mod vendor" #note: you can further speed up subsequent docker builds by doing "make licenses" diff --git a/gpu-aware-scheduling/cmd/gas-scheduler-extender/main.go b/gpu-aware-scheduling/cmd/gas-scheduler-extender/main.go index 48568c37..58a554b8 100644 --- a/gpu-aware-scheduling/cmd/gas-scheduler-extender/main.go +++ b/gpu-aware-scheduling/cmd/gas-scheduler-extender/main.go @@ -12,6 +12,19 @@ import ( "k8s.io/klog/v2" ) +// build variables need to be globals +// +//nolint:gochecknoglobals +var ( + goVersion = "value is set during build" + buildDate = "value is set during build" + version = "value is set during build" +) + +const ( + l1 = klog.Level(1) +) + func main() { var ( kubeConfig, port, certFile, keyFile, caFile, balancedRes string @@ -29,6 +42,8 @@ func main() { klog.InitFlags(nil) flag.Parse() + klog.V(l1).Infof("%s built on %s with go %s", version, buildDate, goVersion) + kubeClient, _, err := extender.GetKubeClient(kubeConfig) if err != nil { klog.Error("couldn't get kube client, cannot continue: ", err.Error()) diff --git a/gpu-aware-scheduling/deploy/images/Dockerfile_gpu-extender b/gpu-aware-scheduling/deploy/images/Dockerfile_gpu-extender index f76f356f..fe190557 100644 --- a/gpu-aware-scheduling/deploy/images/Dockerfile_gpu-extender +++ b/gpu-aware-scheduling/deploy/images/Dockerfile_gpu-extender @@ -7,7 +7,7 @@ ARG LOCAL_LICENSES COPY . /src_root WORKDIR /src_root/gpu-aware-scheduling RUN mkdir -p /install_root/etc && adduser --disabled-password --quiet --gecos "" -u 10001 gas && tail -1 /etc/passwd > /install_root/etc/passwd \ - && CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -o /install_root/extender ./cmd/gas-scheduler-extender \ + && BUILD_OUTPUT_DIR=/install_root make build \ && if [ -z "$LOCAL_LICENSES" ] ; then \ GO111MODULE=on go run github.com/google/go-licenses@${GOLICENSES_VERSION} save "./cmd/gas-scheduler-extender" --save_path /install_root/licenses ; \ else cp -r licenses /install_root/ ; fi