Commit 96c1bc17 authored by Joe Beda's avatar Joe Beda

Set shell options for reliability.

Tweak a few other small things in our shell scripts.
parent d43a6ec5
...@@ -46,18 +46,20 @@ function kube::build::make_binary() { ...@@ -46,18 +46,20 @@ function kube::build::make_binary() {
} }
function kube::build::make_binaries() { function kube::build::make_binaries() {
if [[ ${#targets[@]} -eq 0 ]]; then local -a targets=(
targets=( cmd/proxy
cmd/proxy cmd/apiserver
cmd/apiserver cmd/controller-manager
cmd/controller-manager cmd/kubelet
cmd/kubelet cmd/kubecfg
cmd/kubecfg plugin/cmd/scheduler
plugin/cmd/scheduler )
)
if [[ -n "${1-}" ]]; then
targets=("$1")
fi fi
binaries=() local -a binaries=()
local target local target
for target in "${targets[@]}"; do for target in "${targets[@]}"; do
binaries+=("${KUBE_GO_PACKAGE}/${target}") binaries+=("${KUBE_GO_PACKAGE}/${target}")
...@@ -66,11 +68,6 @@ function kube::build::make_binaries() { ...@@ -66,11 +68,6 @@ function kube::build::make_binaries() {
ARCH_TARGET="${KUBE_TARGET}/${GOOS}/${GOARCH}" ARCH_TARGET="${KUBE_TARGET}/${GOOS}/${GOARCH}"
mkdir -p "${ARCH_TARGET}" mkdir -p "${ARCH_TARGET}"
if [[ -n "$1" ]]; then
kube::build::make_binary "$1"
exit 0
fi
local b local b
for b in "${binaries[@]}"; do for b in "${binaries[@]}"; do
kube::build::make_binary "$b" kube::build::make_binary "$b"
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -e set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/build/build-image/common.sh" source "${KUBE_ROOT}/build/build-image/common.sh"
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -e set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/build/build-image/common.sh" source "${KUBE_ROOT}/build/build-image/common.sh"
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -e set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/build/build-image/common.sh" source "${KUBE_ROOT}/build/build-image/common.sh"
......
...@@ -14,14 +14,16 @@ ...@@ -14,14 +14,16 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -e set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/build/build-image/common.sh" source "${KUBE_ROOT}/build/build-image/common.sh"
echo "+++ Running unit tests" echo "+++ Running unit tests"
if [[ -n "$1" ]]; then if [[ -n "${1-}" ]]; then
godep go test -cover -coverprofile=tmp.out "$KUBE_GO_PACKAGE/$1" godep go test -cover -coverprofile=tmp.out "$KUBE_GO_PACKAGE/$1"
exit 0 exit 0
fi fi
......
...@@ -53,7 +53,7 @@ readonly LOCAL_OUTPUT_BUILD="${LOCAL_OUTPUT_ROOT}/build" ...@@ -53,7 +53,7 @@ readonly LOCAL_OUTPUT_BUILD="${LOCAL_OUTPUT_ROOT}/build"
readonly REMOTE_OUTPUT_ROOT="/go/src/${KUBE_GO_PACKAGE}/_output" readonly REMOTE_OUTPUT_ROOT="/go/src/${KUBE_GO_PACKAGE}/_output"
readonly REMOTE_OUTPUT_DIR="${REMOTE_OUTPUT_ROOT}/build" readonly REMOTE_OUTPUT_DIR="${REMOTE_OUTPUT_ROOT}/build"
readonly DOCKER_CONTAINER_NAME=kube-build readonly DOCKER_CONTAINER_NAME=kube-build
readonly DOCKER_MOUNT="-v ${LOCAL_OUTPUT_BUILD}:${REMOTE_OUTPUT_DIR}" readonly DOCKER_MOUNT_ARGS=(--volume "${LOCAL_OUTPUT_BUILD}:${REMOTE_OUTPUT_DIR}")
readonly KUBE_CLIENT_BINARIES=( readonly KUBE_CLIENT_BINARIES=(
kubecfg kubecfg
...@@ -114,6 +114,7 @@ function kube::build::verify_prereqs() { ...@@ -114,6 +114,7 @@ function kube::build::verify_prereqs() {
echo " - On Mac OS X, boot2docker VM isn't started" >&2 echo " - On Mac OS X, boot2docker VM isn't started" >&2
echo " - On Mac OS X, DOCKER_HOST env variable isn't set approriately" >&2 echo " - On Mac OS X, DOCKER_HOST env variable isn't set approriately" >&2
echo " - On Linux, user isn't in 'docker' group. Add and relogin." >&2 echo " - On Linux, user isn't in 'docker' group. Add and relogin." >&2
echo " Something like 'sudo usermod -a -G docker ${USER-user}'" >&2
echo " - On Linux, Docker daemon hasn't been started or has crashed" >&2 echo " - On Linux, Docker daemon hasn't been started or has crashed" >&2
return 1 return 1
fi fi
...@@ -207,25 +208,23 @@ function kube::build::run_image() { ...@@ -207,25 +208,23 @@ function kube::build::run_image() {
function kube::build::docker_build() { function kube::build::docker_build() {
local -r image=$1 local -r image=$1
local -r context_dir=$2 local -r context_dir=$2
local -r build_cmd="docker build -t ${image} ${context_dir}" local -ra build_cmd=(docker build -t "${image}" "${context_dir}")
echo "+++ Building Docker image ${image}. This can take a while." echo "+++ Building Docker image ${image}. This can take a while."
set +e # We are handling the error here manually
local docker_output local docker_output
docker_output=$(${build_cmd} 2>&1) docker_output=$("${build_cmd[@]}" 2>&1) || {
if [[ $? -ne 0 ]]; then cat <<EOF >&2
set -e +++ Docker build command failed for ${image}
echo "+++ Docker build command failed for ${image}" >&2
echo >&2 ${docker_output}
echo "${docker_output}" >&2
echo >&2 To retry manually, run:
echo "To retry manually, run:" >&2
echo >&2 ${build_cmd[*]}
echo " ${build_cmd}" >&2
echo >&2 EOF
return 1 return 1
fi }
set -e
} }
function kube::build::clean_image() { function kube::build::clean_image() {
...@@ -252,18 +251,21 @@ function kube::build::clean_images() { ...@@ -252,18 +251,21 @@ function kube::build::clean_images() {
# Run a command in the kube-build image. This assumes that the image has # Run a command in the kube-build image. This assumes that the image has
# already been built. This will sync out all output data from the build. # already been built. This will sync out all output data from the build.
function kube::build::run_build_command() { function kube::build::run_build_command() {
[[ -n "$@" ]] || { echo "Invalid input." >&2; return 4; } [[ $# != 0 ]] || { echo "Invalid input." >&2; return 4; }
local -r docker="docker run --name=${DOCKER_CONTAINER_NAME} --attach=stdout --attach=stderr --attach=stdin --tty ${DOCKER_MOUNT} ${KUBE_BUILD_IMAGE}" local -ra docker_cmd=(
docker run "--name=${DOCKER_CONTAINER_NAME}"
--interactive --tty
"${DOCKER_MOUNT_ARGS[@]}" "${KUBE_BUILD_IMAGE}")
# Remove the container if it is left over from some previous aborted run # Remove the container if it is left over from some previous aborted run
docker rm ${DOCKER_CONTAINER_NAME} >/dev/null 2>&1 || true docker rm "${DOCKER_CONTAINER_NAME}" >/dev/null 2>&1 || true
${docker} "$@" "${docker_cmd[@]}" "$@"
# Remove the container after we run. '--rm' might be appropriate but it # Remove the container after we run. '--rm' might be appropriate but it
# appears that sometimes it fails. See # appears that sometimes it fails. See
# https://github.com/docker/docker/issues/3968 # https://github.com/docker/docker/issues/3968
docker rm ${DOCKER_CONTAINER_NAME} >/dev/null 2>&1 || true docker rm "${DOCKER_CONTAINER_NAME}" >/dev/null 2>&1 || true
} }
# If the Docker server is remote, copy the results back out. # If the Docker server is remote, copy the results back out.
...@@ -278,21 +280,23 @@ function kube::build::copy_output() { ...@@ -278,21 +280,23 @@ function kube::build::copy_output() {
# The easiest thing I (jbeda) could figure out was to launch another # The easiest thing I (jbeda) could figure out was to launch another
# container pointed at the same volume, tar the output directory and ship # container pointed at the same volume, tar the output directory and ship
# that tar over stdou. # that tar over stdou.
local -r docker="docker run -a stdout --name=${DOCKER_CONTAINER_NAME} ${DOCKER_MOUNT} ${KUBE_BUILD_IMAGE}" local -ra docker_cmd=(
docker run -a stdout "--name=${DOCKER_CONTAINER_NAME}"
"${DOCKER_MOUNT_ARGS[@]}" "${KUBE_BUILD_IMAGE}")
# Kill any leftover container # Kill any leftover container
docker rm ${DOCKER_CONTAINER_NAME} >/dev/null 2>&1 || true docker rm "${DOCKER_CONTAINER_NAME}" >/dev/null 2>&1 || true
echo "+++ Syncing back _output directory from boot2docker VM" echo "+++ Syncing back _output directory from boot2docker VM"
rm -rf "${LOCAL_OUTPUT_BUILD}" rm -rf "${LOCAL_OUTPUT_BUILD}"
mkdir -p "${LOCAL_OUTPUT_BUILD}" mkdir -p "${LOCAL_OUTPUT_BUILD}"
${docker} sh -c "tar c -C ${REMOTE_OUTPUT_DIR} . ; sleep 1" \ "${docker_cmd[@]}" sh -c "tar c -C ${REMOTE_OUTPUT_DIR} . ; sleep 1" \
| tar xv -C "${LOCAL_OUTPUT_BUILD}" | tar xv -C "${LOCAL_OUTPUT_BUILD}"
# Remove the container after we run. '--rm' might be appropriate but it # Remove the container after we run. '--rm' might be appropriate but it
# appears that sometimes it fails. See # appears that sometimes it fails. See
# https://github.com/docker/docker/issues/3968 # https://github.com/docker/docker/issues/3968
docker rm ${DOCKER_CONTAINER_NAME} >/dev/null 2>&1 || true docker rm "${DOCKER_CONTAINER_NAME}" >/dev/null 2>&1 || true
# I (jbeda) also tried getting rsync working using 'docker run' as the # I (jbeda) also tried getting rsync working using 'docker run' as the
# 'remote shell'. This mostly worked but there was a hang when # 'remote shell'. This mostly worked but there was a hang when
...@@ -440,7 +444,7 @@ function kube::release::gcs::verify_prereqs() { ...@@ -440,7 +444,7 @@ function kube::release::gcs::verify_prereqs() {
if [[ -z "${GCLOUD_ACCOUNT-}" ]]; then if [[ -z "${GCLOUD_ACCOUNT-}" ]]; then
GCLOUD_ACCOUNT=$(gcloud auth list 2>/dev/null | awk '/(active)/ { print $2 }') GCLOUD_ACCOUNT=$(gcloud auth list 2>/dev/null | awk '/(active)/ { print $2 }')
fi fi
if [[ -z "${GCLOUD_ACCOUNT}" ]]; then if [[ -z "${GCLOUD_ACCOUNT-}" ]]; then
echo "No account authorized through gcloud. Please fix with:" echo "No account authorized through gcloud. Please fix with:"
echo echo
echo " gcloud auth login" echo " gcloud auth login"
...@@ -450,7 +454,7 @@ function kube::release::gcs::verify_prereqs() { ...@@ -450,7 +454,7 @@ function kube::release::gcs::verify_prereqs() {
if [[ -z "${GCLOUD_PROJECT-}" ]]; then if [[ -z "${GCLOUD_PROJECT-}" ]]; then
GCLOUD_PROJECT=$(gcloud config list project | awk '{project = $3} END {print project}') GCLOUD_PROJECT=$(gcloud config list project | awk '{project = $3} END {print project}')
fi fi
if [[ -z "${GCLOUD_PROJECT}" ]]; then if [[ -z "${GCLOUD_PROJECT-}" ]]; then
echo "No account authorized through gcloud. Please fix with:" echo "No account authorized through gcloud. Please fix with:"
echo echo
echo " gcloud config set project <project id>" echo " gcloud config set project <project id>"
...@@ -471,9 +475,9 @@ function kube::release::gcs::ensure_release_bucket() { ...@@ -471,9 +475,9 @@ function kube::release::gcs::ensure_release_bucket() {
KUBE_GCS_RELEASE_PREFIX=${KUBE_GCS_RELEASE_PREFIX-devel/} KUBE_GCS_RELEASE_PREFIX=${KUBE_GCS_RELEASE_PREFIX-devel/}
KUBE_GCS_DOCKER_REG_PREFIX=${KUBE_GCS_DOCKER_REG_PREFIX-docker-reg/} KUBE_GCS_DOCKER_REG_PREFIX=${KUBE_GCS_DOCKER_REG_PREFIX-docker-reg/}
if ! gsutil ls gs://${KUBE_GCS_RELEASE_BUCKET} >/dev/null 2>&1 ; then if ! gsutil ls "gs://${KUBE_GCS_RELEASE_BUCKET}" >/dev/null 2>&1 ; then
echo "Creating Google Cloud Storage bucket: $RELEASE_BUCKET" echo "Creating Google Cloud Storage bucket: $RELEASE_BUCKET"
gsutil mb gs://${KUBE_GCS_RELEASE_BUCKET} gsutil mb "gs://${KUBE_GCS_RELEASE_BUCKET}"
fi fi
} }
...@@ -487,7 +491,8 @@ function kube::release::gcs::ensure_docker_registry() { ...@@ -487,7 +491,8 @@ function kube::release::gcs::ensure_docker_registry() {
# Grovel around and find the OAuth token in the gcloud config # Grovel around and find the OAuth token in the gcloud config
local -r boto=~/.config/gcloud/legacy_credentials/${GCLOUD_ACCOUNT}/.boto local -r boto=~/.config/gcloud/legacy_credentials/${GCLOUD_ACCOUNT}/.boto
local -r refresh_token=$(grep 'gs_oauth2_refresh_token =' $boto | awk '{ print $3 }') local refresh_token
refresh_token=$(grep 'gs_oauth2_refresh_token =' "$boto" | awk '{ print $3 }')
if [[ -z "$refresh_token" ]]; then if [[ -z "$refresh_token" ]]; then
echo "Couldn't find OAuth 2 refresh token in ${boto}" >&2 echo "Couldn't find OAuth 2 refresh token in ${boto}" >&2
...@@ -498,14 +503,16 @@ function kube::release::gcs::ensure_docker_registry() { ...@@ -498,14 +503,16 @@ function kube::release::gcs::ensure_docker_registry() {
docker rm ${reg_container_name} >/dev/null 2>&1 || true docker rm ${reg_container_name} >/dev/null 2>&1 || true
echo "+++ Starting GCS backed Docker registry" echo "+++ Starting GCS backed Docker registry"
local docker="docker run -d --name=${reg_container_name} " local -ra docker_cmd=(
docker+="-e GCS_BUCKET=${KUBE_GCS_RELEASE_BUCKET} " docker run -d "--name=${reg_container_name}"
docker+="-e STORAGE_PATH=${KUBE_GCS_DOCKER_REG_PREFIX} " -e "GCS_BUCKET=${KUBE_GCS_RELEASE_BUCKET}"
docker+="-e GCP_OAUTH2_REFRESH_TOKEN=${refresh_token} " -e "STORAGE_PATH=${KUBE_GCS_DOCKER_REG_PREFIX}"
docker+="-p 127.0.0.1:5000:5000 " -e "GCP_OAUTH2_REFRESH_TOKEN=${refresh_token}"
docker+="google/docker-registry" -p 127.0.0.1:5000:5000
google/docker-registry
${docker} )
"${docker[@]}"
# Give it time to spin up before we start throwing stuff at it # Give it time to spin up before we start throwing stuff at it
sleep 5 sleep 5
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
# #
# This is a no-op on Linux when the Docker daemon is local. This is only # This is a no-op on Linux when the Docker daemon is local. This is only
# necessary on Mac OS X with boot2docker. # necessary on Mac OS X with boot2docker.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "$KUBE_ROOT/build/common.sh" source "$KUBE_ROOT/build/common.sh"
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
# #
# This makes the docker build image, builds the binaries and copies them out # This makes the docker build image, builds the binaries and copies them out
# of the docker container. # of the docker container.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "$KUBE_ROOT/build/common.sh" source "$KUBE_ROOT/build/common.sh"
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
# Kubernetes into a tar file and put it in the right place in the output # Kubernetes into a tar file and put it in the right place in the output
# directory. It will then copy over the Dockerfile and build the kube-build # directory. It will then copy over the Dockerfile and build the kube-build
# image. # image.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT="$(dirname "${BASH_SOURCE}")/.." KUBE_ROOT="$(dirname "${BASH_SOURCE}")/.."
source "$KUBE_ROOT/build/common.sh" source "$KUBE_ROOT/build/common.sh"
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
# limitations under the License. # limitations under the License.
# Clean out the output directory on the docker host. # Clean out the output directory on the docker host.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "$KUBE_ROOT/build/common.sh" source "$KUBE_ROOT/build/common.sh"
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
# This makes the docker build image, builds the cross binaries and copies them # This makes the docker build image, builds the cross binaries and copies them
# out of the docker container. # out of the docker container.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "$KUBE_ROOT/build/common.sh" source "$KUBE_ROOT/build/common.sh"
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
# This script will make the 'run image' after building all of the necessary # This script will make the 'run image' after building all of the necessary
# binaries. # binaries.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "$KUBE_ROOT/build/common.sh" source "$KUBE_ROOT/build/common.sh"
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
# images and other build artifacts. All intermediate artifacts will be hosted # images and other build artifacts. All intermediate artifacts will be hosted
# publicly on Google Cloud Storage currently. # publicly on Google Cloud Storage currently.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "$KUBE_ROOT/build/common.sh" source "$KUBE_ROOT/build/common.sh"
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
# Run the integration test. # Run the integration test.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "$KUBE_ROOT/build/common.sh" source "$KUBE_ROOT/build/common.sh"
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
# Run all of the golang unit tests. # Run all of the golang unit tests.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "$KUBE_ROOT/build/common.sh" source "$KUBE_ROOT/build/common.sh"
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
# #
# This container will have a snapshot of the current sources. # This container will have a snapshot of the current sources.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "$KUBE_ROOT/build/common.sh" source "$KUBE_ROOT/build/common.sh"
......
...@@ -16,8 +16,9 @@ ...@@ -16,8 +16,9 @@
# Tear down a Kubernetes cluster. # Tear down a Kubernetes cluster.
# exit on any error set -o errexit
set -e set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/cluster/kube-env.sh" source "${KUBE_ROOT}/cluster/kube-env.sh"
......
...@@ -19,8 +19,9 @@ ...@@ -19,8 +19,9 @@
# This will find the release tar, cause it to be downloaded, unpacked, installed # This will find the release tar, cause it to be downloaded, unpacked, installed
# and enacted. # and enacted.
# exit on any error set -o errexit
set -e set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/cluster/kube-env.sh" source "${KUBE_ROOT}/cluster/kube-env.sh"
......
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
# that directly. If not then we assume we are doing development stuff and take # that directly. If not then we assume we are doing development stuff and take
# the defaults in the release config. # the defaults in the release config.
# exit on any error set -o errexit
set -e set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/cluster/kube-env.sh" source "${KUBE_ROOT}/cluster/kube-env.sh"
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/cluster/kube-env.sh" source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh" source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh"
...@@ -22,34 +26,36 @@ source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh" ...@@ -22,34 +26,36 @@ source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh"
case "$(uname -s)" in case "$(uname -s)" in
Darwin) Darwin)
host_os=darwin host_os=darwin
;; ;;
Linux) Linux)
host_os=linux host_os=linux
;; ;;
*) *)
echo "Unsupported host OS. Must be Linux or Mac OS X." >&2 echo "Unsupported host OS. Must be Linux or Mac OS X." >&2
exit 1 exit 1
;;
esac esac
case "$(uname -m)" in case "$(uname -m)" in
x86_64*) x86_64*)
host_arch=amd64 host_arch=amd64
;; ;;
i?86_64*) i?86_64*)
host_arch=amd64 host_arch=amd64
;; ;;
amd64*) amd64*)
host_arch=amd64 host_arch=amd64
;; ;;
arm*) arm*)
host_arch=arm host_arch=arm
;; ;;
i?86*) i?86*)
host_arch=x86 host_arch=x86
;; ;;
*) *)
echo "Unsupported host arch. Must be x86_64, 386 or arm." >&2 echo "Unsupported host arch. Must be x86_64, 386 or arm." >&2
exit 1 exit 1
;;
esac esac
kubecfg="${KUBE_ROOT}/_output/build/${host_os}/${host_arch}/kubecfg" kubecfg="${KUBE_ROOT}/_output/build/${host_os}/${host_arch}/kubecfg"
...@@ -84,8 +90,8 @@ else ...@@ -84,8 +90,8 @@ else
fi fi
detect-master > /dev/null detect-master > /dev/null
if [[ "$KUBE_MASTER_IP" != "" ]] && [[ "$KUBERNETES_MASTER" == "" ]]; then if [[ -n "${KUBE_MASTER_IP-}" && -z "${KUBERNETES_MASTER-}" ]]; then
export KUBERNETES_MASTER=https://${KUBE_MASTER_IP} export KUBERNETES_MASTER=https://${KUBE_MASTER_IP}
fi fi
"$kubecfg" "${auth_config[@]}" "$@" "$kubecfg" "${auth_config[@]:+${auth_config[@]}}" "$@"
...@@ -21,7 +21,8 @@ set -o errexit ...@@ -21,7 +21,8 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
readonly SALT_ROOT=$(dirname "${BASH_SOURCE}") SALT_ROOT=$(dirname "${BASH_SOURCE}")
readonly SALT_ROOT
readonly SERVER_BIN_TAR=${1-} readonly SERVER_BIN_TAR=${1-}
if [[ -z "$SERVER_BIN_TAR" ]]; then if [[ -z "$SERVER_BIN_TAR" ]]; then
...@@ -31,7 +32,7 @@ fi ...@@ -31,7 +32,7 @@ fi
# Create a temp dir for untaring # Create a temp dir for untaring
KUBE_TEMP=$(mktemp -d -t kubernetes.XXXXXX) KUBE_TEMP=$(mktemp -d -t kubernetes.XXXXXX)
trap "rm -rf ${KUBE_TEMP}" EXIT trap 'rm -rf "${KUBE_TEMP}"' EXIT
# This file is meant to run on the master. It will install the salt configs # This file is meant to run on the master. It will install the salt configs
# into the appropriate place on the master. # into the appropriate place on the master.
......
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
# that directly. If not then we assume we are doing development stuff and take # that directly. If not then we assume we are doing development stuff and take
# the defaults in the release config. # the defaults in the release config.
# exit on any error set -o errexit
set -e set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/cluster/kube-env.sh" source "${KUBE_ROOT}/cluster/kube-env.sh"
...@@ -44,13 +45,15 @@ fi ...@@ -44,13 +45,15 @@ fi
for (( i=0; i<${#MINION_NAMES[@]}; i++)); do for (( i=0; i<${#MINION_NAMES[@]}; i++)); do
# Grep returns an exit status of 1 when line is not found, so we need the : to always return a 0 exit status # Grep returns an exit status of 1 when line is not found, so we need the : to always return a 0 exit status
count=$(grep -c ${MINION_NAMES[i]} ${MINIONS_FILE}) || : count=$(grep -c ${MINION_NAMES[i]} ${MINIONS_FILE}) || :
if [ "$count" == "0" ]; then if [[ "$count" == "0" ]]; then
echo "Failed to find ${MINION_NAMES[i]}, cluster is probably broken." echo "Failed to find ${MINION_NAMES[i]}, cluster is probably broken."
exit 1 exit 1
fi fi
# Make sure the kubelet is healthy # Make sure the kubelet is healthy
if [ "$(curl -s --insecure --user ${KUBE_USER}:${KUBE_PASSWORD} https://${KUBE_MASTER_IP}/proxy/minion/${MINION_NAMES[$i]}/healthz)" != "ok" ]; then curl_output=$(curl -s --insecure --user "${KUBE_USER}:${KUBE_PASSWORD}" \
"https://${KUBE_MASTER_IP}/proxy/minion/${MINION_NAMES[$i]}/healthz")
if [[ "${curl_output}" != "ok" ]]; then
echo "Kubelet failed to install on ${MINION_NAMES[$i]}. Your cluster is unlikely to work correctly." echo "Kubelet failed to install on ${MINION_NAMES[$i]}. Your cluster is unlikely to work correctly."
echo "Please run ./cluster/kube-down.sh and re-create the cluster. (sorry!)" echo "Please run ./cluster/kube-down.sh and re-create the cluster. (sorry!)"
exit 1 exit 1
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -e set -o errexit
set -o nounset
set -o pipefail
KUBE_COVER=" " KUBE_RACE=" " hack/test-go.sh "" -test.run="^X" -benchtime=1s -bench=. -benchmem KUBE_COVER=" " KUBE_RACE=" " hack/test-go.sh "" -test.run="^X" -benchtime=1s -bench=. -benchmem
\ No newline at end of file
...@@ -199,6 +199,7 @@ export KUBE_GO_PACKAGE ...@@ -199,6 +199,7 @@ export KUBE_GO_PACKAGE
set -o errexit set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
go_pkg_dir="${KUBE_TARGET}/src/${KUBE_GO_PACKAGE}" go_pkg_dir="${KUBE_TARGET}/src/${KUBE_GO_PACKAGE}"
go_pkg_basedir=$(dirname "${go_pkg_dir}") go_pkg_basedir=$(dirname "${go_pkg_dir}")
mkdir -p "${go_pkg_basedir}" mkdir -p "${go_pkg_basedir}"
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
# This script will build a dev release and push it to an existing cluster. # This script will build a dev release and push it to an existing cluster.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
# Build a release # Build a release
......
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
# This script will build a dev release and bring up a new cluster with that # This script will build a dev release and bring up a new cluster with that
# release. # release.
set -e set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
......
...@@ -17,9 +17,11 @@ ...@@ -17,9 +17,11 @@
# Launches an nginx container and verifies it can be reached. Assumes that # Launches an nginx container and verifies it can be reached. Assumes that
# we're being called by hack/e2e-test.sh (we use some env vars it sets up). # we're being called by hack/e2e-test.sh (we use some env vars it sets up).
# Exit on error set -o errexit
set -e set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/kube-env.sh" source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh" source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
...@@ -41,17 +43,17 @@ function teardown() { ...@@ -41,17 +43,17 @@ function teardown() {
trap "teardown" EXIT trap "teardown" EXIT
POD_ID_LIST=$($KUBECFG '-template={{range.Items}}{{.ID}} {{end}}' -l replicationController=myNginx list pods) pod_id_list=$($KUBECFG '-template={{range.Items}}{{.ID}} {{end}}' -l replicationController=myNginx list pods)
# Container turn up on a clean cluster can take a while for the docker image pull. # Container turn up on a clean cluster can take a while for the docker image pull.
ALL_RUNNING=0 all_running=0
while [ $ALL_RUNNING -ne 1 ]; do while [[ $all_running -ne 1 ]]; do
echo "Waiting for all containers in pod to come up." echo "Waiting for all containers in pod to come up."
sleep 5 sleep 5
ALL_RUNNING=1 all_running=1
for id in $POD_ID_LIST; do for id in $pod_id_list; do
CURRENT_STATUS=$($KUBECFG -template '{{and .CurrentState.Info.mynginx.State.Running .CurrentState.Info.net.State.Running}}' get pods/$id) current_status=$($KUBECFG -template '{{and .CurrentState.Info.mynginx.State.Running .CurrentState.Info.net.State.Running}}' get pods/$id) || true
if [ "$CURRENT_STATUS" != "{0001-01-01 00:00:00 +0000 UTC}" ]; then if [[ "$current_status" != "{0001-01-01 00:00:00 +0000 UTC}" ]]; then
ALL_RUNNING=0 all_running=0
fi fi
done done
done done
...@@ -65,9 +67,9 @@ sleep 5 ...@@ -65,9 +67,9 @@ sleep 5
# Verify that something is listening (nginx should give us a 404) # Verify that something is listening (nginx should give us a 404)
for (( i=0; i<${#KUBE_MINION_IP_ADDRESSES[@]}; i++)); do for (( i=0; i<${#KUBE_MINION_IP_ADDRESSES[@]}; i++)); do
IP_ADDRESS=${KUBE_MINION_IP_ADDRESSES[$i]} ip_address=${KUBE_MINION_IP_ADDRESSES[$i]}
echo "Trying to reach nginx instance that should be running at ${IP_ADDRESS}:8080..." echo "Trying to reach nginx instance that should be running at ${ip_address}:8080..."
curl "http://${IP_ADDRESS}:8080" curl "http://${ip_address}:8080"
done done
exit 0 exit 0
...@@ -18,8 +18,11 @@ ...@@ -18,8 +18,11 @@
# works. Assumes that we're being called by hack/e2e-test.sh (we use some env # works. Assumes that we're being called by hack/e2e-test.sh (we use some env
# vars it sets up). # vars it sets up).
set -e set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/kube-env.sh" source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh" source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
......
...@@ -20,6 +20,7 @@ set -o errexit ...@@ -20,6 +20,7 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/kube-env.sh" source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh" source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
# Starts a Kubernetes cluster, runs the e2e test suite, and shuts it # Starts a Kubernetes cluster, runs the e2e test suite, and shuts it
# down. # down.
set -o errexit
set -o nounset
set -o pipefail
# Use testing config # Use testing config
export KUBE_CONFIG_FILE="config-test.sh" export KUBE_CONFIG_FILE="config-test.sh"
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
...@@ -34,9 +38,6 @@ ALREADY_UP=${1:-0} ...@@ -34,9 +38,6 @@ ALREADY_UP=${1:-0}
LEAVE_UP=${2:-0} LEAVE_UP=${2:-0}
TEAR_DOWN=${3:-0} TEAR_DOWN=${3:-0}
# Exit on error
set -e
if [[ $TEAR_DOWN -ne 0 ]]; then if [[ $TEAR_DOWN -ne 0 ]]; then
detect-project detect-project
trap test-teardown EXIT trap test-teardown EXIT
......
...@@ -14,9 +14,13 @@ ...@@ -14,9 +14,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
cd third_party cd third_party
git clone https://github.com/coreos/etcd.git git clone https://github.com/coreos/etcd.git
cd etcd cd etcd
git checkout ab4bcc18694644d12f0c038339d8d039072502b1 git checkout ab4bcc18694644d12f0c038339d8d039072502b1
./build ./build
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
# This script installs std -race on Travis (see https://code.google.com/p/go/issues/detail?id=6479) # This script installs std -race on Travis (see https://code.google.com/p/go/issues/detail?id=6479)
set -e set -o errexit
set -o nounset
set -o pipefail
if [ "${TRAVIS}" == "true" ]; then if [ "${TRAVIS}" == "true" ]; then
GO_VERSION=($(go version)) GO_VERSION=($(go version))
......
...@@ -17,18 +17,21 @@ ...@@ -17,18 +17,21 @@
# This command checks that the built commands can function together for # This command checks that the built commands can function together for
# simple scenarios. It does not require Docker so it can run in travis. # simple scenarios. It does not require Docker so it can run in travis.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/util.sh" source "${KUBE_ROOT}/hack/util.sh"
source "${KUBE_ROOT}/hack/config-go.sh" source "${KUBE_ROOT}/hack/config-go.sh"
function cleanup() function cleanup()
{ {
set +e [[ -n ${APISERVER_PID-} ]] && kill ${APISERVER_PID} 1>&2 2>/dev/null
kill ${APISERVER_PID} 1>&2 2>/dev/null [[ -n ${CTLRMGR_PID-} ]] && kill ${CTLRMGR_PID} 1>&2 2>/dev/null
kill ${CTLRMGR_PID} 1>&2 2>/dev/null [[ -n ${KUBELET_PID-} ]] && kill ${KUBELET_PID} 1>&2 2>/dev/null
kill ${KUBELET_PID} 1>&2 2>/dev/null [[ -n ${PROXY_PID-} ]] && kill ${PROXY_PID} 1>&2 2>/dev/null
kill ${PROXY_PID} 1>&2 2>/dev/null [[ -n ${ETCD_PID-} ]] && kill ${ETCD_PID} 1>&2 2>/dev/null
kill ${ETCD_PID} 1>&2 2>/dev/null
rm -rf ${ETCD_DIR} 1>&2 2>/dev/null rm -rf ${ETCD_DIR} 1>&2 2>/dev/null
echo echo
echo "Complete" echo "Complete"
......
...@@ -14,8 +14,9 @@ ...@@ -14,8 +14,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -o errexit
set -e set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/config-go.sh" source "${KUBE_ROOT}/hack/config-go.sh"
...@@ -138,7 +139,7 @@ if [[ "${iterations}" -gt 1 ]]; then ...@@ -138,7 +139,7 @@ if [[ "${iterations}" -gt 1 ]]; then
fi fi
fi fi
if [[ -n "$1" ]]; then if [[ -n "${1-}" ]]; then
covdir="/tmp/k8s_coverage/$(date "+%s")" covdir="/tmp/k8s_coverage/$(date "+%s")"
echo saving coverage output in "${covdir}" echo saving coverage output in "${covdir}"
for arg; do for arg; do
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
result=0 result=0
......
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
# GoFmt apparently is changing @ head... # GoFmt apparently is changing @ head...
set -o errexit
set -o nounset
set -o pipefail
GO_VERSION=($(go version)) GO_VERSION=($(go version))
if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.2|go1.3') ]]; then if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.2|go1.3') ]]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment