diff --git a/build/build-image/common.sh b/build/build-image/common.sh index 734e1a57bcb..0dfe765c558 100644 --- a/build/build-image/common.sh +++ b/build/build-image/common.sh @@ -17,9 +17,10 @@ # This script sets up a go workspace locally and builds all go components. # You can 'source' this file if you want to set up GOPATH in your local shell. -cd $(dirname "${BASH_SOURCE}")/../.. >/dev/null -readonly KUBE_REPO_ROOT="${PWD}" -readonly KUBE_TARGET="${KUBE_REPO_ROOT}/_output/build" +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +cd "${KUBE_ROOT}" + +readonly KUBE_TARGET="${KUBE_ROOT}/_output/build" readonly KUBE_GO_PACKAGE=github.com/GoogleCloudPlatform/kubernetes mkdir -p "${KUBE_TARGET}" @@ -39,7 +40,7 @@ function kube::build::make_binary() { local -r bin=${gopkg##*/} echo "+++ Building ${bin} for ${GOOS}/${GOARCH}" - pushd "${KUBE_REPO_ROOT}" >/dev/null + pushd "${KUBE_ROOT}" >/dev/null godep go build -ldflags "${KUBE_LD_FLAGS-}" -o "${ARCH_TARGET}/${bin}" "${gopkg}" popd >/dev/null } diff --git a/build/build-image/make-binaries.sh b/build/build-image/make-binaries.sh index 2ee1b7e2e9e..abcd462acfc 100755 --- a/build/build-image/make-binaries.sh +++ b/build/build-image/make-binaries.sh @@ -16,6 +16,7 @@ set -e -source $(dirname $0)/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +source "${KUBE_ROOT}/build/build-image/common.sh" kube::build::make_binaries "$@" diff --git a/build/build-image/make-cross.sh b/build/build-image/make-cross.sh index 81befd040c2..11af6759091 100755 --- a/build/build-image/make-cross.sh +++ b/build/build-image/make-cross.sh @@ -16,7 +16,8 @@ set -e -source $(dirname $0)/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +source "${KUBE_ROOT}/build/build-image/common.sh" readonly CROSS_BINARIES=( ./cmd/kubecfg diff --git a/build/build-image/run-integration.sh b/build/build-image/run-integration.sh index bd8a2e6fe28..69863929323 100755 --- a/build/build-image/run-integration.sh +++ b/build/build-image/run-integration.sh @@ -16,20 +16,21 @@ set -e -source $(dirname $0)/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +source "${KUBE_ROOT}/build/build-image/common.sh" kube::build::make_binaries "./cmd/integration" -readonly ETCD_DIR="${KUBE_REPO_ROOT}/_output/etcd" +readonly ETCD_DIR="${KUBE_ROOT}/_output/etcd" mkdir -p "${ETCD_DIR}" echo "+++ Running integration test" -etcd -name test -data-dir ${ETCD_DIR} > "${KUBE_REPO_ROOT}/_output/etcd.log" & +etcd -name test -data-dir ${ETCD_DIR} > "${KUBE_ROOT}/_output/etcd.log" & readonly ETCD_PID=$! sleep 5 -${KUBE_TARGET}/linux/amd64/integration +"${KUBE_TARGET}/linux/amd64/integration" kill $ETCD_PID diff --git a/build/build-image/run-tests.sh b/build/build-image/run-tests.sh index bd7ff0edada..353f200c0b2 100755 --- a/build/build-image/run-tests.sh +++ b/build/build-image/run-tests.sh @@ -16,7 +16,8 @@ set -e -source $(dirname $0)/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +source "${KUBE_ROOT}/build/build-image/common.sh" echo "+++ Running unit tests" diff --git a/build/common.sh b/build/common.sh index a797cb215cc..0f4f127aada 100644 --- a/build/common.sh +++ b/build/common.sh @@ -19,7 +19,8 @@ set -o errexit set -o nounset set -o pipefail -cd $(dirname "${BASH_SOURCE}")/.. +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +cd "${KUBE_ROOT}" source hack/config-go.sh @@ -36,8 +37,6 @@ readonly KUBE_GCS_MAKE_PUBLIC="${KUBE_GCS_MAKE_PUBLIC:-y}" # Constants -readonly KUBE_REPO_ROOT="${PWD}" - readonly KUBE_BUILD_IMAGE_REPO=kube-build readonly KUBE_BUILD_IMAGE_TAG=build readonly KUBE_BUILD_IMAGE="${KUBE_BUILD_IMAGE_REPO}:${KUBE_BUILD_IMAGE_TAG}" @@ -49,7 +48,7 @@ readonly KUBE_GO_PACKAGE="github.com/GoogleCloudPlatform/kubernetes" # # Note that here "LOCAL" is local to the docker daemon. In the boot2docker case # this is still inside the VM. We use the same directory in both cases though. -readonly LOCAL_OUTPUT_ROOT="${KUBE_REPO_ROOT}/_output" +readonly LOCAL_OUTPUT_ROOT="${KUBE_ROOT}/_output" readonly LOCAL_OUTPUT_BUILD="${LOCAL_OUTPUT_ROOT}/build" readonly REMOTE_OUTPUT_ROOT="/go/src/${KUBE_GO_PACKAGE}/_output" readonly REMOTE_OUTPUT_DIR="${REMOTE_OUTPUT_ROOT}/build" @@ -374,7 +373,7 @@ function kube::release::package_salt_tarball() { rm -rf "${release_stage}" mkdir -p "${release_stage}" - cp -R "${KUBE_REPO_ROOT}/cluster/saltbase" "${release_stage}/" + cp -R "${KUBE_ROOT}/cluster/saltbase" "${release_stage}/" local package_name="${RELEASE_DIR}/kubernetes-salt.tar.gz" tar czf "${package_name}" -C "${release_stage}/.." . @@ -396,7 +395,7 @@ function kube::release::package_full_tarball() { # We want everything in /cluster except saltbase. That is only needed on the # server. - cp -R "${KUBE_REPO_ROOT}/cluster" "${release_stage}/" + cp -R "${KUBE_ROOT}/cluster" "${release_stage}/" rm -rf "${release_stage}/cluster/saltbase" mkdir -p "${release_stage}/server" @@ -404,12 +403,12 @@ function kube::release::package_full_tarball() { cp "${RELEASE_DIR}"/kubernetes-server-*.tar.gz "${release_stage}/server/" mkdir -p "${release_stage}/third_party" - cp -R "${KUBE_REPO_ROOT}/third_party/htpasswd" "${release_stage}/third_party/htpasswd" + cp -R "${KUBE_ROOT}/third_party/htpasswd" "${release_stage}/third_party/htpasswd" - cp -R "${KUBE_REPO_ROOT}/examples" "${release_stage}/" - cp "${KUBE_REPO_ROOT}/README.md" "${release_stage}/" - cp "${KUBE_REPO_ROOT}/LICENSE" "${release_stage}/" - cp "${KUBE_REPO_ROOT}/Vagrantfile" "${release_stage}/" + cp -R "${KUBE_ROOT}/examples" "${release_stage}/" + cp "${KUBE_ROOT}/README.md" "${release_stage}/" + cp "${KUBE_ROOT}/LICENSE" "${release_stage}/" + cp "${KUBE_ROOT}/Vagrantfile" "${release_stage}/" local package_name="${RELEASE_DIR}/kubernetes.tar.gz" tar czf "${package_name}" -C "${release_stage}/.." . diff --git a/build/copy-output.sh b/build/copy-output.sh index 3e1c06f4dac..d273219a7e6 100755 --- a/build/copy-output.sh +++ b/build/copy-output.sh @@ -19,7 +19,8 @@ # This is a no-op on Linux when the Docker daemon is local. This is only # necessary on Mac OS X with boot2docker. -source $(dirname "${BASH_SOURCE}")/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "$KUBE_ROOT/build/common.sh" kube::build::verify_prereqs kube::build::copy_output diff --git a/build/make-binaries.sh b/build/make-binaries.sh index 001f5953278..cfa1925bb3a 100755 --- a/build/make-binaries.sh +++ b/build/make-binaries.sh @@ -19,7 +19,8 @@ # This makes the docker build image, builds the binaries and copies them out # of the docker container. -source $(dirname "${BASH_SOURCE}")/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "$KUBE_ROOT/build/common.sh" kube::build::verify_prereqs kube::build::build_image diff --git a/build/make-build-image.sh b/build/make-build-image.sh index 54e5bd09c95..9560436dd6f 100755 --- a/build/make-build-image.sh +++ b/build/make-build-image.sh @@ -21,7 +21,8 @@ # directory. It will then copy over the Dockerfile and build the kube-build # image. -source $(dirname "${BASH_SOURCE}")/common.sh +KUBE_ROOT="$(dirname "${BASH_SOURCE}")/.." +source "$KUBE_ROOT/build/common.sh" kube::build::verify_prereqs kube::build::build_image diff --git a/build/make-clean.sh b/build/make-clean.sh index d8f4f9fde58..bf9d169975b 100755 --- a/build/make-clean.sh +++ b/build/make-clean.sh @@ -16,7 +16,8 @@ # Clean out the output directory on the docker host. -source $(dirname "${BASH_SOURCE}")/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "$KUBE_ROOT/build/common.sh" kube::build::verify_prereqs kube::build::clean_output diff --git a/build/make-cross.sh b/build/make-cross.sh index c9da5d0f083..2148b7dbb52 100755 --- a/build/make-cross.sh +++ b/build/make-cross.sh @@ -19,7 +19,8 @@ # This makes the docker build image, builds the cross binaries and copies them # out of the docker container. -source $(dirname "${BASH_SOURCE}")/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "$KUBE_ROOT/build/common.sh" kube::build::verify_prereqs kube::build::build_image diff --git a/build/make-run-image.sh b/build/make-run-image.sh index fe90035b9f2..c6a49295aae 100755 --- a/build/make-run-image.sh +++ b/build/make-run-image.sh @@ -19,7 +19,8 @@ # This script will make the 'run image' after building all of the necessary # binaries. -source $(dirname "${BASH_SOURCE}")/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "$KUBE_ROOT/build/common.sh" kube::build::verify_prereqs kube::build::build_image diff --git a/build/release.sh b/build/release.sh index 65ea04ae355..3a448734c29 100755 --- a/build/release.sh +++ b/build/release.sh @@ -18,7 +18,8 @@ # images and other build artifacts. All intermediate artifacts will be hosted # publicly on Google Cloud Storage currently. -source $(dirname "${BASH_SOURCE}")/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "$KUBE_ROOT/build/common.sh" kube::build::verify_prereqs kube::build::build_image diff --git a/build/run-integration.sh b/build/run-integration.sh index c363a81adae..c6924c364bf 100755 --- a/build/run-integration.sh +++ b/build/run-integration.sh @@ -16,7 +16,8 @@ # Run the integration test. -source $(dirname "${BASH_SOURCE}")/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "$KUBE_ROOT/build/common.sh" kube::build::verify_prereqs kube::build::build_image diff --git a/build/run-tests.sh b/build/run-tests.sh index f9d32e8389d..1c06fb0cea9 100755 --- a/build/run-tests.sh +++ b/build/run-tests.sh @@ -16,7 +16,8 @@ # Run all of the golang unit tests. -source $(dirname "${BASH_SOURCE}")/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "$KUBE_ROOT/build/common.sh" kube::build::verify_prereqs kube::build::build_image diff --git a/build/shell.sh b/build/shell.sh index 4f95f010c33..3749a472081 100755 --- a/build/shell.sh +++ b/build/shell.sh @@ -18,7 +18,8 @@ # # This container will have a snapshot of the current sources. -source $(dirname "${BASH_SOURCE}")/common.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "$KUBE_ROOT/build/common.sh" kube::build::verify_prereqs kube::build::build_image diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index d52c1278b6f..87fe35d1a56 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -18,15 +18,11 @@ # Use the config file specified in $KUBE_CONFIG_FILE, or default to # config-default.sh. -source $(dirname ${BASH_SOURCE})/${KUBE_CONFIG_FILE-"config-default.sh"} +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +source "${KUBE_ROOT}/cluster/gce/${KUBE_CONFIG_FILE-"config-default.sh"}" # Verify prereqs -# -# Vars set: -# KUBE_REPO_ROOT function verify-prereqs { - KUBE_REPO_ROOT="$(dirname ${BASH_SOURCE})/../.." - for x in gcloud gcutil gsutil; do if [ "$(which $x)" == "" ]; then echo "Can't find $x in PATH, please fix and retry." @@ -41,18 +37,18 @@ function verify-prereqs { # SERVER_BINARY_TAR # SALT_TAR function find-release-tars { - SERVER_BINARY_TAR="${KUBE_REPO_ROOT}/server/kubernetes-server-linux-amd64.tar.gz" + SERVER_BINARY_TAR="${KUBE_ROOT}/server/kubernetes-server-linux-amd64.tar.gz" if [[ ! -f "$SERVER_BINARY_TAR" ]]; then - SERVER_BINARY_TAR="${KUBE_REPO_ROOT}/_output/release-tars/kubernetes-server-linux-amd64.tar.gz" + SERVER_BINARY_TAR="${KUBE_ROOT}/_output/release-tars/kubernetes-server-linux-amd64.tar.gz" fi if [[ ! -f "$SERVER_BINARY_TAR" ]]; then echo "!!! Cannot find kubernetes-server-linux-amd64.tar.gz" exit 1 fi - SALT_TAR="${KUBE_REPO_ROOT}/server/kubernetes-salt.tar.gz" + SALT_TAR="${KUBE_ROOT}/server/kubernetes-salt.tar.gz" if [[ ! -f "$SALT_TAR" ]]; then - SALT_TAR="${KUBE_REPO_ROOT}/_output/release-tars/kubernetes-salt.tar.gz" + SALT_TAR="${KUBE_ROOT}/_output/release-tars/kubernetes-salt.tar.gz" fi if [[ ! -f "$SALT_TAR" ]]; then echo "!!! Cannot find kubernetes-salt.tar.gz" @@ -195,7 +191,7 @@ EOF # Instantiate a kubernetes cluster # # Assumed vars -# KUBE_REPO_ROOT +# KUBE_ROOT # function kube-up { # Detect the project into $PROJECT if it isn't set @@ -210,7 +206,7 @@ function kube-up { trap 'rm -rf "${kube_temp}"' EXIT get-password - python "${KUBE_REPO_ROOT}/third_party/htpasswd/htpasswd.py" \ + python "${KUBE_ROOT}/third_party/htpasswd/htpasswd.py" \ -b -c "${kube_temp}/htpasswd" "$KUBE_USER" "$KUBE_PASSWORD" local htpasswd=$(cat "${kube_temp}/htpasswd") @@ -253,8 +249,8 @@ function kube-up { echo "readonly SERVER_BINARY_TAR_URL='${SERVER_BINARY_TAR_URL}'" echo "readonly SALT_TAR_URL='${SALT_TAR_URL}'" echo "readonly MASTER_HTPASSWD='${htpasswd}'" - grep -v "^#" "${KUBE_REPO_ROOT}/cluster/gce/templates/download-release.sh" - grep -v "^#" "${KUBE_REPO_ROOT}/cluster/gce/templates/salt-master.sh" + grep -v "^#" "${KUBE_ROOT}/cluster/gce/templates/download-release.sh" + grep -v "^#" "${KUBE_ROOT}/cluster/gce/templates/salt-master.sh" ) > "${kube_temp}/master-start.sh" gcutil addinstance ${MASTER_NAME}\ @@ -275,7 +271,7 @@ function kube-up { echo "#! /bin/bash" echo "MASTER_NAME='${MASTER_NAME}'" echo "MINION_IP_RANGE=${MINION_IP_RANGES[$i]}" - grep -v "^#" "${KUBE_REPO_ROOT}/cluster/gce/templates/salt-minion.sh" + grep -v "^#" "${KUBE_ROOT}/cluster/gce/templates/salt-minion.sh" ) > "${kube_temp}/minion-start-${i}.sh" gcutil addfirewall ${MINION_NAMES[$i]}-all \ @@ -448,7 +444,7 @@ function kube-push { echo "cd /var/cache/kubernetes-install" echo "readonly SERVER_BINARY_TAR_URL=${SERVER_BINARY_TAR_URL}" echo "readonly SALT_TAR_URL=${SALT_TAR_URL}" - grep -v "^#" "${KUBE_REPO_ROOT}/cluster/gce/templates/download-release.sh" + grep -v "^#" "${KUBE_ROOT}/cluster/gce/templates/download-release.sh" echo "echo Executing configuration" echo "sudo salt '*' mine.update" echo "sudo salt --force-color '*' state.highstate" @@ -472,12 +468,12 @@ function kube-push { # Execute prior to running tests to build a release if required for env. # # Assumed Vars: -# KUBE_REPO_ROOT +# KUBE_ROOT function test-build-release { # Build source - "${KUBE_REPO_ROOT}/hack/build-go.sh" + "${KUBE_ROOT}/hack/build-go.sh" # Make a release - "${KUBE_REPO_ROOT}/release/release.sh" + "${KUBE_ROOT}/release/release.sh" } # Execute prior to running tests to initialize required structure. This is @@ -520,5 +516,5 @@ function test-teardown { --sleep_between_polls "${POLL_SLEEP_INTERVAL}" \ --force \ ${MINION_TAG}-${INSTANCE_PREFIX}-http-alt || true > /dev/null - $(dirname $0)/../cluster/kube-down.sh > /dev/null + "${KUBE_ROOT}/cluster/kube-down.sh" > /dev/null } diff --git a/cluster/kube-down.sh b/cluster/kube-down.sh index baaa233524e..041f03d2f30 100755 --- a/cluster/kube-down.sh +++ b/cluster/kube-down.sh @@ -19,8 +19,9 @@ # exit on any error set -e -source $(dirname $0)/kube-env.sh -source $(dirname $0)/$KUBERNETES_PROVIDER/util.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/cluster/kube-env.sh" +source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh" echo "Bringing down cluster using provider: $KUBERNETES_PROVIDER" diff --git a/cluster/kube-push.sh b/cluster/kube-push.sh index c6eec62e11b..396e2bbaf7d 100755 --- a/cluster/kube-push.sh +++ b/cluster/kube-push.sh @@ -22,14 +22,15 @@ # exit on any error set -e -source $(dirname $0)/kube-env.sh -source $(dirname $0)/$KUBERNETES_PROVIDER/util.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/cluster/kube-env.sh" +source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh" echo "Updating cluster using provider: $KUBERNETES_PROVIDER" verify-prereqs kube-push -source $(dirname $0)/validate-cluster.sh +"${KUBE_ROOT}/cluster/validate-cluster.sh" echo "Done" diff --git a/cluster/kube-up.sh b/cluster/kube-up.sh index b7f0b94fdba..40729277810 100755 --- a/cluster/kube-up.sh +++ b/cluster/kube-up.sh @@ -23,14 +23,15 @@ # exit on any error set -e -source $(dirname $0)/kube-env.sh -source $(dirname $0)/$KUBERNETES_PROVIDER/util.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/cluster/kube-env.sh" +source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh" echo "Starting cluster using provider: $KUBERNETES_PROVIDER" verify-prereqs kube-up -source $(dirname $0)/validate-cluster.sh +"${KUBE_ROOT}/cluster/validate-cluster.sh" echo "Done" diff --git a/cluster/kubecfg.sh b/cluster/kubecfg.sh index 9a82d006047..aa72a75d6ed 100755 --- a/cluster/kubecfg.sh +++ b/cluster/kubecfg.sh @@ -14,9 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -ROOT_DIR="$(dirname ${BASH_SOURCE})/.." -source "${ROOT_DIR}/cluster/kube-env.sh" -source "${ROOT_DIR}/cluster/${KUBERNETES_PROVIDER}/util.sh" +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/cluster/kube-env.sh" +source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh" # Detect the OS name/arch so that we can find our binary case "$(uname -s)" in @@ -52,9 +52,9 @@ case "$(uname -m)" in exit 1 esac -kubecfg="${ROOT_DIR}/_output/build/${host_os}/${host_arch}/kubecfg" +kubecfg="${KUBE_ROOT}/_output/build/${host_os}/${host_arch}/kubecfg" if [[ ! -x "$kubecfg" ]]; then - kubecfg="${ROOT_DIR}/platforms/${host_os}/${host_arch}/kubecfg" + kubecfg="${KUBE_ROOT}/platforms/${host_os}/${host_arch}/kubecfg" fi if [[ ! -x "$kubecfg" ]]; then echo "It looks as if you don't have a compiled version of Kubernetes. If you" >&2 diff --git a/cluster/saltbase/install.sh b/cluster/saltbase/install.sh index 0768b3e51e2..6245267d65f 100755 --- a/cluster/saltbase/install.sh +++ b/cluster/saltbase/install.sh @@ -21,7 +21,7 @@ set -o errexit set -o nounset set -o pipefail -readonly SALTBASE="$(dirname $0)" +readonly SALT_ROOT=$(dirname "${BASH_SOURCE}") readonly SERVER_BIN_TAR=${1-} if [[ -z "$SERVER_BIN_TAR" ]]; then @@ -38,10 +38,10 @@ trap "rm -rf ${KUBE_TEMP}" EXIT echo "+++ Installing salt files" mkdir -p /srv -# This bash voodoo will prepend $SALTBASE to the start of each item in the +# This bash voodoo will prepend $SALT_ROOT to the start of each item in the # $SALTDIRS array readonly SALTDIRS=(salt pillar reactor) -cp -R --preserve=mode "${SALTDIRS[@]/#/${SALTBASE}/}" /srv/ +cp -R --preserve=mode "${SALTDIRS[@]/#/${SALT_ROOT}/}" /srv/ echo "+++ Install binaries from tar: $1" diff --git a/cluster/vagrant/config-test.sh b/cluster/vagrant/config-test.sh index 7a636f9d6a2..1655f6e23f1 100644 --- a/cluster/vagrant/config-test.sh +++ b/cluster/vagrant/config-test.sh @@ -15,4 +15,5 @@ # limitations under the License. ## Contains configuration values for interacting with the Vagrant cluster in test mode -source $(dirname ${BASH_SOURCE})/config-default.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +source "${KUBE_ROOT}/cluster/vagrant/config-default.sh" diff --git a/cluster/vagrant/pod-ip-test.sh b/cluster/vagrant/pod-ip-test.sh index 56aba721fd9..64529de9cf8 100755 --- a/cluster/vagrant/pod-ip-test.sh +++ b/cluster/vagrant/pod-ip-test.sh @@ -53,7 +53,8 @@ while [[ $# > 0 ]]; do esac done -cd $(dirname ${BASH_SOURCE})/../../ +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +cd "${KUBE_ROOT}" echo All verbose output will be redirected to $logfile, use --logfile option to change. diff --git a/cluster/vagrant/provision-master.sh b/cluster/vagrant/provision-master.sh index 6ac5a2d632f..60a1e2544b1 100755 --- a/cluster/vagrant/provision-master.sh +++ b/cluster/vagrant/provision-master.sh @@ -16,19 +16,9 @@ # exit on any error set -e -source $(dirname $0)/provision-config.sh -# # Install Docker on master to run the build. This is a necessary chunk of -# # bootstrapping. -# yum install -y docker-io -# SYSTEMD_LOG_LEVEL=notice systemctl enable docker -# systemctl start docker - -# # Build release -# echo "Building release" -# pushd /vagrant -# bash -x ./build/release.sh -# popd +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +source "${KUBE_ROOT}/cluster/vagrant/provision-config.sh" function release_not_found() { echo "It looks as if you don't have a compiled version of Kubernetes. If you" >&2 @@ -117,10 +107,10 @@ state_output: mixed EOF # Configure nginx authorization -mkdir -p $KUBE_TEMP +mkdir -p "$KUBE_TEMP" mkdir -p /srv/salt/nginx -python $(dirname $0)/../../third_party/htpasswd/htpasswd.py -b -c ${KUBE_TEMP}/htpasswd $MASTER_USER $MASTER_PASSWD -MASTER_HTPASSWD=$(cat ${KUBE_TEMP}/htpasswd) +python "${KUBE_ROOT}/third_party/htpasswd/htpasswd.py" -b -c "${KUBE_TEMP}/htpasswd" "$MASTER_USER" "$MASTER_PASSWD" +MASTER_HTPASSWD=$(cat "${KUBE_TEMP}/htpasswd") echo $MASTER_HTPASSWD > /srv/salt/nginx/htpasswd # we will run provision to update code each time we test, so we do not want to do salt install each time diff --git a/cluster/vagrant/provision-minion.sh b/cluster/vagrant/provision-minion.sh index 8236a055416..60c48f1063b 100755 --- a/cluster/vagrant/provision-minion.sh +++ b/cluster/vagrant/provision-minion.sh @@ -16,7 +16,8 @@ # exit on any error set -e -source $(dirname $0)/provision-config.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +source "${KUBE_ROOT}/cluster/vagrant/provision-config.sh" MINION_IP=$4 @@ -30,11 +31,11 @@ fi minion_ip_array=(${MINION_IPS//,/ }) for (( i=0; i<${#MINION_NAMES[@]}; i++)); do minion=${MINION_NAMES[$i]} - ip=${minion_ip_array[$i]} + ip=${minion_ip_array[$i]} if [ ! "$(cat /etc/hosts | grep $minion)" ]; then echo "Adding $minion to hosts file" echo "$ip $minion" >> /etc/hosts - fi + fi done # Let the minion know who its master is @@ -61,4 +62,4 @@ if ! which salt-minion >/dev/null 2>&1; then fi # run the networking setup -$(dirname $0)/provision-network.sh $@ +"${KUBE_ROOT}/cluster/vagrant/provision-network.sh" $@ diff --git a/cluster/vagrant/provision-network.sh b/cluster/vagrant/provision-network.sh index 178f0b28ae0..00cbb6c3b24 100755 --- a/cluster/vagrant/provision-network.sh +++ b/cluster/vagrant/provision-network.sh @@ -16,7 +16,8 @@ # exit on any error set -e -source $(dirname $0)/provision-config.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +source "${KUBE_ROOT}/cluster/vagrant/provision-config.sh" MINION_IP=$4 MINION_ID=$5 diff --git a/cluster/vagrant/util.sh b/cluster/vagrant/util.sh index 66953c73702..a704d06140e 100644 --- a/cluster/vagrant/util.sh +++ b/cluster/vagrant/util.sh @@ -16,7 +16,8 @@ # A library of helper functions that each provider hosting Kubernetes must implement to use cluster/kube-*.sh scripts. -source $(dirname ${BASH_SOURCE})/${KUBE_CONFIG_FILE-"config-default.sh"} +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +source "${KUBE_ROOT}/cluster/vagrant/${KUBE_CONFIG_FILE-"config-default.sh"}" function detect-master () { echo "KUBE_MASTER_IP: ${KUBE_MASTER_IP}" @@ -91,7 +92,7 @@ function kube-up { local count="0" until [[ "$count" == "1" ]]; do local minions - minions=$("$(dirname $0)/cluster/kubecfg.sh" -template '{{range.Items}}{{.ID}}:{{end}}' list minions) + minions=$("${KUBE_ROOT}/cluster/kubecfg.sh" -template '{{range.Items}}{{.ID}}:{{end}}' list minions) count=$(echo $minions | grep -c "${MINION_NAMES[i]}") || { printf "." sleep 2 diff --git a/cluster/validate-cluster.sh b/cluster/validate-cluster.sh index 217281b32a9..3e235a043b5 100755 --- a/cluster/validate-cluster.sh +++ b/cluster/validate-cluster.sh @@ -23,15 +23,16 @@ # exit on any error set -e -source $(dirname $0)/kube-env.sh -source $(dirname $0)/$KUBERNETES_PROVIDER/util.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/cluster/kube-env.sh" +source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh" get-password detect-master > /dev/null detect-minions > /dev/null MINIONS_FILE=/tmp/minions -$(dirname $0)/kubecfg.sh -template '{{range.Items}}{{.ID}}:{{end}}' list minions > ${MINIONS_FILE} +"${KUBE_ROOT}/cluster/kubecfg.sh" -template '{{range.Items}}{{.ID}}:{{end}}' list minions > ${MINIONS_FILE} # On vSphere, use minion IPs as their names if [ "$KUBERNETES_PROVIDER" == "vsphere" ]; then diff --git a/hack/build-go.sh b/hack/build-go.sh index 19d8233fdf7..8947ba58353 100755 --- a/hack/build-go.sh +++ b/hack/build-go.sh @@ -20,13 +20,13 @@ set -o errexit set -o nounset set -o pipefail -hackdir=$(CDPATH="" cd $(dirname $0); pwd) +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. # Set the environment variables required by the build. -. "${hackdir}/config-go.sh" +source "${KUBE_ROOT}/hack/config-go.sh" # Go to the top of the tree. -cd "${KUBE_REPO_ROOT}" +cd "${KUBE_ROOT}" # Check for `go` binary and set ${GOPATH}. kube::setup_go_environment diff --git a/hack/config-go.sh b/hack/config-go.sh index c4beb930885..bd23f081d32 100644 --- a/hack/config-go.sh +++ b/hack/config-go.sh @@ -36,7 +36,7 @@ # the final GOPATH. # --- Environment Variables set by sourcing config-go.sh --- -# KUBE_REPO_ROOT - Path to the top of the build tree. +# KUBE_ROOT - Path to the top of the build tree. # KUBE_TARGET - Path where output Go files are saved. # KUBE_GO_PACKAGE - Full name of the Kubernetes Go package. @@ -61,7 +61,7 @@ kube::version_ldflags() { unset CDPATH - cd "${KUBE_REPO_ROOT}" + cd "${KUBE_ROOT}" declare -a ldflags=() if [[ -n ${KUBE_GIT_COMMIT-} ]] || KUBE_GIT_COMMIT=$(git rev-parse "HEAD^{commit}" 2>/dev/null); then @@ -143,7 +143,7 @@ kube::setup_go_environment() { # Append the tree maintained by `godep` to the GOPATH unless KUBE_NO_GODEPS # is defined. if [[ -z ${KUBE_NO_GODEPS:-} ]]; then - GOPATH="${GOPATH}:${KUBE_REPO_ROOT}/Godeps/_workspace" + GOPATH="${GOPATH}:${KUBE_ROOT}/Godeps/_workspace" fi export GOPATH @@ -172,18 +172,19 @@ kube::binaries_from_targets() { } # --- Environment Variables --- -# Make ${KUBE_REPO_ROOT} an absolute path. -KUBE_REPO_ROOT=$( - set -eu +# Make ${KUBE_ROOT} an absolute path. +KUBE_ROOT=$( + set -o errexit + set -o nounset + set -o pipefail unset CDPATH - scripts_dir=$(dirname "${BASH_SOURCE[0]}") - cd "${scripts_dir}" - cd .. + kube_root=$(dirname "${BASH_SOURCE}")/.. + cd "${kube_root}" pwd ) -export KUBE_REPO_ROOT +export KUBE_ROOT -KUBE_TARGET="${KUBE_REPO_ROOT}/_output/go" +KUBE_TARGET="${KUBE_ROOT}/_output/go" mkdir -p "${KUBE_TARGET}" export KUBE_TARGET @@ -195,12 +196,14 @@ export KUBE_GO_PACKAGE # So that Go knows how to import Kubernetes sources by full path. # Use a subshell to avoid leaking these variables. - set -eu + set -o errexit + set -o nounset + set -o pipefail go_pkg_dir="${KUBE_TARGET}/src/${KUBE_GO_PACKAGE}" go_pkg_basedir=$(dirname "${go_pkg_dir}") mkdir -p "${go_pkg_basedir}" rm -f "${go_pkg_dir}" # TODO: This symlink should be relative. - ln -s "${KUBE_REPO_ROOT}" "${go_pkg_dir}" + ln -s "${KUBE_ROOT}" "${go_pkg_dir}" ) diff --git a/hack/dev-build-and-push.sh b/hack/dev-build-and-push.sh index 678c00029f2..69a2bea4db9 100755 --- a/hack/dev-build-and-push.sh +++ b/hack/dev-build-and-push.sh @@ -16,12 +16,14 @@ # This script will build a dev release and push it to an existing cluster. -# Then build a release -$(dirname $0)/../build/release.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. + +# Build a release +"${KUBE_ROOT}/build/release.sh" if [ "$?" != "0" ]; then echo "Building a release failed!" exit 1 fi # Now push this out to the cluster -$(dirname $0)/../cluster/kube-push.sh +"${KUBE_ROOT}/cluster/kube-push.sh" diff --git a/hack/dev-build-and-up.sh b/hack/dev-build-and-up.sh index f50da7831b5..f855e8d83b7 100755 --- a/hack/dev-build-and-up.sh +++ b/hack/dev-build-and-up.sh @@ -19,12 +19,14 @@ set -e +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. + # Then build a release -$(dirname $0)/../build/release.sh +"${KUBE_ROOT}/build/release.sh" if [ "$?" != "0" ]; then echo "Building the release failed!" exit 1 fi # Now bring a new cluster up with that release. -$(dirname $0)/../cluster/kube-up.sh +"${KUBE_ROOT}/cluster/kube-up.sh" diff --git a/hack/e2e-suite/basic.sh b/hack/e2e-suite/basic.sh index 793aac0dba3..0ef7a9cbb15 100755 --- a/hack/e2e-suite/basic.sh +++ b/hack/e2e-suite/basic.sh @@ -20,8 +20,8 @@ # Exit on error set -e -source "${KUBE_REPO_ROOT}/cluster/kube-env.sh" -source "${KUBE_REPO_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh" +source "${KUBE_ROOT}/cluster/kube-env.sh" +source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh" # Launch a container $KUBECFG -p 8080:80 run dockerfile/nginx 2 myNginx diff --git a/hack/e2e-suite/guestbook.sh b/hack/e2e-suite/guestbook.sh index 1da6f890e60..d72bbb1eb44 100755 --- a/hack/e2e-suite/guestbook.sh +++ b/hack/e2e-suite/guestbook.sh @@ -20,10 +20,10 @@ set -e -source "${KUBE_REPO_ROOT}/cluster/kube-env.sh" -source "${KUBE_REPO_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh" +source "${KUBE_ROOT}/cluster/kube-env.sh" +source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh" -GUESTBOOK="${KUBE_REPO_ROOT}/examples/guestbook" +GUESTBOOK="${KUBE_ROOT}/examples/guestbook" # Launch the guestbook example $KUBECFG -c "${GUESTBOOK}/redis-master.json" create /pods diff --git a/hack/e2e-suite/update.sh b/hack/e2e-suite/update.sh index d5a3ebe15e9..93f912ff6e0 100755 --- a/hack/e2e-suite/update.sh +++ b/hack/e2e-suite/update.sh @@ -20,8 +20,8 @@ set -o errexit set -o nounset set -o pipefail -source "${KUBE_REPO_ROOT}/cluster/kube-env.sh" -source "${KUBE_REPO_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh" +source "${KUBE_ROOT}/cluster/kube-env.sh" +source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh" CONTROLLER_NAME=update-demo @@ -79,26 +79,26 @@ function validate() { export DOCKER_HUB_USER=jbeda # Launch a container -${KUBE_REPO_ROOT}/examples/update-demo/2-create-replication-controller.sh +${KUBE_ROOT}/examples/update-demo/2-create-replication-controller.sh function teardown() { echo "Cleaning up test artifacts" - ${KUBE_REPO_ROOT}/examples/update-demo/5-down.sh + ${KUBE_ROOT}/examples/update-demo/5-down.sh } trap "teardown" EXIT validate 2 nautilus -${KUBE_REPO_ROOT}/examples/update-demo/3-scale.sh 1 +${KUBE_ROOT}/examples/update-demo/3-scale.sh 1 sleep 2 validate 1 nautilus -${KUBE_REPO_ROOT}/examples/update-demo/3-scale.sh 2 +${KUBE_ROOT}/examples/update-demo/3-scale.sh 2 sleep 2 validate 2 nautilus -${KUBE_REPO_ROOT}/examples/update-demo/4-rolling-update.sh kitten 1s +${KUBE_ROOT}/examples/update-demo/4-rolling-update.sh kitten 1s sleep 2 validate 2 kitten diff --git a/hack/e2e-test.sh b/hack/e2e-test.sh index 19805d4d587..fa7537fa307 100755 --- a/hack/e2e-test.sh +++ b/hack/e2e-test.sh @@ -19,14 +19,14 @@ # Use testing config export KUBE_CONFIG_FILE="config-test.sh" -export KUBE_REPO_ROOT="$(dirname $0)/.." +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. # TODO(jbeda): This will break on usage if there is a space in -# ${KUBE_REPO_ROOT}. Covert to an array? Or an exported function? -export KUBECFG="${KUBE_REPO_ROOT}/cluster/kubecfg.sh -expect_version_match" +# ${KUBE_ROOT}. Covert to an array? Or an exported function? +export KUBECFG="${KUBE_ROOT}/cluster/kubecfg.sh -expect_version_match" -source $(dirname $0)/../cluster/kube-env.sh -source $(dirname $0)/../cluster/$KUBERNETES_PROVIDER/util.sh +source "${KUBE_ROOT}/cluster/kube-env.sh" +source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh" # For debugging of this test's components, it's helpful to leave the test # cluster running. @@ -48,10 +48,10 @@ test-build-release if [[ ${ALREADY_UP} -ne 1 ]]; then # Now bring a test cluster up with that release. - $(dirname $0)/../cluster/kube-up.sh + "${KUBE_ROOT}/cluster/kube-up.sh" else # Just push instead - $(dirname $0)/../cluster/kube-push.sh + "${KUBE_ROOT}/cluster/kube-push.sh" fi # Perform any required setup of the cluster @@ -64,8 +64,8 @@ if [[ ${LEAVE_UP} -ne 1 ]]; then fi any_failed=0 -for test_file in $(ls $(dirname $0)/e2e-suite/); do - "$(dirname $0)/e2e-suite/${test_file}" +for test_file in $(ls "${KUBE_ROOT}/hack/e2e-suite/"); do + "${KUBE_ROOT}/hack/e2e-suite/${test_file}" result="$?" if [[ "${result}" -eq "0" ]]; then echo "${test_file} returned ${result}; passed!" diff --git a/hack/test-cmd.sh b/hack/test-cmd.sh index 6450fb997e6..6e7c7da532b 100755 --- a/hack/test-cmd.sh +++ b/hack/test-cmd.sh @@ -17,8 +17,9 @@ # This command checks that the built commands can function together for # simple scenarios. It does not require Docker so it can run in travis. -source $(dirname $0)/util.sh -source $(dirname $0)/config-go.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/hack/util.sh" +source "${KUBE_ROOT}/hack/config-go.sh" function cleanup() { @@ -48,7 +49,7 @@ KUBELET_PORT=${KUBELET_PORT:-10250} GO_OUT=${KUBE_TARGET}/bin # Check kubecfg -out=$(${GO_OUT}/kubecfg -version) +out=$("${GO_OUT}/kubecfg" -version) echo kubecfg: $out # Start kubelet diff --git a/hack/test-go.sh b/hack/test-go.sh index aaca6b61d13..c854a1d9410 100755 --- a/hack/test-go.sh +++ b/hack/test-go.sh @@ -17,15 +17,15 @@ set -e -source $(dirname $0)/config-go.sh +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/hack/config-go.sh" # Go to the top of the tree. -cd "${KUBE_REPO_ROOT}" +cd "${KUBE_ROOT}" # Check for `go` binary and set ${GOPATH}. kube::setup_go_environment - find_test_dirs() { cd src/${KUBE_GO_PACKAGE} find . -not \( \ diff --git a/hack/test-integration.sh b/hack/test-integration.sh index f36514d0656..eb9200d269b 100755 --- a/hack/test-integration.sh +++ b/hack/test-integration.sh @@ -18,10 +18,9 @@ set -o errexit set -o nounset set -o pipefail -basedir=$(dirname "$0") -source "${basedir}/config-go.sh" - -source "${KUBE_REPO_ROOT}/hack/util.sh" +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/hack/config-go.sh" +source "${KUBE_ROOT}/hack/util.sh" cleanup() { kill "${ETCD_PID-}" >/dev/null 2>&1 || : @@ -31,7 +30,7 @@ cleanup() { } if [[ "${KUBE_NO_BUILD_INTEGRATION+set}" != "set" ]]; then - "${KUBE_REPO_ROOT}/hack/build-go.sh" cmd/integration + "${KUBE_ROOT}/hack/build-go.sh" cmd/integration fi # Run cleanup to stop etcd on interrupt or other kill signal. @@ -43,7 +42,7 @@ echo "" echo "Integration test cases..." echo "" GOFLAGS="-tags 'integration no-docker'" \ - "${KUBE_REPO_ROOT}/hack/test-go.sh" test/integration + "${KUBE_ROOT}/hack/test-go.sh" test/integration echo "" echo "Integration scenario ..." diff --git a/hack/verify-boilerplate.sh b/hack/verify-boilerplate.sh index a2c01da504b..b9c05db8c22 100755 --- a/hack/verify-boilerplate.sh +++ b/hack/verify-boilerplate.sh @@ -14,13 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -REPO_ROOT="$(cd "$(dirname "$0")/../" && pwd -P)" +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. result=0 -gofiles="$(find ${REPO_ROOT} -type f | grep "[.]go$" | grep -v "Godeps/\|third_party/\|release/\|_?output/|target/")" +gofiles="$(find "${KUBE_ROOT}" -type f | grep "[.]go$" | grep -v "Godeps/\|third_party/\|release/\|_?output/|target/")" for file in ${gofiles}; do - if [[ "$(${REPO_ROOT}/hooks/boilerplate.sh "${file}")" -eq "0" ]]; then + if [[ "$("${KUBE_ROOT}/hooks/boilerplate.sh" "${file}")" -eq "0" ]]; then echo "Boilerplate header is wrong for: ${file}" result=1 fi @@ -29,8 +29,8 @@ done dirs=("cluster" "hack" "hooks") for dir in ${dirs[@]}; do - for file in $(grep -r -l "" "${REPO_ROOT}/${dir}/" | grep "[.]sh"); do - if [[ "$(${REPO_ROOT}/hooks/boilerplate.sh "${file}")" -eq "0" ]]; then + for file in $(grep -r -l "" "${KUBE_ROOT}/${dir}/" | grep "[.]sh"); do + if [[ "$("${KUBE_ROOT}/hooks/boilerplate.sh" "${file}")" -eq "0" ]]; then echo "Boilerplate header is wrong for: ${file}" result=1 fi diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh index d929d6dcc3b..925030c7c22 100755 --- a/hack/verify-gofmt.sh +++ b/hack/verify-gofmt.sh @@ -23,9 +23,9 @@ if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.2|go1.3') ]]; then exit 0 fi -REPO_ROOT="$(cd "$(dirname "$0")/../" && pwd -P)" +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. -files="$(find ${REPO_ROOT} -type f | grep "[.]go$" | grep -v "third_party/\|release/\|_?output/\|target/\|Godeps/")" +files="$(find "${KUBE_ROOT}" -type f | grep "[.]go$" | grep -v "third_party/\|release/\|_?output/\|target/\|Godeps/")" bad=$(gofmt -s -l ${files}) if [[ -n "${bad}" ]]; then echo "$bad"