diff --git a/build/common.sh b/build/common.sh index 4ca4fbb791..bd04c13bc8 100755 --- a/build/common.sh +++ b/build/common.sh @@ -163,7 +163,7 @@ function kube::build::verify_prereqs() { if kube::build::is_osx; then kube::build::docker_available_on_osx || return 1 fi - kube::build::ensure_docker_daemon_connectivity || return 1 + kube::util::ensure_docker_daemon_connectivity || return 1 if (( ${KUBE_VERBOSE} > 6 )); then kube::log::status "Docker Version:" @@ -272,29 +272,6 @@ function kube::build::ensure_docker_in_path() { fi } -function kube::build::ensure_docker_daemon_connectivity { - if ! "${DOCKER[@]}" info > /dev/null 2>&1 ; then - cat <<'EOF' >&2 -Can't connect to 'docker' daemon. please fix and retry. - -Possible causes: - - Docker Daemon not started - - Linux: confirm via your init system - - macOS w/ docker-machine: run `docker-machine ls` and `docker-machine start ` - - macOS w/ Docker for Mac: Check the menu bar and start the Docker application - - DOCKER_HOST hasn't been set or is set incorrectly - - Linux: domain socket is used, DOCKER_* should be unset. In Bash run `unset ${!DOCKER_*}` - - macOS w/ docker-machine: run `eval "$(docker-machine env )"` - - macOS w/ Docker for Mac: domain socket is used, DOCKER_* should be unset. In Bash run `unset ${!DOCKER_*}` - - Other things to check: - - Linux: User isn't in 'docker' group. Add and relogin. - - Something like 'sudo usermod -a -G docker ${USER}' - - RHEL7 bug and workaround: https://bugzilla.redhat.com/show_bug.cgi?id=1119282#c8 -EOF - return 1 - fi -} - function kube::build::ensure_tar() { if [[ -n "${TAR:-}" ]]; then return diff --git a/hack/lib/etcd.sh b/hack/lib/etcd.sh index ae0d15a9cb..03ad07c0f3 100755 --- a/hack/lib/etcd.sh +++ b/hack/lib/etcd.sh @@ -20,18 +20,21 @@ ETCD_VERSION=${ETCD_VERSION:-3.0.14} ETCD_HOST=${ETCD_HOST:-127.0.0.1} ETCD_PORT=${ETCD_PORT:-2379} -kube::etcd::start() { +kube::etcd::validate() { + # validate if in path which etcd >/dev/null || { kube::log::usage "etcd must be in your PATH" exit 1 } + # validate it is not running if pgrep etcd >/dev/null 2>&1; then kube::log::usage "etcd appears to already be running on this machine (`pgrep -l etcd`) (or its a zombie and you need to kill its parent)." kube::log::usage "retry after you resolve this etcd error." exit 1 fi + # validate installed version is at least equal to minimum version=$(etcd --version | tail -n +1 | head -n 1 | cut -d " " -f 3) if [[ "${version}" < "${ETCD_VERSION}" ]]; then export PATH=$KUBE_ROOT/third_party/etcd:$PATH @@ -45,6 +48,11 @@ kube::etcd::start() { exit 1 fi fi +} + +kube::etcd::start() { + # validate before running + kube::etcd::validate # Start etcd ETCD_DIR=${ETCD_DIR:-$(mktemp -d 2>/dev/null || mktemp -d -t test-etcd.XXXXXX)} diff --git a/hack/lib/init.sh b/hack/lib/init.sh index 64a8c1bf95..e4b2554566 100644 --- a/hack/lib/init.sh +++ b/hack/lib/init.sh @@ -156,3 +156,4 @@ kube::realpath() { fi kube::readlinkdashf "$1" } + diff --git a/hack/lib/util.sh b/hack/lib/util.sh index 14cbe0e6f1..20626c0f6b 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -575,5 +575,31 @@ EOF EOF } +# Determines if docker can be run, failures may simply require that the user be added to the docker group. +function kube::util::ensure_docker_daemon_connectivity { + DOCKER=(docker ${DOCKER_OPTS}) + if ! "${DOCKER[@]}" info > /dev/null 2>&1 ; then + cat <<'EOF' >&2 +Can't connect to 'docker' daemon. please fix and retry. + +Possible causes: + - Docker Daemon not started + - Linux: confirm via your init system + - macOS w/ docker-machine: run `docker-machine ls` and `docker-machine start ` + - macOS w/ Docker for Mac: Check the menu bar and start the Docker application + - DOCKER_HOST hasn't been set or is set incorrectly + - Linux: domain socket is used, DOCKER_* should be unset. In Bash run `unset ${!DOCKER_*}` + - macOS w/ docker-machine: run `eval "$(docker-machine env )"` + - macOS w/ Docker for Mac: domain socket is used, DOCKER_* should be unset. In Bash run `unset ${!DOCKER_*}` + - Other things to check: + - Linux: User isn't in 'docker' group. Add and relogin. + - Something like 'sudo usermod -a -G docker ${USER}' + - RHEL7 bug and workaround: https://bugzilla.redhat.com/show_bug.cgi?id=1119282#c8 +EOF + return 1 + fi +} + + # ex: ts=2 sw=2 et filetype=sh diff --git a/hack/local-up-cluster.sh b/hack/local-up-cluster.sh index b0ca0ce3f8..f652b28140 100755 --- a/hack/local-up-cluster.sh +++ b/hack/local-up-cluster.sh @@ -94,6 +94,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh" function usage { echo "This script starts a local kube cluster. " + echo "Example 0: hack/local-up-cluster.sh -h (this 'help' usage description)" echo "Example 1: hack/local-up-cluster.sh -o _output/dockerized/bin/linux/amd64/ (run from docker output)" echo "Example 2: hack/local-up-cluster.sh -O (auto-guess the bin path for your platform)" echo "Example 3: hack/local-up-cluster.sh (build a local copy of the source)" @@ -111,7 +112,7 @@ function guess_built_binary_path { ### Allow user to supply the source directory. GO_OUT=${GO_OUT:-} -while getopts "o:O" OPTION +while getopts "ho:O" OPTION do case $OPTION in o) @@ -126,6 +127,10 @@ do exit 1 fi ;; + h) + usage + exit + ;; ?) usage exit @@ -139,14 +144,6 @@ else echo "skipped the build." fi -function test_docker { - ${DOCKER[@]} ps 2> /dev/null 1> /dev/null - if [ "$?" != "0" ]; then - echo "Failed to successfully run 'docker ps', please verify that docker is installed and \$DOCKER_HOST is set correctly." - exit 1 - fi -} - function test_rkt { if [[ -n "${RKT_PATH}" ]]; then ${RKT_PATH} list 2> /dev/null 1> /dev/null @@ -680,8 +677,11 @@ EOF fi } -if [[ "${CONTAINER_RUNTIME}" == "docker" ]]; then - test_docker +# validate that etcd is: not running, in path, and has minimum required version. +kube::etcd::validate + +if [ "${CONTAINER_RUNTIME}" == "docker" ] && ! kube::util::ensure_docker_daemon_connectivity; then + exit 1 fi if [[ "${CONTAINER_RUNTIME}" == "rkt" ]]; then