Skip to content

Commit c975d37

Browse files
committed
workflows/e2e: Use local envtest github action
Use local actions/envtest to setup envtest. The envtest action downloads the envtest binaries for a given version inside a container and moves them to the host. The binaries also include the setup-envtest binary. The env var KUBEBUILDER_ASSETS is also set to the directory containing the envtest binaries. The cache in /github/home/.cache populated when installing setup-envtest causes the builds to fail in `make test` target due to the cached go build files, maybe due to some incompatibilities. Deleting them at the end of the action helps avoid affecting other build steps in the workflow. Since the run-test action runs in a container, the host $PATH is not passed to the test container. The ENV directive in Dockerfile is used to append the PATH with envtest binary path. This helps avoid redownload of the envtest binaries when it's not found in the path via the Makefile targets. Signed-off-by: Sunny <darkowlzz@protonmail.com>
1 parent 4ce7c0d commit c975d37

File tree

5 files changed

+54
-7
lines changed

5 files changed

+54
-7
lines changed

.github/actions/envtest/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM golang:1.16-buster
2+
3+
COPY entrypoint.sh /entrypoint.sh
4+
RUN chmod +x /entrypoint.sh
5+
6+
ENTRYPOINT ["/entrypoint.sh"]

.github/actions/envtest/action.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Setup envtest
2+
description: A GitHub Action for setting up controller-runtime envtest
3+
author: Flux authors
4+
branding:
5+
color: blue
6+
icon: command
7+
inputs:
8+
version:
9+
description: 'Kubernetes version'
10+
required: false
11+
default: "latest"
12+
runs:
13+
using: docker
14+
image: Dockerfile
15+
args:
16+
- ${{ inputs.version }}

.github/actions/envtest/entrypoint.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
# envtest kubernetes version.
6+
VERSION=${1:-latest}
7+
8+
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
9+
setup-envtest use $VERSION
10+
11+
ENVTEST_DIR=$(setup-envtest use -i $VERSION -p path)
12+
SETUP_ENVTEST_PATH=$(which setup-envtest)
13+
14+
mkdir -p $GITHUB_WORKSPACE/envtest
15+
mv $ENVTEST_DIR/* $GITHUB_WORKSPACE/envtest
16+
mv $SETUP_ENVTEST_PATH $GITHUB_WORKSPACE/envtest
17+
ls -lh $GITHUB_WORKSPACE/envtest
18+
19+
echo "$GITHUB_WORKSPACE/envtest" >> $GITHUB_PATH
20+
echo "$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/envtest" >> $GITHUB_PATH
21+
echo "KUBEBUILDER_ASSETS=$GITHUB_WORKSPACE/envtest" >> $GITHUB_ENV
22+
23+
# Cleanup cache to avoid affecting other builds. Some go builds may get
24+
# affected by this cache populated in the above operations.
25+
rm -rf /github/home/.cache

.github/actions/run-tests/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ RUN set -eux; \
1717
RUN groupadd -g 116 test && \
1818
useradd -u 1001 --gid test --shell /bin/sh --create-home test
1919

20+
# Set path to envtest binaries.
21+
ENV PATH="/github/workspace/envtest:${PATH}"
22+
2023
# Run as test user
2124
USER test
2225

.github/workflows/e2e.yaml

+4-7
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ jobs:
2626
image: kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
2727
- name: Setup Kustomize
2828
uses: fluxcd/pkg/actions/kustomize@main
29-
- name: Setup Kubebuilder
30-
uses: fluxcd/pkg/actions/kubebuilder@main
29+
- name: Setup envtest
30+
uses: ./.github/actions/envtest
31+
with:
32+
version: "1.19.2"
3133
- name: Setup Helm
3234
uses: fluxcd/pkg/actions/helm@main
3335
- name: Run tests
3436
uses: ./.github/actions/run-tests
3537
env:
3638
GOPATH: /github/home/go
37-
KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin
3839
- name: Check if working tree is dirty
3940
run: |
4041
if [[ $(git diff --stat) != '' ]]; then
@@ -44,14 +45,10 @@ jobs:
4445
fi
4546
- name: Build container image
4647
run: make docker-build IMG=test/source-controller:latest
47-
env:
48-
KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin
4948
- name: Load test image
5049
run: kind load docker-image test/source-controller:latest
5150
- name: Deploy controller
5251
run: make dev-deploy IMG=test/source-controller:latest
53-
env:
54-
KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin
5552
- name: Run smoke tests
5653
run: |
5754
kubectl -n source-system apply -f ./config/samples

0 commit comments

Comments
 (0)