Merge pull request #38713 from alejandroEsc/ae/localup1

Automatic merge from submit-queue (batch tested with PRs 37468, 36546, 38713, 38902, 38614)

local-up-cluster additions

**What this PR does / why we need it**:
Changes to local-cluster-up: These include: 1)  a simple additional help option. 2) additional error message to not being able to run `docker ps`. 3) fail faster when etcd is not found in path. Hopefully these make developing a bit more pleasant.

**Release note**:
```NONE
```
This commit is contained in:
Kubernetes Submit Queue 2016-12-16 18:55:32 -08:00 committed by GitHub
commit 9a1c607673
5 changed files with 48 additions and 36 deletions

View File

@ -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 <name>`
- 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 <name>)"`
- 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

View File

@ -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)}

View File

@ -156,3 +156,4 @@ kube::realpath() {
fi
kube::readlinkdashf "$1"
}

View File

@ -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 <name>`
- 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 <name>)"`
- 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

View File

@ -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