Skip to content

Commit

Permalink
Merge branch 'lint-improvements' into 'master'
Browse files Browse the repository at this point in the history
add more CI check and linting improvements

See merge request nvidia/kubernetes/gpu-operator!765
  • Loading branch information
tariq1890 committed Aug 28, 2023
2 parents cb25aa5 + 0b09d64 commit d75de9b
Show file tree
Hide file tree
Showing 21 changed files with 11 additions and 1,516 deletions.
20 changes: 2 additions & 18 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,12 @@ validate-helm-values:
script:
- make validate-helm-values

.go-check:
go-checks:
extends:
- .requires-build-image
stage: go-checks

fmt:
extends:
- .go-check
script:
- make assert-fmt

golangci-lint:
extends:
- .go-check
script:
- make golangci-lint

go-validate-modules:
extends:
- .go-check
script:
- make validate-modules
- make check

go-build:
extends:
Expand Down
22 changes: 5 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ all: gpu-operator

# Run tests
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt golangci-lint manifests
test: generate check manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out

# Build gpu-operator binary
gpu-operator: generate fmt golangci-lint
gpu-operator: generate check
go build -o bin/gpu-operator main.go

# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt golangci-lint manifests
run: generate check manifests
go run ./main.go

# Install CRDs into a cluster
Expand Down Expand Up @@ -154,7 +154,7 @@ push-bundle-image: build-bundle-image
CMDS := $(patsubst ./cmd/%/,%,$(sort $(dir $(wildcard ./cmd/*/))))
CMD_TARGETS := $(patsubst %,cmd-%, $(CMDS))

CHECK_TARGETS := assert-fmt golangci-lint
CHECK_TARGETS := golangci-lint validate-modules
MAKE_TARGETS := build check coverage cmds $(CMD_TARGETS) $(CHECK_TARGETS)
DOCKER_TARGETS := $(patsubst %,docker-%, $(MAKE_TARGETS))
.PHONY: $(MAKE_TARGETS) $(DOCKER_TARGETS)
Expand All @@ -167,7 +167,6 @@ DOCKER_TARGETS := $(patsubst %,docker-%, $(MAKE_TARGETS))
$(DOCKER) build \
--progress=plain \
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
--build-arg GOLANGCI_LINT_VERSION="$(GOLANGCI_LINT_VERSION)" \
--tag $(BUILDIMAGE) \
-f $(^) \
docker; \
Expand All @@ -192,23 +191,12 @@ $(DOCKER_TARGETS): docker-%: .build-image

check: $(CHECK_TARGETS)


# Apply go fmt to the codebase
fmt:
go list -f '{{.Dir}}' $(MODULE)/... \
| xargs gofmt -s -l -w

assert-fmt:
go list -f '{{.Dir}}' $(MODULE)/... \
| xargs gofmt -s -l | ( grep -v /vendor/ || true ) > fmt.out
@if [ -s fmt.out ]; then \
echo "\nERROR: The following files are not formatted:\n"; \
cat fmt.out; \
rm fmt.out; \
exit 1; \
else \
rm fmt.out; \
fi

golangci-lint:
golangci-lint run ./...

Expand Down
6 changes: 3 additions & 3 deletions controllers/object_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"bufio"
"context"
stderrors "errors"
"fmt"
"hash/fnv"
"os"
Expand All @@ -15,7 +16,6 @@ import (
"path/filepath"

"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/go-multierror"
"github.com/mitchellh/hashstructure"
apiconfigv1 "github.com/openshift/api/config/v1"
apiimagev1 "github.com/openshift/api/image/v1"
Expand Down Expand Up @@ -1878,7 +1878,7 @@ func TransformValidator(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec,

for _, component := range components {
if err := TransformValidatorComponent(config, &obj.Spec.Template.Spec, component); err != nil {
validatorErr = multierror.Append(validatorErr, err)
validatorErr = stderrors.Join(validatorErr, err)
}
}

Expand Down Expand Up @@ -1907,7 +1907,7 @@ func TransformSandboxValidator(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolic

for _, component := range components {
if err := TransformValidatorComponent(config, &obj.Spec.Template.Spec, component); err != nil {
validatorErr = multierror.Append(validatorErr, err)
validatorErr = stderrors.Join(validatorErr, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.devel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
ARG GOLANG_VERSION=x.x.x
ARG GOLANGCI_LINT_VERSION=x.y.z
ARG GOLANGCI_LINT_VERSION=1.54.2
FROM golang:${GOLANG_VERSION}

RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/NVIDIA/nvidia-container-toolkit v1.14.0-rc.2.0.20230823085558-fca30d7acc67
github.com/davecgh/go-spew v1.1.1
github.com/go-logr/logr v1.2.4
github.com/hashicorp/go-multierror v1.1.1
github.com/mitchellh/hashstructure v1.1.0
github.com/openshift/api v0.0.0-20230607151152-bdd886567621
github.com/openshift/client-go v0.0.0-20230607134213-3cd0021bbee3
Expand Down Expand Up @@ -61,7 +60,6 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
Expand Down
Loading

0 comments on commit d75de9b

Please sign in to comment.