Skip to content

Commit 2611c59

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

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

hack/check-everything.sh

Lines changed: 4 additions & 3 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
@@ -32,14 +34,13 @@ kb_root_dir=$tmp_root/kubebuilder
3234
# machine, but rebuild the kubebuilder and kubebuilder-bin binaries.
3335
SKIP_FETCH_TOOLS=${SKIP_FETCH_TOOLS:-""}
3436

37+
ENVTEST_K8S_VERSION=${ENVTEST_K8S_VERSION:-"1.16.4"}
3538

3639
if [ -z "$SKIP_FETCH_TOOLS" ]; then
37-
header_text "fetching envtest tools"
3840
fetch_envtest_tools "$kb_root_dir"
3941
fetch_envtest_tools "${hack_dir}/../pkg/internal/testing/integration/assets"
4042
fi
4143

42-
header_text "setting up envtest environment"
4344
setup_envtest_env "$kb_root_dir"
4445

4546
${hack_dir}/verify.sh

hack/setup-envtest.sh

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,58 @@
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
2141
if [[ -z "${KUBEBUILDER_ASSETS}" ]]; then
2242
export KUBEBUILDER_ASSETS=$1/bin
2343
fi
2444
}
2545

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

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

41-
if [[ "$goos" == "unknown" ]]; then
42-
echo "OS '$OSTYPE' not supported. Aborting." >&2
67+
if [[ "$goos" != "linux" && "$goos" != "darwin" ]]; then
68+
echo "OS '$goos' not supported. Aborting." >&2
4369
return 1
4470
fi
4571

@@ -49,10 +75,12 @@ function fetch_envtest_tools {
4975
if [[ -x "${dest_dir}/bin/kube-apiserver" ]]; then
5076
version=$("${dest_dir}"/bin/kube-apiserver --version)
5177
if [[ $version == *"${k8s_version}"* ]]; then
78+
header_text "Using cached envtest tools from ${dest_dir}"
5279
return 0
5380
fi
5481
fi
5582

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

0 commit comments

Comments
 (0)