Skip to content

Commit

Permalink
Use setup-envtest from CR main (07.05.2024) to use envtest binaries from
Browse files Browse the repository at this point in the history
CT releases

Signed-off-by: Stefan Büringer buringerst@vmware.com
  • Loading branch information
sbueringer committed May 7, 2024
1 parent 439e970 commit df688e1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ CAPD_DIR := $(TEST_DIR)/infrastructure/docker
CAPIM_DIR := $(TEST_DIR)/infrastructure/inmemory
TEST_EXTENSION_DIR := $(TEST_DIR)/extension
GO_INSTALL := ./scripts/go_install.sh
GO_TOOLS_BUILD := ./hack/go-tools-build.sh
OBSERVABILITY_DIR := hack/observability

export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
Expand Down Expand Up @@ -101,7 +102,7 @@ KUSTOMIZE_BIN := kustomize
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER))
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v5

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

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

$(TILT_PREPARE): $(TOOLS_DIR)/go.mod # Build tilt-prepare from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/tilt-prepare sigs.k8s.io/cluster-api/hack/tools/internal/tilt-prepare
Expand Down
76 changes: 76 additions & 0 deletions hack/go-tools-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

if [ -z "${1}" ]; then
echo "must provide module as first parameter"
exit 1
fi

if [ -z "${2}" ]; then
echo "must provide binary name as second parameter"
exit 1
fi

if [ -z "${3}" ]; then
echo "must provide version as third parameter"
exit 1
fi

if [ -z "${GOBIN}" ]; then
echo "GOBIN is not set. Must set GOBIN to install the bin in a specified directory."
exit 1
fi

rm -f "${GOBIN}/${2}"* || true

ORIGINAL_WORKDIR="$(pwd)"
TMP_MODULE_DIR="${2}.tmp"

# Create TMP_MODULE_DIR to create a go module for building the binary.
rm -r "${TMP_MODULE_DIR}" || true
mkdir -p "${TMP_MODULE_DIR}"
cd "${TMP_MODULE_DIR}"

# Initialize a go module and place a tools.go file for building the binary.
go mod init "tools"
# Set require for "sigs.k8s.io/cluster-api" to let go resolve the tools version via the CAPI version.
go mod edit -replace "sigs.k8s.io/controller-runtime/tools/setup-envtest=github.com/sbueringer/controller-runtime/tools/setup-envtest@v0.0.0-20240506183901-d950bb92291d"

# Create go file which imports the required package and resolve dependencies.
cat << EOF > tools.go
//go:build tools
// +build tools
package tools
import (
_ "${1}"
)
EOF

go mod tidy

# Build the binary.
go build -tags=tools -o "${GOBIN}/${2}-${3}" "${1}"

# Get back to the original directory and cleanup the temporary directory.
cd "${ORIGINAL_WORKDIR}"
rm -r "${TMP_MODULE_DIR}"

# Link the unversioned name to the versioned binary.
ln -sf "${GOBIN}/${2}-${3}" "${GOBIN}/${2}"

0 comments on commit df688e1

Please sign in to comment.