-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use setup-envtest from CR main (07.05.2024) to use envtest binaries from
CT releases Signed-off-by: Stefan Büringer buringerst@vmware.com
- Loading branch information
1 parent
439e970
commit df688e1
Showing
2 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |