Skip to content

Commit a6f4771

Browse files
committed
Envtest Binary Version Manager Tool
This introduces an envtest binary manager tool. It can download binaries from GCS, list available versions, print out help for switching between them, and remove old ones. By default, it downloads binaries into an OS-specific cache directory, as per the OS's conventions, but this can be overridden.
1 parent 4aecab5 commit a6f4771

15 files changed

+2788
-0
lines changed

tools/setup-envtest/README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Envtest Binaries Manager
2+
3+
This is a small tool that manages binaries for envtest. It can be used to
4+
download new binaries, list currently installed and available ones, and
5+
clean up versions.
6+
7+
To use it, just go-install it on 1.16+ (it's a separate, self-contained
8+
module):
9+
10+
```shell
11+
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
12+
```
13+
14+
For full documentation, run it with the `--help` flag, but here are some
15+
examples:
16+
17+
```shell
18+
# download the latest envtest, and print out info about it
19+
setup-envtest use
20+
21+
# download the latest 1.19 envtest, and print out the path
22+
setup-envtest use -p path 1.19.x!
23+
24+
# switch to the most recent 1.21 envtest on disk
25+
source <(setup-envtest use -i -p env 1.21.x)
26+
27+
# list all available local versions for darwin/amd64
28+
setup-envtest list -i --os darwin --arch amd64
29+
30+
# remove all versions older than 1.16 from disk
31+
setup-envtest cleanup <1.16
32+
33+
# use the value from $KUBEBUILDER_ASSETS if set, otherwise follow the normal
34+
# logic for 'use'
35+
setup-envtest --use-env=always
36+
37+
# use the value from $KUBEBUILDER_ASSETS if set, otherwise use the latest
38+
# installed version
39+
setup-envtest use -i --use-env=always
40+
41+
# sideload a pre-downloaded tarball as Kubernetes 1.16.2 into our store
42+
setup-envtest sideload 1.16.2 < downloaded-envtest.tar.gz
43+
```
44+
45+
## Where does it put all those binaries?
46+
47+
By default, binaries are stored in an OS-specific cache directory, as per
48+
the OS's conventions (see Go's `os.UserCacheDir`).
49+
50+
For example, on Linux this is `$XDG_CACHE_DIR`, or just `~/.config` if
51+
that's unset.
52+
53+
There's an overall folder that holds all files, and inside that is
54+
a folder for each version/platform pair. The exact directory structure is
55+
not guarnateed, except that the leaf directory will contain the names
56+
expected by envtest. You should always use `setup-envtest fetch` or
57+
`setup-envtest switch` (generally with the `-p path` or `-p env` flags) to
58+
get the directory that you should use.
59+
60+
## What if I don't want to talk to the internet?
61+
62+
There are a few options.
63+
64+
First, you'll probably want to set the `-i/--installed` flag. If you want
65+
to avoid forgetting to set this flag, set the `ENVTEST_INSTALLED_ONLY`
66+
env variable, which will switch that flag on by default.
67+
68+
Then, you have a few options for managing your binaries:
69+
70+
- If you don't *really* want to manage with this tool, or you want to
71+
respect the $KUBEBUILDER_ASSETS variable if it's set to something
72+
outside the store, use the `use --use-env=always -i` command.
73+
74+
`--use-env=always` makes the command unconditionally use the value of
75+
KUBEBUILDER_ASSETS as long as it contains the required binaries, and
76+
`-i` indicates that we only ever want to work with installed binaries
77+
(no reaching out the the remote GCS storage).
78+
79+
As noted about, you can use `ENVTEST_INSTALLED_ONLY=true` to switch `-i`
80+
on by default, and you can use `ENVTEST_USE_ENV=always` to switch
81+
`--use-env=always` on by default.
82+
83+
- If you want to use this tool, but download your gziped tarballs
84+
separately, you can use the `sideload` command. You'll need to use the
85+
`-k/--version` flag to indicate which version you're sideloading.
86+
87+
After that, it'll be as if you'd installed the binaries with `use`.
88+
89+
- If you want to talk to some internal source, you can use the
90+
`--remote-bucket` and `--remote-server` options. The former sets which
91+
GCS bucket to download from, and the latter sets the host to talk to as
92+
if it were a GCS endpoint. Theoretically, you could use the latter
93+
version to run an internal "mirror" -- the tool expects
94+
95+
- `HOST/storage/v1/b/BUCKET/o` to return JSON like
96+
97+
```json
98+
{"items": [
99+
{"name": "kubebuilder-tools-X.Y.Z-os-arch.tar.gz", "md5Hash": "<base-64-encoded-md5-hash>"},
100+
{"name": "kubebuilder-tools-X.Y.Z-os-arch.tar.gz", "md5Hash": "<base-64-encoded-md5-hash>"},
101+
]}
102+
```
103+
104+
- `HOST/storage/v1/b/BUCKET/o/TARBALL_NAME` to return JSON like
105+
`{"name": "kubebuilder-tools-X.Y.Z-os-arch.tar.gz", "md5Hash": "<base-64-encoded-md5-hash>"}`
106+
107+
- `HOST/storage/v1/b/BUCKET/o/TARBALL_NAME?alt=media` to return the
108+
actual file contents

0 commit comments

Comments
 (0)