Skip to content

Commit c02b7b8

Browse files
tomlebaruiz14
andauthored
[v0.4] Pin dependencies (#1090)
* Add sha pinning to Dockerfile * Pin setup-envtest and envtest binaries * Update go mod gotools * Fix setup-envtest gotools mod path Co-authored-by: Alejandro Ruiz <4057165+aruiz14@users.noreply.github.com> * Fix gotools's README * Remove gotools envtest and use pinned go install * Pin envtest to v1.31.0 * Fix client-go version detection * Remove gotools * Pin envtest --------- Co-authored-by: Alejandro Ruiz <4057165+aruiz14@users.noreply.github.com>
1 parent 3722dd8 commit c02b7b8

5 files changed

Lines changed: 56 additions & 14 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ jobs:
2525
uses: golangci/golangci-lint-action@051d91933864810ecd5e2ea2cfd98f6a5bca5347 # v6.3.2
2626
with:
2727
version: v1.63.4
28-
- name: Install env-test
29-
run: go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
3028
- name: Build
3129
run: make build-bin
3230
- name: Test

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# syntax = docker/dockerfile:experimental
2-
FROM registry.suse.com/bci/golang:1.24 as build
2+
FROM registry.suse.com/bci/golang:1.24@sha256:ae722bb8954485d10eb26d90c14d521d90810d8b0c84c3c72b58cbb1fc1ee284 as build
33
COPY go.mod go.sum main.go /src/
44
COPY pkg /src/pkg/
55
#RUN --mount=type=cache,target=/root/.cache/go-build \
66
RUN \
77
cd /src && \
88
CGO_ENABLED=0 go build -ldflags "-extldflags -static -s" -o /steve
99

10-
FROM registry.suse.com/bci/bci-micro:15.6
10+
FROM registry.suse.com/bci/bci-micro:15.6@sha256:f6561730395434ac5da9284fc73c9476ab45108a7eace445f5295fba95e75cd0
1111

1212
ARG user=steve
1313

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ Some of steve's tests make use of [envtest](https://book.kubebuilder.io/referenc
803803
To install the required `setup-envtest` binary, use the following command:
804804
805805
```bash
806-
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
806+
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@f9589b9f2b9d
807807
```
808808
809809
Before running the tests, you must run the following command to setup the fake server:

scripts/install-envtest.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# The envtest version and SHAs can be found here: https://raw.githubusercontent.com/kubernetes-sigs/controller-tools/HEAD/envtest-releases.yaml
5+
6+
ENVTEST_VERSION=v1.31.0
7+
ENVTEST_SUM_linux_amd64=5d96ae284610863ce5974e030aecd2eaad693f3210103ca778107aa0ea00f6f1d0a7b1b34aa74d7257cb0d7f713c2da365beba89b1d60823ce56c7b84b935423
8+
ENVTEST_SUM_linux_arm64=72f5c8fd615c9db62eeb66e30edfda0f3879bffa3577c5776ec83363c018d7f51c174ac5ea807414072a21f8151a7bdf9826f414543f690686550e49db202ca0
9+
ENVTEST_SUM_darwin_amd64=d681838609a1b0856e731888e0db0a1191003e1021801b5969b7d7084130076b30b2d99e53e460f1c5202b3308354a2118bd4a330d06d97797ef009dd56e256e
10+
ENVTEST_SUM_darwin_arm64=e42c27e1ee90d13d56189e665d4c79b7a34f637581fc7e20b028a3c16b22b85060760eb91ca79901bc1c22dcd0d66ef41a0f760c2f1ae65265f0576e4109d87d
11+
12+
CLIENT_GO_MINOR=$(go list -m -f '{{if .Replace}}{{.Replace.Version}}{{else}}{{.Version}}{{end}}' k8s.io/client-go | cut -d . -f 2)
13+
ENVTEST_MINOR=$(echo "$ENVTEST_VERSION" | cut -d '.' -f 2)
14+
15+
if [ "$CLIENT_GO_MINOR" != "$ENVTEST_MINOR" ]; then
16+
echo "k8s.io/client-go minor version ($CLIENT_GO_MINOR) does not match envtest minor version ($ENVTEST_MINOR)" >&2
17+
exit 1
18+
fi
19+
20+
if ! command -v setup-envtest >/dev/null; then
21+
echo "Installing setup-envtest..."
22+
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@52b17917caa97ec546423867d9637f1787830f3e
23+
fi
24+
25+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
26+
ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')
27+
28+
eval "ENVTEST_SUM=\$ENVTEST_SUM_${OS}_${ARCH}"
29+
30+
if [ -z "$ENVTEST_SUM" ]; then
31+
echo "Unsupported platform: ${OS}-${ARCH}" >&2
32+
exit 1
33+
fi
34+
35+
TARBALL="envtest-${ENVTEST_VERSION}-${OS}-${ARCH}.tar.gz"
36+
URL="https://github.com/kubernetes-sigs/controller-tools/releases/download/envtest-${ENVTEST_VERSION}/${TARBALL}"
37+
DEST="/tmp/${TARBALL}"
38+
39+
SEMVER=${ENVTEST_VERSION#v}
40+
41+
if ! setup-envtest list -i | grep -q "v${SEMVER}"; then
42+
curl -sL -o "$DEST" "$URL"
43+
44+
echo "${ENVTEST_SUM} ${DEST}" | sha512sum --check > /dev/null
45+
46+
cat "$DEST" | setup-envtest sideload "${SEMVER}" > /dev/null
47+
fi

scripts/test.sh

100644100755
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
#!/bin/bash
1+
#!/bin/sh
2+
set -e
23

3-
if ! command -v setup-envtest; then
4-
echo "setup-envtest is required for tests, but was not installed"
5-
echo "see the 'Running Tests' section of the readme for install instructions"
6-
exit 127
7-
fi
4+
./scripts/install-envtest.sh
85

9-
minor=$(go list -m all | grep 'k8s.io/client-go' | cut -d ' ' -f 2 | cut -d '.' -f 2)
10-
version="1.$minor.x"
6+
ENVTEST_VERSION=$(grep '^ENVTEST_VERSION=' scripts/install-envtest.sh | cut -d= -f2)
7+
SEMVER=${ENVTEST_VERSION#v}
118

12-
export KUBEBUILDER_ASSETS=$(setup-envtest use -p path "$version")
9+
export KUBEBUILDER_ASSETS=$(setup-envtest use -p path -i "${SEMVER}")
1310
go test ./...

0 commit comments

Comments
 (0)