-
Notifications
You must be signed in to change notification settings - Fork 1.2k
🏃 setup-envtest.sh: standalone script for setting up envtest #1092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,66 @@ | ||||||||||||||||
#!/usr/bin/env bash | ||||||||||||||||
|
||||||||||||||||
# Copyright 2020 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 -e | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
function setup_envtest_env { | ||||||||||||||||
# Setup env vars | ||||||||||||||||
if [[ -z "${KUBEBUILDER_ASSETS}" ]]; then | ||||||||||||||||
export KUBEBUILDER_ASSETS=$1/bin | ||||||||||||||||
fi | ||||||||||||||||
Comment on lines
+21
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is KUBEBUILDER_ASSETS preferable to what we were doing before
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed calls to If the header text is important, I could copy that code into this script. But I figured callers of these functions could call For environment variables, I opted to keep the existing environment setup as what's in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah let's copy it, it's great to see some styled output when running it |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
# fetch k8s API gen tools and make it available under envtest_root_dir/bin. | ||||||||||||||||
function fetch_envtest_tools { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about checking and returning early if |
||||||||||||||||
tmp_root=/tmp | ||||||||||||||||
envtest_root_dir=$tmp_root/envtest | ||||||||||||||||
|
||||||||||||||||
k8s_version=1.16.4 | ||||||||||||||||
goarch=amd64 | ||||||||||||||||
goos="unknown" | ||||||||||||||||
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about passing these in? So they're not hardcoded and they can be set dynamically when we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me |
||||||||||||||||
|
||||||||||||||||
if [[ "$OSTYPE" == "linux-gnu" ]]; then | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
goos="linux" | ||||||||||||||||
elif [[ "$OSTYPE" == "darwin"* ]]; then | ||||||||||||||||
goos="darwin" | ||||||||||||||||
fi | ||||||||||||||||
|
||||||||||||||||
if [[ "$goos" == "unknown" ]]; then | ||||||||||||||||
echo "OS '$OSTYPE' not supported. Aborting." >&2 | ||||||||||||||||
return 1 | ||||||||||||||||
fi | ||||||||||||||||
|
||||||||||||||||
local dest_dir="${1}" | ||||||||||||||||
|
||||||||||||||||
# use the pre-existing version in the temporary folder if it matches our k8s version | ||||||||||||||||
if [[ -x "${dest_dir}/bin/kube-apiserver" ]]; then | ||||||||||||||||
version=$("${dest_dir}"/bin/kube-apiserver --version) | ||||||||||||||||
if [[ $version == *"${k8s_version}"* ]]; then | ||||||||||||||||
return 0 | ||||||||||||||||
fi | ||||||||||||||||
fi | ||||||||||||||||
|
||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
envtest_tools_archive_name="kubebuilder-tools-$k8s_version-$goos-$goarch.tar.gz" | ||||||||||||||||
envtest_tools_download_url="https://storage.googleapis.com/kubebuilder-tools/$envtest_tools_archive_name" | ||||||||||||||||
|
||||||||||||||||
envtest_tools_archive_path="$tmp_root/$envtest_tools_archive_name" | ||||||||||||||||
if [ ! -f $envtest_tools_archive_path ]; then | ||||||||||||||||
curl -sL ${envtest_tools_download_url} -o "$envtest_tools_archive_path" | ||||||||||||||||
fi | ||||||||||||||||
|
||||||||||||||||
mkdir -p "${dest_dir}" | ||||||||||||||||
tar -C "${dest_dir}" --strip-components=1 -zvxf "$envtest_tools_archive_path" | ||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.