From bc13ede7f6cfcd850e05154d77f024109a585d2f Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 29 Feb 2024 14:27:33 +0200 Subject: [PATCH 1/4] Add vendor check to CI Signed-off-by: Evan Lezar --- .github/workflows/golang.yaml | 23 ++++++++++++++++++++--- Makefile | 16 ++++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/golang.yaml b/.github/workflows/golang.yaml index c674ca56..e58d8865 100644 --- a/.github/workflows/golang.yaml +++ b/.github/workflows/golang.yaml @@ -1,4 +1,4 @@ -# Copyright 2023 NVIDIA CORPORATION +# Copyright 2023-2024 NVIDIA CORPORATION # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,28 +29,45 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - + name: Checkout code + - name: Get Golang version + id: vars + run: | + GOLANG_VERSION=$( grep "GOLANG_VERSION ?=" versions.mk ) + echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GOLANG_VERSION }} - name: Lint uses: golangci/golangci-lint-action@v4 with: version: latest args: -v --timeout 5m skip-cache: true + - name: Check golang modules + run: make check-vendor test: name: Unit test runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 + - name: Get Golang version + id: vars + run: | + GOLANG_VERSION=$( grep "GOLANG_VERSION ?=" versions.mk ) + echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV - name: Install Go uses: actions/setup-go@v5 with: - go-version: '1.20' + go-version: ${{ env.GOLANG_VERSION }} - run: make test build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + name: Checkout code - name: Build run: make docker-build diff --git a/Makefile b/Makefile index bb967ffc..a6abee63 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ CMDS := $(patsubst ./cmd/%/,%,$(sort $(dir $(wildcard ./cmd/*/)))) CMD_TARGETS := $(patsubst %,cmd-%, $(CMDS)) CHECK_TARGETS := golangci-lint -MAKE_TARGETS := binaries build check fmt vendor lint-internal test examples cmds coverage generate $(CHECK_TARGETS) +MAKE_TARGETS := binaries build check fmt lint-internal test examples cmds coverage generate vendor check-vendor $(CHECK_TARGETS) TARGETS := $(MAKE_TARGETS) $(CMD_TARGETS) @@ -64,10 +64,6 @@ $(EXAMPLE_TARGETS): example-%: all: check test build binaries check: $(CHECK_TARGETS) -# Update the vendor folder -vendor: - go mod vendor - # Apply go fmt to the codebase fmt: go list -f '{{.Dir}}' $(MODULE)/... \ @@ -84,6 +80,14 @@ goimports: golangci-lint: golangci-lint run ./... +vendor: + go mod tidy + go mod vendor + go mod verify + +check-vendor: vendor + git diff --quiet HEAD -- go.mod go.sum vendor + COVERAGE_FILE := coverage.out test: build cmds go test -race -cover -v -coverprofile=$(COVERAGE_FILE) $(MODULE)/... @@ -135,7 +139,7 @@ generate-clientset: .remove-clientset .remove-deepcopy .remove-crds .remove-clientset: rm -rf $(CURDIR)/$(PKG_BASE)/clientset -$(DOCKER_TARGETS): docker-%: +$(DOCKER_TARGETS): docker-%: @echo "Running 'make $(*)' in container image $(BUILDIMAGE)" $(DOCKER) run \ --rm \ From f64b4a740cc35d06c3d85c3e60f2f168c621c4a2 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 29 Feb 2024 15:31:46 +0200 Subject: [PATCH 2/4] Set boilerplate year to 2023 Signed-off-by: Evan Lezar --- hack/boilerplate.go.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt index 16db6e45..9c04a1f3 100644 --- a/hack/boilerplate.go.txt +++ b/hack/boilerplate.go.txt @@ -1,5 +1,5 @@ /* - * Copyright (c) YEAR, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 66874429713a19758bc43c7b88900c9e93b558bd Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 12 Feb 2024 16:49:32 +0100 Subject: [PATCH 3/4] Use nvidia/cuda base images for build Signed-off-by: Evan Lezar --- deployments/container/Dockerfile.ubi8 | 23 ++++++++++++++++++++++- deployments/container/Dockerfile.ubuntu | 23 ++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/deployments/container/Dockerfile.ubi8 b/deployments/container/Dockerfile.ubi8 index d5ae0ea3..d9445d39 100644 --- a/deployments/container/Dockerfile.ubi8 +++ b/deployments/container/Dockerfile.ubi8 @@ -16,7 +16,28 @@ ARG GOLANG_VERSION=1.20.4 ARG CUDA_IMAGE=cuda ARG CUDA_VERSION=11.8.0 ARG BASE_DIST=ubi8 -FROM golang:${GOLANG_VERSION} as build +FROM nvidia/cuda:${CUDA_VERSION}-base-${BASE_DIST} as build + +RUN yum install -y \ + wget make git gcc \ + && \ + rm -rf /var/cache/yum/* + +ARG GOLANG_VERSION=x.x.x +RUN set -eux; \ + \ + arch="$(uname -m)"; \ + case "${arch##*-}" in \ + x86_64 | amd64) ARCH='amd64' ;; \ + ppc64el | ppc64le) ARCH='ppc64le' ;; \ + aarch64 | arm64) ARCH='arm64' ;; \ + *) echo "unsupported architecture" ; exit 1 ;; \ + esac; \ + wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${ARCH}.tar.gz \ + | tar -C /usr/local -xz + +ENV GOPATH /go +ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH WORKDIR /build COPY . . diff --git a/deployments/container/Dockerfile.ubuntu b/deployments/container/Dockerfile.ubuntu index 21e2e4d3..2acaaa78 100644 --- a/deployments/container/Dockerfile.ubuntu +++ b/deployments/container/Dockerfile.ubuntu @@ -16,7 +16,28 @@ ARG GOLANG_VERSION=1.20.4 ARG CUDA_IMAGE=cuda ARG CUDA_VERSION=11.8.0 ARG BASE_DIST=ubuntu20.04 -FROM golang:${GOLANG_VERSION} as build +FROM nvidia/cuda:${CUDA_VERSION}-base-${BASE_DIST} as build + +RUN apt-get update && \ + apt-get install -y wget make git gcc \ + && \ + rm -rf /var/lib/apt/lists/* + +ARG GOLANG_VERSION=x.x.x +RUN set -eux; \ + \ + arch="$(uname -m)"; \ + case "${arch##*-}" in \ + x86_64 | amd64) ARCH='amd64' ;; \ + ppc64el | ppc64le) ARCH='ppc64le' ;; \ + aarch64 | arm64) ARCH='arm64' ;; \ + *) echo "unsupported architecture" ; exit 1 ;; \ + esac; \ + wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${ARCH}.tar.gz \ + | tar -C /usr/local -xz + +ENV GOPATH /go +ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH WORKDIR /build COPY . . From b9c70f0be8390bcf309a97580eece72abb234c2f Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 29 Feb 2024 15:47:43 +0200 Subject: [PATCH 4/4] Fix %w usage in klog.Errorf Signed-off-by: Evan Lezar --- cmd/nvidia-dra-plugin/driver.go | 10 +++++----- cmd/nvidia-dra-plugin/main.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/nvidia-dra-plugin/driver.go b/cmd/nvidia-dra-plugin/driver.go index ac1b810c..bbc85d1b 100644 --- a/cmd/nvidia-dra-plugin/driver.go +++ b/cmd/nvidia-dra-plugin/driver.go @@ -198,12 +198,12 @@ func (d *driver) CleanupStaleStateContinuously(ctx context.Context) { for { resourceVersion, err := d.cleanupStaleStateOnce(ctx) if err != nil { - klog.Errorf("Error cleaning up stale claim state: %w", err) + klog.Errorf("Error cleaning up stale claim state: %v", err) } err = d.cleanupStaleStateContinuously(ctx, resourceVersion, err) if err != nil { - klog.Errorf("Error cleaning up stale claim state: %w", err) + klog.Errorf("Error cleaning up stale claim state: %v", err) time.Sleep(CleanupTimeoutSecondsOnError * time.Second) } } @@ -279,7 +279,7 @@ func (d *driver) cleanupStaleState(ctx context.Context, nas *nascrd.NodeAllocati go func() { count := 0 for err := range caErrors { - klog.Errorf("Error cleaning up claim allocations: %w", err) + klog.Errorf("Error cleaning up claim allocations: %v", err) count++ } errorCounts <- count @@ -290,7 +290,7 @@ func (d *driver) cleanupStaleState(ctx context.Context, nas *nascrd.NodeAllocati go func() { count := 0 for err := range cdiErrors { - klog.Errorf("Error cleaning up CDI files: %w", err) + klog.Errorf("Error cleaning up CDI files: %v", err) count++ } errorCounts <- count @@ -301,7 +301,7 @@ func (d *driver) cleanupStaleState(ctx context.Context, nas *nascrd.NodeAllocati go func() { count := 0 for err := range mpsErrors { - klog.Errorf("Error cleaning up MPS control daemon artifacts: %w", err) + klog.Errorf("Error cleaning up MPS control daemon artifacts: %v", err) count++ } errorCounts <- count diff --git a/cmd/nvidia-dra-plugin/main.go b/cmd/nvidia-dra-plugin/main.go index c40b02ae..f2bf3254 100644 --- a/cmd/nvidia-dra-plugin/main.go +++ b/cmd/nvidia-dra-plugin/main.go @@ -191,7 +191,7 @@ func StartPlugin(ctx context.Context, config *Config) error { err = driver.Shutdown(ctx) if err != nil { - klog.Errorf("Unable to cleanly shutdown driver: %w", err) + klog.Errorf("Unable to cleanly shutdown driver: %v", err) } return nil