Skip to content

Commit

Permalink
Switch hack to use the new envtest tool
Browse files Browse the repository at this point in the history
We can now drop the `setup-envtest.sh` script, and instead just use
`source <(setup-envtest fetch -k ${version} -p env)` (plus a couple
lines to install setup-envtest ;-)).
  • Loading branch information
DirectXMan12 committed Apr 28, 2021
1 parent a6f4771 commit a70e98d
Show file tree
Hide file tree
Showing 17 changed files with 1,213 additions and 528 deletions.
19 changes: 15 additions & 4 deletions hack/check-everything.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,27 @@ set -o pipefail

hack_dir=$(dirname ${BASH_SOURCE})
source ${hack_dir}/common.sh
source ${hack_dir}/setup-envtest.sh

tmp_root=/tmp
kb_root_dir=$tmp_root/kubebuilder

ENVTEST_K8S_VERSION=${ENVTEST_K8S_VERSION:-"1.19.2"}

fetch_envtest_tools "$kb_root_dir"
fetch_envtest_tools "${hack_dir}/../pkg/internal/testing/integration/assets"
setup_envtest_env "$kb_root_dir"
# set up envtest tools if necessary

header_text "installing envtest tools@${ENVTEST_K8S_VERSION} with setup-envtest if necessary"
tmp_bin=/tmp/cr-tests-bin
(
# don't presume to install for the user
cd ${hack_dir}/../tools/setup-envtest
GOBIN=${tmp_bin} go install .
)
source <(${tmp_bin}/setup-envtest use --use-env -p env ${ENVTEST_K8S_VERSION})

# link the assets into integration
for tool in kube-apiserver etcd kubectl; do
ln -f -s "${KUBEBUILDER_ASSETS:?unable find envtest assets}/${tool}" "${hack_dir}/../pkg/internal/testing/integration/assets/bin/${tool}"
done

${hack_dir}/verify.sh
${hack_dir}/test-all.sh
Expand Down
96 changes: 0 additions & 96 deletions hack/setup-envtest.sh

This file was deleted.

33 changes: 23 additions & 10 deletions tools/setup-envtest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ setup-envtest cleanup <1.16

# use the value from $KUBEBUILDER_ASSETS if set, otherwise follow the normal
# logic for 'use'
setup-envtest --use-env=always
setup-envtest --use-env

# use the value from $KUBEBUILDER_ASSETS if set, otherwise use the latest
# installed version
setup-envtest use -i --use-env=always
setup-envtest use -i --use-env

# sideload a pre-downloaded tarball as Kubernetes 1.16.2 into our store
setup-envtest sideload 1.16.2 < downloaded-envtest.tar.gz
```

## Where does it put all those binaries?

By default, binaries are stored in an OS-specific cache directory, as per
the OS's conventions (see Go's `os.UserCacheDir`).
By default, binaries are stored in a subdirectory of an OS-specific data
directory, as per the OS's conventions.

For example, on Linux this is `$XDG_CACHE_DIR`, or just `~/.config` if
that's unset.
On Linux, this is `$XDG_DATA_HOME`; on Windows, `%LocalAppData`; and on
OSX, `~/Library/Application Support`.

There's an overall folder that holds all files, and inside that is
a folder for each version/platform pair. The exact directory structure is
Expand All @@ -57,6 +57,19 @@ expected by envtest. You should always use `setup-envtest fetch` or
`setup-envtest switch` (generally with the `-p path` or `-p env` flags) to
get the directory that you should use.

## Why do I have to do that `source <(blah blah blah)` thing

This is a normal binary, not a shell script, so we can't set the parent
process's environment variables. If you use this by hand a lot and want
to save the typing, you could put something like the following in your
`~/.bashrc` (or similar):

```shell
function setup-envtest() {
export KUBEBUILDER_ASSETS=$(GOPATH/bin/setup-envtest -p path $@)
}
```

## What if I don't want to talk to the internet?

There are a few options.
Expand All @@ -69,16 +82,16 @@ Then, you have a few options for managing your binaries:

- If you don't *really* want to manage with this tool, or you want to
respect the $KUBEBUILDER_ASSETS variable if it's set to something
outside the store, use the `use --use-env=always -i` command.
outside the store, use the `use --use-env -i` command.

`--use-env=always` makes the command unconditionally use the value of
`--use-env` makes the command unconditionally use the value of
KUBEBUILDER_ASSETS as long as it contains the required binaries, and
`-i` indicates that we only ever want to work with installed binaries
(no reaching out the the remote GCS storage).

As noted about, you can use `ENVTEST_INSTALLED_ONLY=true` to switch `-i`
on by default, and you can use `ENVTEST_USE_ENV=always` to switch
`--use-env=always` on by default.
on by default, and you can use `ENVTEST_USE_ENV=true` to switch
`--use-env` on by default.

- If you want to use this tool, but download your gziped tarballs
separately, you can use the `sideload` command. You'll need to use the
Expand Down

0 comments on commit a70e98d

Please sign in to comment.