Skip to content

Commit df688e1

Browse files
committed
Use setup-envtest from CR main (07.05.2024) to use envtest binaries from
CT releases Signed-off-by: Stefan Büringer [email protected]
1 parent 439e970 commit df688e1

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ CAPD_DIR := $(TEST_DIR)/infrastructure/docker
6666
CAPIM_DIR := $(TEST_DIR)/infrastructure/inmemory
6767
TEST_EXTENSION_DIR := $(TEST_DIR)/extension
6868
GO_INSTALL := ./scripts/go_install.sh
69+
GO_TOOLS_BUILD := ./hack/go-tools-build.sh
6970
OBSERVABILITY_DIR := hack/observability
7071

7172
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
@@ -101,7 +102,7 @@ KUSTOMIZE_BIN := kustomize
101102
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER))
102103
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v5
103104

104-
SETUP_ENVTEST_VER := v0.0.0-20240215143116-d0396a3d6f9f
105+
SETUP_ENVTEST_VER := v0.0.0-20240506183901-d950bb92291d
105106
SETUP_ENVTEST_BIN := setup-envtest
106107
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER))
107108
SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest
@@ -1456,7 +1457,7 @@ $(KUSTOMIZE): # Build kustomize from tools folder.
14561457
CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)
14571458

14581459
$(SETUP_ENVTEST): # Build setup-envtest from tools folder.
1459-
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(SETUP_ENVTEST_PKG) $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER)
1460+
GOBIN=$(TOOLS_BIN_DIR) $(GO_TOOLS_BUILD) $(SETUP_ENVTEST_PKG) $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER)
14601461

14611462
$(TILT_PREPARE): $(TOOLS_DIR)/go.mod # Build tilt-prepare from tools folder.
14621463
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/tilt-prepare sigs.k8s.io/cluster-api/hack/tools/internal/tilt-prepare

hack/go-tools-build.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2023 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
if [ -z "${1}" ]; then
21+
echo "must provide module as first parameter"
22+
exit 1
23+
fi
24+
25+
if [ -z "${2}" ]; then
26+
echo "must provide binary name as second parameter"
27+
exit 1
28+
fi
29+
30+
if [ -z "${3}" ]; then
31+
echo "must provide version as third parameter"
32+
exit 1
33+
fi
34+
35+
if [ -z "${GOBIN}" ]; then
36+
echo "GOBIN is not set. Must set GOBIN to install the bin in a specified directory."
37+
exit 1
38+
fi
39+
40+
rm -f "${GOBIN}/${2}"* || true
41+
42+
ORIGINAL_WORKDIR="$(pwd)"
43+
TMP_MODULE_DIR="${2}.tmp"
44+
45+
# Create TMP_MODULE_DIR to create a go module for building the binary.
46+
rm -r "${TMP_MODULE_DIR}" || true
47+
mkdir -p "${TMP_MODULE_DIR}"
48+
cd "${TMP_MODULE_DIR}"
49+
50+
# Initialize a go module and place a tools.go file for building the binary.
51+
go mod init "tools"
52+
# Set require for "sigs.k8s.io/cluster-api" to let go resolve the tools version via the CAPI version.
53+
go mod edit -replace "sigs.k8s.io/controller-runtime/tools/setup-envtest=github.com/sbueringer/controller-runtime/tools/[email protected]"
54+
55+
# Create go file which imports the required package and resolve dependencies.
56+
cat << EOF > tools.go
57+
//go:build tools
58+
// +build tools
59+
package tools
60+
61+
import (
62+
_ "${1}"
63+
)
64+
EOF
65+
66+
go mod tidy
67+
68+
# Build the binary.
69+
go build -tags=tools -o "${GOBIN}/${2}-${3}" "${1}"
70+
71+
# Get back to the original directory and cleanup the temporary directory.
72+
cd "${ORIGINAL_WORKDIR}"
73+
rm -r "${TMP_MODULE_DIR}"
74+
75+
# Link the unversioned name to the versioned binary.
76+
ln -sf "${GOBIN}/${2}-${3}" "${GOBIN}/${2}"

0 commit comments

Comments
 (0)