-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: add script in the repo to setup envtest #1608
Merged
k8s-ci-robot
merged 2 commits into
kubernetes-sigs:master
from
camilamacedo86:only-script
Jul 23, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ docs/book/book/ | |
|
||
# skip bin | ||
bin/* | ||
testbin/* | ||
|
||
# skip .out files (coverage tests) | ||
*.out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/bin/sh | ||
|
||
# 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. | ||
|
||
# This file will be fetched as: curl -L https://git.io/getLatestKubebuilder | sh - | ||
# so it should be pure bourne shell, not bash (and not reference other scripts) | ||
|
||
set -eu | ||
|
||
# To use envtest is required to have etcd, kube-apiserver and kubetcl binaries installed locally. | ||
# This script will create the directory testbin and perform this setup for linux or mac os x envs in | ||
|
||
# Kubernetes version e.g v1.18.2 | ||
K8S_VER=$1 | ||
# ETCD version e.g v3.4.3 | ||
ETCD_VER=$2 | ||
OS=$(uname -s | tr '[:upper:]' '[:lower:]') | ||
ARCH=$(uname -m | sed 's/x86_64/amd64/') | ||
ETCD_EXT="tar.gz" | ||
TESTBIN_DIR=testbin | ||
|
||
function setup_testenv_bin() { | ||
# Do nothing if the $TESTBIN_DIR directory exist already. | ||
if [ ! -d $TESTBIN_DIR ]; then | ||
mkdir -p $TESTBIN_DIR | ||
|
||
# install etcd binary | ||
# the extension for linux env is not equals for mac os x | ||
if [ $OS == "darwin" ]; then | ||
ETCD_EXT="zip" | ||
fi | ||
[[ -x ${TESTBIN_DIR}/etcd ]] || curl -L https://storage.googleapis.com/etcd/${ETCD_VER}/etcd-${ETCD_VER}-${OS}-${ARCH}.${ETCD_EXT} | tar zx -C ${TESTBIN_DIR} --strip-components=1 etcd-${ETCD_VER}-${OS}-${ARCH}/etcd | ||
|
||
# install kube-apiserver and kubetcl binaries | ||
if [ $OS == "darwin" ] | ||
then | ||
# kubernetes do not provide the kubernetes-server for darwin, | ||
# In this way, to have the kube-apiserver is required to build it locally | ||
# if the project is cloned locally already do nothing | ||
if [ ! -d $GOPATH/src/k8s.io/kubernetes ]; then | ||
git clone https://github.com/kubernetes/kubernetes $GOPATH/src/k8s.io/kubernetes --depth=1 -b ${K8S_VER} | ||
fi | ||
|
||
# if the kube-apiserve is built already then, just copy it | ||
if [ ! -f $GOPATH/src/k8s.io/kubernetes/_output/local/bin/darwin/amd64/kube-apiserver ]; then | ||
DIR=$(pwd) | ||
cd $GOPATH/src/k8s.io/kubernetes | ||
# Build for linux first otherwise it won't work for darwin - :( | ||
export KUBE_BUILD_PLATFORMS="linux/amd64" | ||
make WHAT=cmd/kube-apiserver | ||
export KUBE_BUILD_PLATFORMS="darwin/amd64" | ||
make WHAT=cmd/kube-apiserver | ||
cd ${DIR} | ||
fi | ||
cp $GOPATH/src/k8s.io/kubernetes/_output/local/bin/darwin/amd64/kube-apiserver $TESTBIN_DIR/ | ||
|
||
# setup kubectl binary | ||
curl -LO https://storage.googleapis.com/kubernetes-release/release/${K8S_VER}/bin/darwin/amd64/kubectl | ||
chmod +x kubectl | ||
mv kubectl $TESTBIN_DIR/ | ||
|
||
# allow run the tests without the Mac OS Firewall popup shows for each execution | ||
codesign --deep --force --verbose --sign - ./${TESTBIN_DIR}/kube-apiserver | ||
else | ||
[[ -x $TESTBIN_DIR/kube-apiserver && -x ${TESTBIN_DIR}/kubectl ]] || curl -L https://dl.k8s.io/${K8S_VER}/kubernetes-server-${OS}-${ARCH}.tar.gz | tar zx -C ${TESTBIN_DIR} --strip-components=3 kubernetes/server/bin/kube-apiserver kubernetes/server/bin/kubectl | ||
fi | ||
fi | ||
export PATH=/$TESTBIN_DIR:$PATH | ||
export TEST_ASSET_KUBECTL=/$TESTBIN_DIR/kubectl | ||
export TEST_ASSET_KUBE_APISERVER=/$TESTBIN_DIR/kube-apiserver | ||
export TEST_ASSET_ETCD=/$TESTBIN_DIR/etcd | ||
} | ||
|
||
setup_testenv_bin |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As a follow up consider defaulting these if they are unset. Maybe keep as env var