Skip to content

Commit 5816832

Browse files
Hack utility added (#86)
* Go mod files after linting * Hack utility added
1 parent 990f7da commit 5816832

File tree

12 files changed

+226
-11
lines changed

12 files changed

+226
-11
lines changed

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,21 @@ VERSION=v0.0.1
1818
GIT_COMMIT?=$(shell git rev-parse HEAD)
1919
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
2020
LDFLAGS?="-X ${PKG}/pkg/driver.driverVersion=${VERSION} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE} -s -w"
21+
2122
GO111MODULE=on
2223
GOPROXY=direct
2324
GOPATH=$(shell go env GOPATH)
2425
GOOS=$(shell go env GOOS)
2526
GOBIN=$(shell pwd)/bin
27+
2628
PLATFORM=linux/ppc64le
2729

30+
2831
.EXPORT_ALL_VARIABLES:
2932

33+
bin:
34+
@mkdir -p $@
35+
3036
.PHONY: bin/ibm-powervs-block-csi-driver
3137
bin/ibm-powervs-block-csi-driver: | bin
3238
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -ldflags ${LDFLAGS} -o bin/ibm-powervs-block-csi-driver ./cmd/
@@ -54,3 +60,26 @@ push:
5460
.PHONY: clean
5561
clean:
5662
rm -rf bin/*
63+
64+
bin/mockgen: | bin
65+
go install github.com/golang/mock/[email protected]
66+
67+
bin/golangci-lint: | bin
68+
echo "Installing golangci-lint..."
69+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.43.0
70+
71+
mockgen: bin/mockgen
72+
./hack/update-gomock
73+
74+
.PHONY: verify
75+
verify: bin/golangci-lint
76+
echo "verifying and linting files ..."
77+
./hack/verify-all
78+
echo "Congratulations! All Go source files have been linted."
79+
80+
.PHONY: verify-vendor
81+
test: verify-vendor
82+
verify: verify-vendor
83+
verify-vendor:
84+
@ echo; echo "### $@:"
85+
@ ./hack/verify-vendor.sh

go.mod

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ require (
99
github.com/davecgh/go-spew v1.1.1
1010
github.com/golang-jwt/jwt v3.2.2+incompatible
1111
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
12+
github.com/golang/mock v1.6.0
13+
github.com/kubernetes-csi/csi-test v2.2.0+incompatible
1214
github.com/onsi/ginkgo v1.16.5
1315
github.com/onsi/gomega v1.17.0
1416
google.golang.org/grpc v1.43.0
@@ -51,7 +53,6 @@ require (
5153
github.com/go-stack/stack v1.8.0 // indirect
5254
github.com/gogo/protobuf v1.3.2 // indirect
5355
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
54-
github.com/golang/mock v1.6.0 // indirect
5556
github.com/golang/protobuf v1.5.2 // indirect
5657
github.com/google/go-cmp v0.5.5 // indirect
5758
github.com/google/gofuzz v1.1.0 // indirect
@@ -65,7 +66,6 @@ require (
6566
github.com/jmespath/go-jmespath v0.4.0 // indirect
6667
github.com/josharian/intern v1.0.0 // indirect
6768
github.com/json-iterator/go v1.1.11 // indirect
68-
github.com/kubernetes-csi/csi-test v2.2.0+incompatible // indirect
6969
github.com/leodido/go-urn v1.2.0 // indirect
7070
github.com/mailru/easyjson v0.7.6 // indirect
7171
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
@@ -97,15 +97,12 @@ require (
9797
go.opentelemetry.io/otel/trace v0.20.0 // indirect
9898
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
9999
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
100-
golang.org/x/mod v0.4.2 // indirect
101100
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
102101
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
103102
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
104103
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
105104
golang.org/x/text v0.3.7 // indirect
106105
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
107-
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff // indirect
108-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
109106
google.golang.org/appengine v1.6.7 // indirect
110107
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
111108
google.golang.org/protobuf v1.27.1 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
911911
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
912912
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
913913
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
914-
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
915914
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
916915
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
917916
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -1171,7 +1170,6 @@ golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
11711170
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
11721171
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
11731172
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
1174-
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff h1:VX/uD7MK0AHXGiScH3fsieUQUcpmRERPDYtqZdJnA+Q=
11751173
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff/go.mod h1:YD9qOF0M9xpSpdWTBbzEl5e/RnCefISl8E5Noe10jFM=
11761174
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
11771175
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

hack/update-gofmt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -w

hack/update-gomock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
bin/mockgen -package mocks -destination=pkg/cloud/mocks/mock_cloud.go -source ./pkg/cloud/cloud_interface.go
20+
bin/mockgen -package mocks -destination=pkg/driver/mocks/mock_mounter.go -source ./pkg/driver/mount.go

hack/update-gomod

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
set -euo pipefail
19+
set -x
20+
21+
VERSION=${1#"v"}
22+
if [ -z "$VERSION" ]; then
23+
echo "Must specify version!"
24+
exit 1
25+
fi
26+
MODS=($(
27+
curl -sS https://raw.githubusercontent.com/kubernetes/kubernetes/v${VERSION}/go.mod |
28+
sed -n 's|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p'
29+
))
30+
echo $MODS
31+
for MOD in "${MODS[@]}"; do
32+
echo $MOD
33+
V=$(
34+
go mod download -json "${MOD}@kubernetes-${VERSION}" |
35+
sed -n 's|.*"Version": "\(.*\)".*|\1|p'
36+
)
37+
go mod edit "-replace=${MOD}=${MOD}@${V}"

hack/verify-all

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
PKG_ROOT=$(git rev-parse --show-toplevel)
20+
21+
${PKG_ROOT}/hack/verify-gofmt
22+
${PKG_ROOT}/hack/verify-govet
23+
${PKG_ROOT}/bin/golangci-lint run --deadline=10m
24+
${PKG_ROOT}/hack/verify-vendor.sh

hack/verify-gofmt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
echo "Verifying gofmt"
20+
21+
diff=$(find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -d 2>&1)
22+
if [[ -n "${diff}" ]]; then
23+
echo "${diff}"
24+
echo
25+
echo "Please run hack/update-gofmt to fix the issue(s)"
26+
exit 1
27+
fi
28+
echo "No issue found"

hack/verify-govet

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
echo "Verifying govet"
20+
21+
go vet $(go list ./... | grep -v vendor)
22+
23+
echo "Done"

hack/verify-vendor.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2022 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
echo "Repo uses 'go mod'."
19+
if ! (set -x; env GO111MODULE=on go mod tidy); then
20+
echo "ERROR: vendor check failed."
21+
exit 1
22+
elif [ "$(git status --porcelain -- go.mod go.sum | wc -l)" -gt 0 ]; then
23+
echo "ERROR: go module files *not* up-to-date, they did get modified by 'GO111MODULE=on go mod tidy':";
24+
git diff -- go.mod go.sum
25+
exit 1
26+
elif [ -d vendor ]; then
27+
if ! (set -x; env GO111MODULE=on go mod vendor); then
28+
echo "ERROR: vendor check failed."
29+
exit 1
30+
elif [ "$(git status --porcelain -- vendor | wc -l)" -gt 0 ]; then
31+
echo "ERROR: vendor directory *not* up-to-date, it did get modified by 'GO111MODULE=on go mod vendor':"
32+
git status -- vendor
33+
git diff -- vendor
34+
exit 1
35+
else
36+
echo "Go dependencies and vendor directory up-to-date."
37+
fi
38+
else
39+
echo "Go dependencies up-to-date."
40+
fi

0 commit comments

Comments
 (0)