Skip to content

Commit 7b16f4c

Browse files
committed
Update to Go 1.20 and latest KRTE for e2e tests
E2Es broke a few days ago, likely when test-infra upgraded to 1.20. I also couldn't run staticcheck on my Google workstation, which has 1.20, with the same failure message. Upgrading staticcheck fixed the problem; I also took the opportunity to match the test-infra krte image as well as the Golang version (which caused some minor reformatting), and also made the integ tests hermetic by including the setup-envtest tool (bug kubernetes-retired#252, based on an approach suggested in kubernetes-retired#253). Tested: couldn't build on my workstation on Go 1.20 before this change; can after it. Can also run integ tests after deleting local output of setup-envtest.
1 parent 3dac447 commit 7b16f4c

File tree

492 files changed

+46435
-12010
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

492 files changed

+46435
-12010
lines changed

Makefile

+18-9
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ CONTROLLER_GEN ?= ${CURDIR}/bin/controller-gen
8282

8383
STATICCHECK ?= ${CURDIR}/bin/staticcheck
8484

85+
# This really could be left blank, and setup-envtest would just download the
86+
# latest. But we may as well make it hermetic-ish by always downloading the
87+
# same version. I doubt the version matters much (or at all).
88+
ENVTEST_K8S_VERSION ?= 1.26.0
89+
SETUP_ENVTEST ?= ${CURDIR}/bin/setup-envtest
90+
8591
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8692
GOBIN ?= $(shell go env GOPATH)/bin
8793

@@ -100,12 +106,9 @@ all: test docker-build
100106
# Run tests
101107
test: build test-only
102108

103-
test-only:
104-
@echo
105-
@echo "If tests fail due to no matches for kind \"CustomResourceDefinition\" in version \"apiextensions.k8s.io/v1\","
106-
@echo "please remove the old kubebuilder and reinstall it - https://book.kubebuilder.io/quick-start.html#installation"
107-
@echo
108-
go test ${DIRS} -coverprofile cover.out
109+
test-only: build-setup-envtest
110+
KUBEBUILDER_ASSETS="$(shell ${SETUP_ENVTEST} use ${ENVTEST_K8S_VERSION} --bin-dir ${CURDIR}/bin -p path)" \
111+
go test ${DIRS} -coverprofile cover.out
109112

110113
# Builds all binaries (manager and kubectl) and manifests
111114
build: generate fmt vet staticcheck manifests
@@ -160,7 +163,7 @@ run: build
160163
#
161164
# We build the full manifest last so that the kustomization.yaml file is still
162165
# there in case you want to rerun it manually.
163-
manifests: controller-gen
166+
manifests: build-controller-gen
164167
@echo "Building manifests with image ${HNC_IMG}"
165168
@# See the comment above about the 'paths' arguments
166169
$(CONTROLLER_GEN) crd rbac:roleName=manager-role webhook paths="./api/..." paths="./cmd/..." paths="./internal/..." output:crd:artifacts:config=config/crd/bases
@@ -189,6 +192,8 @@ manifests: controller-gen
189192

190193
# Run go fmt against code
191194
fmt:
195+
@echo "Go version (for logging posterity):"
196+
@go version
192197
gofmt -l -w ${GOFMT_DIRS}
193198

194199
# check-fmt: Checks gofmt/go fmt has been ran. gofmt -l lists files whose formatting differs from gofmt's, so it fails if there are unformatted go code.
@@ -206,10 +211,11 @@ staticcheck: build-staticcheck
206211
$(STATICCHECK) ${DIRS}
207212

208213
build-staticcheck:
214+
@echo "If this next step fails, try updating honnef.co/go/tools in go.mod"
209215
go build -o $(STATICCHECK) honnef.co/go/tools/cmd/staticcheck
210216

211217
# Generate code
212-
generate: controller-gen
218+
generate: build-controller-gen
213219
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/...
214220

215221
check-generate: generate
@@ -219,9 +225,12 @@ check-generate: generate
219225

220226
# Use the version of controller-gen that's checked into vendor/ (see
221227
# hack/tools.go to see how it got there).
222-
controller-gen:
228+
build-controller-gen:
223229
go build -o $(CONTROLLER_GEN) sigs.k8s.io/controller-tools/cmd/controller-gen
224230

231+
build-setup-envtest:
232+
go build -o $(SETUP_ENVTEST) sigs.k8s.io/controller-runtime/tools/setup-envtest
233+
225234
###################### DEPLOYABLE ARTIFACTS AND ACTIONS #########################
226235

227236
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config.

go.mod

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
module sigs.k8s.io/hierarchical-namespaces
22

3-
go 1.17
3+
go 1.20
44

55
require (
66
contrib.go.opencensus.io/exporter/prometheus v0.4.0
77
contrib.go.opencensus.io/exporter/stackdriver v0.13.0
88
github.com/go-logr/logr v1.2.0
99
github.com/go-logr/zapr v1.2.0
1010
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
11-
github.com/onsi/ginkgo/v2 v2.1.3
11+
github.com/onsi/ginkgo/v2 v2.1.4
1212
github.com/onsi/gomega v1.19.0
1313
github.com/open-policy-agent/cert-controller v0.2.1-0.20220125035755-54af89450964
1414
github.com/spf13/cobra v1.2.1
1515
go.opencensus.io v0.23.0
1616
go.uber.org/zap v1.19.1
17-
honnef.co/go/tools v0.3.0
17+
honnef.co/go/tools v0.4.0
1818
k8s.io/api v0.23.2
1919
k8s.io/apiextensions-apiserver v0.23.2
2020
k8s.io/apimachinery v0.23.2
@@ -32,7 +32,7 @@ require (
3232
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
3333
github.com/Azure/go-autorest/logger v0.2.1 // indirect
3434
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
35-
github.com/BurntSushi/toml v0.4.1 // indirect
35+
github.com/BurntSushi/toml v1.2.1 // indirect
3636
github.com/PuerkitoBio/purell v1.1.1 // indirect
3737
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
3838
github.com/aws/aws-sdk-go v1.23.20 // indirect
@@ -89,16 +89,16 @@ require (
8989
go.uber.org/atomic v1.7.0 // indirect
9090
go.uber.org/multierr v1.6.0 // indirect
9191
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
92-
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e // indirect
93-
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
94-
golang.org/x/net v0.0.0-20220403103023-749bd193bc2b // indirect
92+
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
93+
golang.org/x/mod v0.7.0 // indirect
94+
golang.org/x/net v0.3.0 // indirect
9595
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
96-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
97-
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12 // indirect
98-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
99-
golang.org/x/text v0.3.7
96+
golang.org/x/sync v0.1.0 // indirect
97+
golang.org/x/sys v0.3.0 // indirect
98+
golang.org/x/term v0.3.0 // indirect
99+
golang.org/x/text v0.5.0
100100
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
101-
golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a // indirect
101+
golang.org/x/tools v0.4.1-0.20221208213631-3f74d914ae6d // indirect
102102
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
103103
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
104104
google.golang.org/api v0.44.0 // indirect
@@ -119,3 +119,8 @@ require (
119119
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
120120
sigs.k8s.io/yaml v1.3.0 // indirect
121121
)
122+
123+
require (
124+
github.com/spf13/afero v1.6.0 // indirect
125+
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20230208013708-22718275bffe // indirect
126+
)

0 commit comments

Comments
 (0)