|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2022 The Kubernetes Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# This script is a helper script to install envtest |
| 18 | +# (https://github.com/kubernetes-sigs/controller-runtime/tree/master/pkg/envtest) |
| 19 | +# Mostly used by CI but can also be used for running integration tests locally. |
| 20 | +# Usage: `hack/install-envtest.sh`. |
| 21 | + |
| 22 | +set -o errexit |
| 23 | +set -o nounset |
| 24 | +set -o pipefail |
| 25 | + |
| 26 | +SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. |
| 27 | +source "${SCRIPT_ROOT}/hack/lib/init.sh" |
| 28 | + |
| 29 | +# setup-envtest requires the version to be in the form of X.Y(.Z) (e.g. 1.23 or 1.23.3) |
| 30 | +# thus we want to remove the 'v' from the version extracted out of the go.mod file |
| 31 | +version=$(cat ${SCRIPT_ROOT}/go.mod | grep 'k8s.io/kubernetes' | grep -v '=>' | awk '{print $NF}' | awk 'BEGIN{FS=OFS="."}NF--' | sed 's/v//') |
| 32 | + |
| 33 | +GOPATH=$(go env GOPATH) |
| 34 | +TEMP_DIR=${TMPDIR-/tmp} |
| 35 | +# this is the last version before the bump golang 1.20 -> 1.22. We want to avoid the go.mod version format changes - for now. |
| 36 | +go install sigs.k8s.io/controller-runtime/tools/ [email protected] |
| 37 | +"${GOPATH}"/bin/setup-envtest use -p env "${version}" > "${TEMP_DIR}/setup-envtest" |
| 38 | + |
0 commit comments