Skip to content

Commit 3db8116

Browse files
authored
Merge pull request #34 from pohly/tidy-go-mod
clean up go.mod
2 parents 0479e0e + 9a638a3 commit 3db8116

File tree

5 files changed

+237
-11
lines changed

5 files changed

+237
-11
lines changed

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.12
55
require (
66
github.com/container-storage-interface/spec v1.1.0
77
github.com/davecgh/go-spew v1.1.1 // indirect
8+
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
89
github.com/gogo/protobuf v1.2.1 // indirect
910
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
1011
github.com/golang/protobuf v1.3.1
@@ -13,6 +14,10 @@ require (
1314
github.com/json-iterator/go v1.1.6 // indirect
1415
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
1516
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
17+
github.com/onsi/ginkgo v1.10.2 // indirect
18+
github.com/onsi/gomega v1.7.0 // indirect
19+
github.com/pkg/errors v0.8.1 // indirect
20+
github.com/spf13/pflag v1.0.5 // indirect
1621
github.com/stretchr/testify v1.3.0
1722
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c // indirect
1823
golang.org/x/net v0.0.0-20190328230028-74de082e2cca

go.sum

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ github.com/container-storage-interface/spec v1.1.0/go.mod h1:6URME8mwIBbpVyZV93C
77
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
88
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
99
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10+
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
11+
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
12+
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
13+
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
1014
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
1115
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
16+
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
1217
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
1318
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk=
1419
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -20,6 +25,8 @@ github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeq
2025
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
2126
github.com/googleapis/gnostic v0.2.0 h1:l6N3VoaVzTncYYW+9yOz2LJJammFZGBO13sqgEhpy9g=
2227
github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
28+
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
29+
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
2330
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
2431
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
2532
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
@@ -28,8 +35,17 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
2835
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
2936
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
3037
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
38+
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
39+
github.com/onsi/ginkgo v1.10.2 h1:uqH7bpe+ERSiDa34FDOF7RikN6RzXgduUF8yarlZp94=
40+
github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
41+
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
42+
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
43+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
44+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3145
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3246
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
47+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
48+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
3349
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3450
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
3551
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -41,6 +57,7 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk
4157
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
4258
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
4359
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
60+
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
4461
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
4562
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
4663
golang.org/x/net v0.0.0-20190328230028-74de082e2cca h1:hyA6yiAgbUwuWqtscNvWAI7U1CtlaD1KilQ6iudt1aI=
@@ -53,6 +70,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
5370
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
5471
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
5572
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
73+
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5674
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
5775
golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65 h1:hOY+O8MxdkPV10pNf7/XEHaySCiPKxixMKUshfHsGn0=
5876
golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -73,9 +91,15 @@ google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d/go.mod h1:VzzqZJRn
7391
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
7492
google.golang.org/grpc v1.19.1 h1:TrBcJ1yqAl1G++wO39nD/qtgpsW9/1+QGrluyMGEYgM=
7593
google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
94+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
7695
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
96+
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
97+
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
7798
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
7899
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
100+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
101+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
102+
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
79103
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
80104
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
81105
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

release-tools/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,57 @@ Kubernetes releases:
106106

107107
CSI_PROW_KUBERNETES_VERSION=1.13.3 ./.prow.sh
108108
CSI_PROW_KUBERNETES_VERSION=latest ./.prow.sh
109+
110+
Dependencies and vendoring
111+
--------------------------
112+
113+
Most projects will (eventually) use `go mod` to manage
114+
dependencies. `dep` is also still supported by `csi-release-tools`,
115+
but not documented here because it's not recommended anymore.
116+
117+
The usual instructions for using [go
118+
modules](https://github.com/golang/go/wiki/Modules) apply. Here's a cheat sheet
119+
for some of the relevant commands:
120+
- list available updates: `GO111MODULE=on go list -u -m all`
121+
- update or add a single dependency: `GO111MODULE=on go get <package>`
122+
- update all dependencies to their next minor or patch release:
123+
`GO111MODULE=on go get ./...` (add `-u=patch` to limit to patch
124+
releases)
125+
- lock onto a specific version: `GO111MODULE=on go get <package>@<version>`
126+
- clean up `go.mod`: `GO111MODULE=on go mod tidy`
127+
- update vendor directory: `GO111MODULE=on go mod vendor`
128+
129+
`GO111MODULE=on` can be left out when using Go >= 1.13 or when the
130+
source is checked out outside of `$GOPATH`.
131+
132+
`go mod tidy` must be used to ensure that the listed dependencies are
133+
really still needed. Changing import statements or a tentative `go
134+
get` can result in stale dependencies.
135+
136+
The `test-vendor` verifies that it was used when run locally or in a
137+
pre-merge CI job. If a `vendor` directory is present, it will also
138+
verify that it's content is up-to-date.
139+
140+
The `vendor` directory is optional. It is still present in projects
141+
because it avoids downloading sources during CI builds. If this is no
142+
longer deemed necessary, then a project can also remove the directory.
143+
144+
When using packages that are part of the Kubernetes source code, the
145+
commands above are not enough because the [lack of semantic
146+
versioning](https://github.com/kubernetes/kubernetes/issues/72638)
147+
prevents `go mod` from finding newer releases. Importing directly from
148+
`kubernetes/kubernetes` also needs `replace` statements to override
149+
the fake `v0.0.0` versions
150+
(https://github.com/kubernetes/kubernetes/issues/79384). The
151+
`go-get-kubernetes.sh` script can be used to update all packages in
152+
lockstep to a different Kubernetes version. It takes a single version
153+
number like "1.16.0".
154+
155+
Conversion of a repository that uses `dep` to `go mod` can be done with:
156+
157+
GO111MODULE=on go mod init
158+
release-tools/go-get-kubernetes.sh <current Kubernetes version from Gopkg.toml>
159+
GO111MODULE=on go mod tidy
160+
GO111MODULE=on go mod vendor
161+
git rm -f Gopkg.toml Gopkg.lock
162+
git add go.mod go.sum vendor

release-tools/build.make

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ else
5757
TESTARGS =
5858
endif
5959

60+
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
61+
6062
# Specific packages can be excluded from each of the tests below by setting the *_FILTER_CMD variables
6163
# to something like "| grep -v 'github.com/kubernetes-csi/project/pkg/foobar'". See usage below.
6264

6365
build-%:
6466
mkdir -p bin
6567
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$* ./cmd/$*
66-
CGO_ENABLED=0 GOOS=windows go build -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$*.exe ./cmd/$*
68+
if [ "$$ARCH" = "amd64" ]; then \
69+
CGO_ENABLED=0 GOOS=windows go build -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$*.exe ./cmd/$* ; \
70+
fi
6771

6872
container-%: build-%
6973
docker build -t $*:latest -f $(shell if [ -e ./cmd/$*/Dockerfile ]; then echo ./cmd/$*/Dockerfile; else echo Dockerfile; fi) --label revision=$(REV) .
@@ -126,6 +130,26 @@ test-fmt:
126130
# - the fabricated merge commit leaves go.mod, go.sum and vendor dir unchanged
127131
# - release-tools also didn't change (changing rules or Go version might lead to
128132
# a different result and thus must be tested)
133+
# - import statements not changed (because if they change, go.mod might have to be updated)
134+
#
135+
# "git diff" is intelligent enough to annotate changes inside the "import" block in
136+
# the start of the diff hunk:
137+
#
138+
# diff --git a/rpc/common.go b/rpc/common.go
139+
# index bb4a5c4..5fa4271 100644
140+
# --- a/rpc/common.go
141+
# +++ b/rpc/common.go
142+
# @@ -21,7 +21,6 @@ import (
143+
# "fmt"
144+
# "time"
145+
#
146+
# - "google.golang.org/grpc"
147+
# "google.golang.org/grpc/codes"
148+
# "google.golang.org/grpc/status"
149+
#
150+
# We rely on that to find such changes.
151+
#
152+
# Vendoring is optional when using go.mod.
129153
.PHONY: test-vendor
130154
test: test-vendor
131155
test-vendor:
@@ -136,22 +160,37 @@ test-vendor:
136160
*v0.[56789]*) dep check && echo "vendor up-to-date" || false;; \
137161
*) echo "skipping check, dep >= 0.5 required";; \
138162
esac; \
139-
else \
140-
echo "Repo uses 'go mod' for vendoring."; \
163+
elif [ -f go.mod ]; then \
164+
echo "Repo uses 'go mod'."; \
141165
if [ "$${JOB_NAME}" ] && \
142166
( [ "$${JOB_TYPE}" != "presubmit" ] || \
143-
[ $$(git diff "${PULL_BASE_SHA}..HEAD" -- go.mod go.sum vendor release-tools | wc -l) -eq 0 ] ); then \
144-
echo "Skipping vendor check because the Prow pre-submit job does not change vendoring."; \
145-
elif ! GO111MODULE=on go mod vendor; then \
167+
[ $$( (git diff "${PULL_BASE_SHA}..HEAD" -- go.mod go.sum vendor release-tools; \
168+
git diff "${PULL_BASE_SHA}..HEAD" | grep -e '^@@.*@@ import (' -e '^[+-]import') | \
169+
wc -l) -eq 0 ] ); then \
170+
echo "Skipping vendor check because the Prow pre-submit job does not affect dependencies."; \
171+
elif ! GO111MODULE=on go mod tidy; then \
146172
echo "ERROR: vendor check failed."; \
147173
false; \
148-
elif [ $$(git status --porcelain -- vendor | wc -l) -gt 0 ]; then \
149-
echo "ERROR: vendor directory *not* up-to-date, it did get modified by 'GO111MODULE=on go mod vendor':"; \
150-
git status -- vendor; \
151-
git diff -- vendor; \
174+
elif [ $$(git status --porcelain -- go.mod go.sum | wc -l) -gt 0 ]; then \
175+
echo "ERROR: go module files *not* up-to-date, they did get modified by 'GO111MODULE=on go mod tidy':"; \
176+
git diff -- go.mod go.sum; \
152177
false; \
178+
elif [ -d vendor ]; then \
179+
if ! GO111MODULE=on go mod vendor; then \
180+
echo "ERROR: vendor check failed."; \
181+
false; \
182+
elif [ $$(git status --porcelain -- vendor | wc -l) -gt 0 ]; then \
183+
echo "ERROR: vendor directory *not* up-to-date, it did get modified by 'GO111MODULE=on go mod vendor':"; \
184+
git status -- vendor; \
185+
git diff -- vendor; \
186+
false; \
187+
else \
188+
echo "Go dependencies and vendor directory up-to-date."; \
189+
fi; \
190+
else \
191+
echo "Go dependencies up-to-date."; \
153192
fi; \
154-
fi;
193+
fi
155194

156195
.PHONY: test-subtree
157196
test: test-subtree

release-tools/go-get-kubernetes.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2019 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+
# This script can be used while converting a repo from "dep" to "go mod"
18+
# by calling it after "go mod init" or to update the Kubernetes packages
19+
# in a repo that has already been converted. Only packages that are
20+
# part of kubernetes/kubernetes and thus part of a Kubernetes release
21+
# are modified. Other k8.io packages (like k8s.io/klog, k8s.io/utils)
22+
# need to be updated separately.
23+
24+
set -o pipefail
25+
26+
cmd=$0
27+
28+
function help () {
29+
echo "$cmd <kubernetes version = x.y.z> - update all components from kubernetes/kubernetes to that version"
30+
}
31+
32+
if [ $# -ne 1 ]; then
33+
help
34+
exit 1
35+
fi
36+
case "$1" in -h|--help|help) help; exit 0;; esac
37+
38+
die () {
39+
echo >&2 "$@"
40+
exit 1
41+
}
42+
43+
k8s="$1"
44+
45+
# If the repo imports k8s.io/kubernetes (directly or indirectly), then
46+
# "go mod" will try to find "v0.0.0" versions because
47+
# k8s.io/kubernetes has those in it's go.mod file
48+
# (https://github.com/kubernetes/kubernetes/blob/2bd9643cee5b3b3a5ecbd3af49d09018f0773c77/go.mod#L146-L157).
49+
# (https://github.com/kubernetes/kubernetes/issues/79384).
50+
#
51+
# We need to replicate the replace statements to override those fake
52+
# versions also in our go.mod file (idea and some code from
53+
# https://github.com/kubernetes/kubernetes/issues/79384#issuecomment-521493597).
54+
mods=$( (set -x; curl --silent --show-error --fail "https://raw.githubusercontent.com/kubernetes/kubernetes/v${k8s}/go.mod") |
55+
sed -n 's|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p'
56+
) || die "failed to determine Kubernetes staging modules"
57+
for mod in $mods; do
58+
# The presence of a potentially incomplete go.mod file affects this command,
59+
# so move elsewhere.
60+
modinfo=$(set -x; cd /; env GO111MODULE=on go mod download -json "$mod@kubernetes-${k8s}") ||
61+
die "failed to determine version of $mod: $modinfo"
62+
v=$(echo "$modinfo" | sed -n 's|.*"Version": "\(.*\)".*|\1|p')
63+
(set -x; env GO111MODULE=on go mod edit "-replace=$mod=$mod@$v") || die "'go mod edit' failed"
64+
done
65+
66+
packages=
67+
68+
# Beware that we have to work with packages, not modules (i.e. no -m
69+
# flag), because some modules trigger a "no Go code except tests"
70+
# error. Getting their packages works.
71+
if ! packages=$( (set -x; env GO111MODULE=on go list all) | grep ^k8s.io/ | sed -e 's; *;;'); then
72+
cat >&2 <<EOF
73+
74+
Warning: "GO111MODULE=on go list all" failed, trying individual packages instead.
75+
76+
EOF
77+
if ! packages=$( (set -x; env GO111MODULE=on go list -f '{{ join .Deps "\n" }}' ./...) | grep ^k8s.io/); then
78+
cat >&2 <<EOF
79+
80+
ERROR: could not obtain package list, both of these commands failed:
81+
GO111MODULE=on go list all
82+
GO111MODULE=on go list -f '{{ join .Deps "\n" }}' ./pkg/...
83+
EOF
84+
exit 1
85+
fi
86+
fi
87+
88+
deps=
89+
for package in $packages; do
90+
# Some k8s.io packages do not come from Kubernetes staging and
91+
# thus have different versioning (or none at all...). We need to
92+
# skip those. We know what packages are from staging because we
93+
# now have "replace" statements for them in go.mod.
94+
#
95+
# shellcheck disable=SC2001
96+
module=$(echo "$package" | sed -e 's;k8s.io/\([^/]*\)/.*;k8s.io/\1;')
97+
if grep -q -w "$module *=>" go.mod; then
98+
deps="$deps $(echo "$package" | sed -e "s;\$;@kubernetes-$k8s;" -e 's;^k8s.io/kubernetes\(/.*\)@kubernetes-;k8s.io/kubernetes\1@v;')"
99+
fi
100+
done
101+
102+
# shellcheck disable=SC2086
103+
(set -x; env GO111MODULE=on go get $deps 2>&1) || die "go get failed"
104+
echo "SUCCESS"

0 commit comments

Comments
 (0)