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
Copy file name to clipboardExpand all lines: docs/book/src/reference/envtest.md
+41-26Lines changed: 41 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,48 @@
1
1
# Configuring envtest for integration tests
2
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.
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
4
+
Kubernetes API server, without kubelet, controller-manager or other components.
4
5
5
6
## Installation
6
7
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.
8
+
Installing the binaries is as a simple as running `make envtest`. `envtest` will download the Kubernetes API server binaries to the `bin/` folder in your project
9
+
by default. `make test` is the one-stop shop for downloading the binaries, setting up the test environment, and running the tests.
12
10
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.21.2 is an example version):
## Installation in Air Gaped/disconnected environments
14
+
If you would like to download the tarball containing the binaries, to use in a disconnected environment you can use
15
+
`setup-envtest` to download the required binaries locally. There are a lot of ways to configure `setup-envtest` to avoid talking to
16
+
the internet you can read about them [here](https://github.com/kubernetes-sigs/controller-runtime/tree/master/tools/setup-envtest#what-if-i-dont-want-to-talk-to-the-internet).
17
+
The examples below will show how to install the Kubernetes API binaries using mostly defaults set by `setup-envtest`.
21
18
22
-
Then install them:
19
+
### Download the binaries
20
+
`make envtest` will download the `setup-envtest` binary to `./bin/`.
21
+
```shell
22
+
make envtest
23
+
```
23
24
25
+
Installing the binaries using `setup-envtest` stores the binary in OS specific locations, you can read more about them
NOTE: The `ENVTEST_K8S_VERSION` needs to match the `setup-envtest` you downloaded above. Otherwise, you will see an error like the below
38
41
```sh
39
-
make test SKIP_FETCH_TOOLS=1 KUBEBUILDER_ASSETS=/usr/local/kubebuilder
42
+
no such version (1.24.5) exists on disk for this architecture (darwin/amd64) -- try running `list -i` to see what's on disk
40
43
```
41
44
42
-
###Kubernetes 1.20 and 1.21 binary issues
45
+
## Kubernetes 1.20 and 1.21 binary issues
43
46
44
47
There have been many reports of the `kube-apiserver` or `etcd` binary [hanging during cleanup][cr-1571]
45
48
or misbehaving in other ways. We recommend using the 1.19.2 tools version to circumvent such issues,
@@ -77,7 +80,17 @@ Logs from the test runs are prefixed with `test-env`.
77
80
78
81
Controller-runtime’s [envtest][envtest] framework requires `kubectl`, `kube-apiserver`, and `etcd` binaries be present locally to simulate the API portions of a real cluster.
79
82
80
-
For projects built with plugin v3+ (see your PROJECT file's `layout` key), the `make test` command will install these binaries to the `testbin/` directory and use them when running tests that use `envtest`.
83
+
The `make test` command will install these binaries to the `bin/` directory and use them when running tests that use `envtest`.
84
+
Ie,
85
+
```shell
86
+
./bin/k8s/
87
+
└── 1.24.2-darwin-amd64
88
+
├── etcd
89
+
├── kube-apiserver
90
+
└── kubectl
91
+
92
+
1 directory, 3 files
93
+
```
81
94
82
95
You can use environment variables and/or flags to specify the `kubectl`,`api-server` and `etcd` setup within your integration tests.
83
96
@@ -95,9 +108,11 @@ See that the `test` makefile target will ensure that all is properly setup when
0 commit comments