Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

build: Use setup-envtest to download later version of envtest #1519

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -76,7 +76,9 @@ all: container hyperfed controller kubefedctl webhook e2e

# Unit tests
test:
go test $(TEST_PKGS)
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
source <(setup-envtest use -p env 1.21.x) && \
go test $(TEST_PKGS)

build: hyperfed controller kubefedctl webhook

16 changes: 13 additions & 3 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -34,16 +34,26 @@ help you get started.
### Binaries

The KubeFed deployment depends on `kubebuilder`, `etcd`, `kubectl`, and
`kube-apiserver` >= v1.16 being installed in the path. The `kubebuilder`
([v2.3.1](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/v2.3.1)
as of this writing) release packages all of these dependencies together.
`kube-apiserver` >= v1.21. The `kubebuilder` release packages all of these
dependencies together and the `controller-runtime` project contains a helper
utility called `setup-envtest` that downloads required binaries and can also
set up required environment variables (especially `KUBEBUILDER_ASSETS`).

These binaries can be installed via the `download-binaries.sh` script, which
downloads them to `./bin`:

```bash
./scripts/download-binaries.sh
```

Running make targets will ensure that the `PATH` and other environment variables
are correctly configured for the build itself, but if you wish to configure your
local shell in the same way then run the following commands after running the
`download-binaries.sh` script above:

```bash
export PATH=$(pwd)/bin:${PATH}
source <(setup-envtest use -p env 1.21.x)
```

### kubernetes
18 changes: 16 additions & 2 deletions scripts/download-binaries.sh
Original file line number Diff line number Diff line change
@@ -49,15 +49,29 @@ kb_url="https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${kb_v
curl "${curl_args}" "${kb_url}" \
| tar xzP -C "${dest_dir}" --strip-components=2

export KUBEBUILDER_ASSETS="${dest_dir}"
echo "Setting to KUBEBUILDER_ASSETS ${dest_dir}"
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
source <(setup-envtest use -p env 1.21.x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as in #1516:

Why do we need to setup envtest here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kubebuilder releases used to bundle kubebuilder binary along with kube-apiserver, etcd, kubectl, etc. These stopped happening a long time ago, with version 2.3.2 iirc of kubebuilder (the version used in this project) bundling k8s v1.16 - too old for us now. Recent versions of kubebuilder no longer do that, instead distributing k8s binaries per version. Although you can define the URL to download directly, using setup-envtest is a convenience that allows you to not /discover know the URL and change the minor version to test against as this PR now does. It's just to make things easier tbh...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh you mean why here! Well strictly we don't I guess could remove it but it is just replacing what was here before downloading kubebuilder provided kube-apiserver, etc. I don't mind removing it if you think it's best to though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Yeah, with this line the behaviour would be retained. I'm fine either way.


echo "KUBEBUILDER_ASSETS is set to ${KUBEBUILDER_ASSETS}"

helm_version="3.6.0"
helm_tgz="helm-v${helm_version}-${platform}-amd64.tar.gz"
helm_url="https://get.helm.sh/$helm_tgz"
curl "${curl_args}" "${helm_url}" \
| tar xzP -C "${dest_dir}" --strip-components=1 "${platform}-amd64/helm"

kubectl_version="v1.21.14"
curl -Lo "${dest_dir}/kubectl" "https://dl.k8s.io/release/${kubectl_version}/bin/${platform}/amd64/kubectl"
(cd "${dest_dir}" && \
echo "$(curl -L "https://dl.k8s.io/release/${kubectl_version}/bin/${platform}/amd64/kubectl.sha256") kubectl" | \
sha256sum --check
)
chmod +x "${dest_dir}/kubectl"

kubebuilder_version="2.3.2"
curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${kubebuilder_version}/kubebuilder_${kubebuilder_version}_${platform}_amd64.tar.gz | \
tar xzP -C "${dest_dir}" --strip-components=2 -- "kubebuilder_${kubebuilder_version}_${platform}_amd64/bin/kubebuilder"

golint_version="1.40.1"
golint_dir="golangci-lint-${golint_version}-${platform}-amd64"
golint_tgz="${golint_dir}.tar.gz"