Skip to content

Commit 73def82

Browse files
committed
fix: Round 10 - Use official setup-envtest tool for Kubernetes test environment
The manual kubebuilder tools download was failing because the file doesn't exist at the assumed URL. The official approach is to use the setup-envtest tool from controller-runtime/tools. Changes: - Install setup-envtest using `go install` - Use setup-envtest to download and configure test binaries - Automatically sets KUBEBUILDER_ASSETS to the correct path - Removes manual tar extraction and URL guessing This is the recommended approach per kubebuilder documentation: https://book.kubebuilder.io/reference/envtest.html Files modified: - .github/workflows/test.yml (lines 175-188) - .github/workflows/reusable/build-test.yml (lines 85-98) Related: #CI-fixes
1 parent e51ac80 commit 73def82

2 files changed

Lines changed: 15 additions & 19 deletions

File tree

.github/workflows/reusable/build-test.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ jobs:
8787
run: |
8888
echo "Setting up test environment for ${{ inputs.test-type }} tests..."
8989
90-
# Download and extract kubebuilder test binaries
91-
# Use direct GCS URL to avoid redirect issues
92-
curl -sSLo envtest-bins.tar.gz "https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-1.31.1-linux-amd64.tar.gz"
93-
mkdir -p /tmp/kubebuilder/bin
94-
tar -C /tmp/kubebuilder --strip-components=1 -xzf envtest-bins.tar.gz
90+
# Install setup-envtest tool
91+
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
9592
96-
echo "KUBEBUILDER_ASSETS=/tmp/kubebuilder/bin" >> $GITHUB_ENV
93+
# Download and setup envtest binaries using official tool
94+
ENVTEST_K8S_VERSION=1.31.1 setup-envtest use -p env
95+
96+
# Export assets path
97+
echo "KUBEBUILDER_ASSETS=$(setup-envtest use -i -p path 1.31.1)" >> $GITHUB_ENV
9798
echo "USE_EXISTING_CLUSTER=false" >> $GITHUB_ENV
9899
99100
- name: Validate component path

.github/workflows/test.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,15 @@ jobs:
177177
run: |
178178
echo "Setting up Kubernetes test environment for ${{ matrix.component.name }}"
179179
180-
# Download and extract kubebuilder binaries
181-
# Use direct GCS URL to avoid redirect issues
182-
curl -sSLo envtest-bins.tar.gz "https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-${{ env.K8S_VERSION }}-linux-amd64.tar.gz"
183-
mkdir -p /tmp/kubebuilder/bin
184-
tar -C /tmp/kubebuilder --strip-components=1 -xzf envtest-bins.tar.gz
185-
186-
# Set environment variables
187-
echo "KUBEBUILDER_ASSETS=/tmp/kubebuilder/bin" >> $GITHUB_ENV
188-
echo "USE_EXISTING_CLUSTER=false" >> $GITHUB_ENV
180+
# Install setup-envtest tool
181+
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
182+
183+
# Download and setup envtest binaries using official tool
184+
ENVTEST_K8S_VERSION=${{ env.K8S_VERSION }} setup-envtest use -p env
189185
190-
# Verify installation
191-
ls -la /tmp/kubebuilder/bin/
192-
/tmp/kubebuilder/bin/etcd --version
193-
/tmp/kubebuilder/bin/kube-apiserver --version
186+
# Export assets path
187+
echo "KUBEBUILDER_ASSETS=$(setup-envtest use -i -p path ${{ env.K8S_VERSION }})" >> $GITHUB_ENV
188+
echo "USE_EXISTING_CLUSTER=false" >> $GITHUB_ENV
194189
195190
- name: Cache dependencies
196191
uses: actions/cache@v4

0 commit comments

Comments
 (0)