Skip to content

Commit a9bd911

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

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

hack/check-everything.sh

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
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
hack_dir=$(dirname ${BASH_SOURCE})
2022
source ${hack_dir}/common.sh
@@ -23,23 +25,10 @@ source ${hack_dir}/setup-envtest.sh
2325
tmp_root=/tmp
2426
kb_root_dir=$tmp_root/kubebuilder
2527

26-
# Skip fetching and untaring the tools by setting the SKIP_FETCH_TOOLS variable
27-
# in your environment to any value:
28-
#
29-
# $ SKIP_FETCH_TOOLS=1 ./check-everything.sh
30-
#
31-
# If you skip fetching tools, this script will use the tools already on your
32-
# machine, but rebuild the kubebuilder and kubebuilder-bin binaries.
33-
SKIP_FETCH_TOOLS=${SKIP_FETCH_TOOLS:-""}
34-
35-
36-
if [ -z "$SKIP_FETCH_TOOLS" ]; then
37-
header_text "fetching envtest tools"
38-
fetch_envtest_tools "$kb_root_dir"
39-
fetch_envtest_tools "${hack_dir}/../pkg/internal/testing/integration/assets"
40-
fi
28+
ENVTEST_K8S_VERSION=${ENVTEST_K8S_VERSION:-"1.16.4"}
4129

42-
header_text "setting up envtest environment"
30+
fetch_envtest_tools "$kb_root_dir"
31+
fetch_envtest_tools "${hack_dir}/../pkg/internal/testing/integration/assets"
4332
setup_envtest_env "$kb_root_dir"
4433

4534
${hack_dir}/verify.sh

hack/setup-envtest.sh

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,60 @@
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 pipefail
19+
20+
# Turn colors in this script off by setting the NO_COLOR variable in your
21+
# environment to any value:
22+
#
23+
# $ NO_COLOR=1 test.sh
24+
NO_COLOR=${NO_COLOR:-""}
25+
if [ -z "$NO_COLOR" ]; then
26+
header=$'\e[1;33m'
27+
reset=$'\e[0m'
28+
else
29+
header=''
30+
reset=''
31+
fi
32+
33+
function header_text {
34+
echo "$header$*$reset"
35+
}
1836

1937
function setup_envtest_env {
38+
header_text "setting up env vars"
39+
2040
# Setup env vars
41+
KUBEBUILDER_ASSETS=${KUBEBUILDER_ASSETS:-""}
2142
if [[ -z "${KUBEBUILDER_ASSETS}" ]]; then
2243
export KUBEBUILDER_ASSETS=$1/bin
2344
fi
2445
}
2546

2647
# fetch k8s API gen tools and make it available under envtest_root_dir/bin.
48+
#
49+
# Skip fetching and untaring the tools by setting the SKIP_FETCH_TOOLS variable
50+
# in your environment to any value:
51+
#
52+
# $ SKIP_FETCH_TOOLS=1 ./check-everything.sh
53+
#
54+
# If you skip fetching tools, this script will use the tools already on your
55+
# machine.
2756
function fetch_envtest_tools {
57+
SKIP_FETCH_TOOLS=${SKIP_FETCH_TOOLS:-""}
58+
if [ -n "$SKIP_FETCH_TOOLS" ]; then
59+
return 0
60+
fi
61+
2862
tmp_root=/tmp
2963
envtest_root_dir=$tmp_root/envtest
3064

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
65+
k8s_version="${ENVTEST_K8S_VERSION:-1.16.4}"
66+
goarch="$(go env GOARCH)"
67+
goos="$(go env GOOS)"
4068

41-
if [[ "$goos" == "unknown" ]]; then
42-
echo "OS '$OSTYPE' not supported. Aborting." >&2
69+
if [[ "$goos" != "linux" && "$goos" != "darwin" ]]; then
70+
echo "OS '$goos' not supported. Aborting." >&2
4371
return 1
4472
fi
4573

@@ -49,10 +77,12 @@ function fetch_envtest_tools {
4977
if [[ -x "${dest_dir}/bin/kube-apiserver" ]]; then
5078
version=$("${dest_dir}"/bin/kube-apiserver --version)
5179
if [[ $version == *"${k8s_version}"* ]]; then
80+
header_text "Using cached envtest tools from ${dest_dir}"
5281
return 0
5382
fi
5483
fi
5584

85+
header_text "fetching envtest tools@${k8s_version} (into '${dest_dir}')"
5686
envtest_tools_archive_name="kubebuilder-tools-$k8s_version-$goos-$goarch.tar.gz"
5787
envtest_tools_download_url="https://storage.googleapis.com/kubebuilder-tools/$envtest_tools_archive_name"
5888

0 commit comments

Comments
 (0)