You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To allow downloading the newer versions of the Kubernetes binaries required by Envtest into the `testbin/` directory of your project instead of the global setup, replace:
402
402
403
-
```
403
+
```makefile
404
404
# Run tests
405
405
test: generate fmt vet manifests
406
406
go test ./... -coverprofile cover.out
407
407
```
408
408
409
409
With:
410
410
411
-
```
411
+
```makefile
412
+
# Setting SHELL to bash allows bash commands to be executed by recipes.
413
+
# This is a requirement for 'setup-envtest.sh' in the test target.
414
+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
415
+
SHELL = /usr/bin/env bash -o pipefail
416
+
.SHELLFLAGS = -ec
417
+
412
418
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
413
419
test: manifests generate fmt vet ## Run tests.
414
420
mkdir -p ${ENVTEST_ASSETS_DIR}
415
-
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
421
+
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.8.3/hack/setup-envtest.sh
416
422
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
417
423
```
418
424
419
425
<aside class="note">
420
426
<h1>Envtest binaries</h1>
421
427
422
-
The Kubernetes binaries that are required for the Envtest were upgraded from `1.16.4` to `1.19.2`. You can still install them globally by running:
423
-
424
-
```
425
-
os=$(go env GOOS)
426
-
arch=$(go env GOARCH)
427
-
428
-
# download kubebuilder and extract it to tmp
429
-
curl -LO https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-1.19.2-${os}-${arch}.tar.gz | tar -xz -C /tmp/
430
-
431
-
# move to a long-term location and put it on your path
432
-
# (you'll need to set the KUBEBUILDER_ASSETS env var if you put it somewhere else)
Copy file name to clipboardExpand all lines: docs/book/src/reference/envtest.md
+44-1Lines changed: 44 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,45 @@
1
1
# Configuring envtest for integration tests
2
-
[`controller-runtime`](http://sigs.k8s.io/controller-runtime) offers `envtest` ([godoc](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest?tab=doc)), a package that helps write integration tests for your controllers by setting up and starting an instance of etcd and the Kubernetes API server, without kubelet, controller-manager or other components.
2
+
3
+
The [`controller-runtime/pkg/envtest`][envtest] Go library helps write integration tests for your controllers by setting up and starting an instance of etcd and the Kubernetes API server, without kubelet, controller-manager or other components.
4
+
5
+
## Installation
6
+
7
+
The `test` make target, also called by the `docker-build` target,
8
+
[downloads][setup-envtest] a set of envtest binaries (described above) to run tests with.
9
+
Typically nothing needs to be done on your part,
10
+
as the download and install script is fully automated,
11
+
although it does require `bash` to run.
12
+
13
+
If you would like to download the tarball containing these binaries,
14
+
to use in a disconnected environment for example,
15
+
run the following (Kubernetes version 1.19.2 is an example version):
0 commit comments