Skip to content

Commit 129c394

Browse files
committed
hack/setup-envtest.sh: follow-up from kubernetes-sigs#1092
1 parent de782a3 commit 129c394

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

hack/check-everything.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ kb_root_dir=$tmp_root/kubebuilder
3232
# machine, but rebuild the kubebuilder and kubebuilder-bin binaries.
3333
SKIP_FETCH_TOOLS=${SKIP_FETCH_TOOLS:-""}
3434

35+
ENVTEST_K8S_VERSION=${ENVTEST_K8S_VERSION:-"1.16.4"}
3536

3637
if [ -z "$SKIP_FETCH_TOOLS" ]; then
37-
header_text "fetching envtest tools"
38+
header_text "fetching envtest tools@${ENVTEST_K8S_VERSION}"
3839
fetch_envtest_tools "$kb_root_dir"
3940
fetch_envtest_tools "${hack_dir}/../pkg/internal/testing/integration/assets"
4041
fi
4142

42-
header_text "setting up envtest environment"
43+
header_text "setting up envtest@${ENVTEST_K8S_VERSION}"
4344
setup_envtest_env "$kb_root_dir"
4445

4546
${hack_dir}/verify.sh

hack/setup-envtest.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,41 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
set -e
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
1820

1921
function setup_envtest_env {
2022
# Setup env vars
23+
KUBEBUILDER_ASSETS=${KUBEBUILDER_ASSETS:-""}
2124
if [[ -z "${KUBEBUILDER_ASSETS}" ]]; then
2225
export KUBEBUILDER_ASSETS=$1/bin
2326
fi
2427
}
2528

2629
# fetch k8s API gen tools and make it available under envtest_root_dir/bin.
30+
#
31+
# Skip fetching and untaring the tools by setting the SKIP_FETCH_TOOLS variable
32+
# in your environment to any value:
33+
#
34+
# $ SKIP_FETCH_TOOLS=1 ./check-everything.sh
35+
#
36+
# If you skip fetching tools, this script will use the tools already on your
37+
# machine.
2738
function fetch_envtest_tools {
39+
if [ -n "$SKIP_FETCH_TOOLS" ]; then
40+
return 0
41+
fi
42+
2843
tmp_root=/tmp
2944
envtest_root_dir=$tmp_root/envtest
3045

31-
k8s_version=1.16.4
32-
goarch=amd64
33-
goos="unknown"
34-
35-
if [[ "$OSTYPE" == "linux-gnu" ]]; then
36-
goos="linux"
37-
elif [[ "$OSTYPE" == "darwin"* ]]; then
38-
goos="darwin"
39-
fi
46+
k8s_version="${ENVTEST_K8S_VERSION:-1.16.4}"
47+
goarch="$(go env GOARCH)"
48+
goos="$(go env GOOS)"
4049

41-
if [[ "$goos" == "unknown" ]]; then
42-
echo "OS '$OSTYPE' not supported. Aborting." >&2
50+
if [[ "$goos" != "linux" && "$goos" != "darwin" ]]; then
51+
echo "OS '$goos' not supported. Aborting." >&2
4352
return 1
4453
fi
4554

0 commit comments

Comments
 (0)