mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 18:28:13 +00:00 
			
		
		
		
	Merge pull request #72861 from BenTheElder/slightly-less-bash-fire
fix bugs in get-kube scripts
This commit is contained in:
		| @@ -39,7 +39,7 @@ set -o errexit | ||||
| set -o nounset | ||||
| set -o pipefail | ||||
|  | ||||
| KUBE_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd) | ||||
| KUBE_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) | ||||
|  | ||||
| KUBERNETES_RELEASE_URL="${KUBERNETES_RELEASE_URL:-https://dl.k8s.io}" | ||||
|  | ||||
| @@ -50,7 +50,7 @@ function detect_kube_release() { | ||||
|  | ||||
|   if [[ ! -e "${KUBE_ROOT}/version" ]]; then | ||||
|     echo "Can't determine Kubernetes release." >&2 | ||||
|     echo "${BASH_SOURCE} should only be run from a prebuilt Kubernetes release." >&2 | ||||
|     echo "${BASH_SOURCE[0]} should only be run from a prebuilt Kubernetes release." >&2 | ||||
|     echo "Did you mean to use get-kube.sh instead?" >&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| @@ -59,7 +59,8 @@ function detect_kube_release() { | ||||
| } | ||||
|  | ||||
| function detect_client_info() { | ||||
|   local kernel=$(uname -s) | ||||
|   local kernel machine | ||||
|   kernel="$(uname -s)" | ||||
|   case "${kernel}" in | ||||
|     Darwin) | ||||
|       CLIENT_PLATFORM="darwin" | ||||
| @@ -76,7 +77,7 @@ function detect_client_info() { | ||||
|  | ||||
|   # TODO: migrate the kube::util::host_platform function out of hack/lib and | ||||
|   # use it here. | ||||
|   local machine=$(uname -m) | ||||
|   machine="$(uname -m)" | ||||
|   case "${machine}" in | ||||
|     x86_64*|i?86_64*|amd64*) | ||||
|       CLIENT_ARCH="amd64" | ||||
| @@ -92,7 +93,7 @@ function detect_client_info() { | ||||
|       ;; | ||||
|     s390x*) | ||||
|       CLIENT_ARCH="s390x" | ||||
|       ;;	   | ||||
|       ;; | ||||
|     *) | ||||
|       echo "Unknown, unsupported architecture (${machine})." >&2 | ||||
|       echo "Supported architectures x86_64, i686, arm, arm64, s390x." >&2 | ||||
| @@ -132,9 +133,10 @@ function download_tarball() { | ||||
|     exit 4 | ||||
|   fi | ||||
|   echo | ||||
|   local md5sum=$(md5sum_file "${download_path}/${file}") | ||||
|   local md5sum sha1sum | ||||
|   md5sum=$(md5sum_file "${download_path}/${file}") | ||||
|   echo "md5sum(${file})=${md5sum}" | ||||
|   local sha1sum=$(sha1sum_file "${download_path}/${file}") | ||||
|   sha1sum=$(sha1sum_file "${download_path}/${file}") | ||||
|   echo "sha1sum(${file})=${sha1sum}" | ||||
|   echo | ||||
|   # TODO: add actual verification | ||||
| @@ -151,8 +153,8 @@ function extract_arch_tarball() { | ||||
|   # Tarball looks like kubernetes/{client,server}/bin/BINARY" | ||||
|   tar -xzf "${tarfile}" --strip-components 3 -C "${platforms_dir}" | ||||
|   # Create convenience symlink | ||||
|   ln -sf "${platforms_dir}" "$(dirname ${tarfile})/bin" | ||||
|   echo "Add '$(dirname ${tarfile})/bin' to your PATH to use newly-installed binaries." | ||||
|   ln -sf "${platforms_dir}" "$(dirname "${tarfile}")/bin" | ||||
|   echo "Add '$(dirname "${tarfile}")/bin' to your PATH to use newly-installed binaries." | ||||
| } | ||||
|  | ||||
| detect_kube_release | ||||
| @@ -213,7 +215,7 @@ fi | ||||
|  | ||||
| if [[ -z "${KUBERNETES_SKIP_CONFIRM-}" ]]; then | ||||
|   echo "Is this ok? [Y]/n" | ||||
|   read confirm | ||||
|   read -r confirm | ||||
|   if [[ "${confirm}" =~ ^[nN]$ ]]; then | ||||
|     echo "Aborting." | ||||
|     exit 1 | ||||
|   | ||||
| @@ -23,9 +23,9 @@ set -o pipefail | ||||
| KUBE_HOST=${KUBE_HOST:-localhost} | ||||
| KUBELET_KUBECONFIG=${KUBELET_KUBECONFIG:-"/var/run/kubernetes/kubelet.kubeconfig"} | ||||
|  | ||||
| declare -r RED="\033[0;31m" | ||||
| declare -r GREEN="\033[0;32m" | ||||
| declare -r YELLOW="\033[0;33m" | ||||
| declare -r RED="\\033[0;31m" | ||||
| declare -r GREEN="\\033[0;32m" | ||||
| declare -r YELLOW="\\033[0;33m" | ||||
|  | ||||
| function echo_green { | ||||
|   echo -e "${GREEN}$1"; tput sgr0 | ||||
| @@ -49,7 +49,7 @@ function run { | ||||
|     echo_green "SUCCESS" | ||||
|   else | ||||
|     echo_red "FAILED" | ||||
|     echo $output >&2 | ||||
|     echo "${output}" >&2 | ||||
|     exit 1 | ||||
|   fi | ||||
| } | ||||
| @@ -58,13 +58,14 @@ function run { | ||||
| # Args: the IP address of the API server (e.g. "http://localhost:8080"), destination file path | ||||
| function create-kubelet-kubeconfig() { | ||||
|   #local api_addr="${1}" | ||||
|   local destination="${2}" | ||||
|   local destination dest_dir | ||||
|   destination="${2}" | ||||
|   if [[ -z "${destination}" ]]; then | ||||
|     echo "Must provide destination path to create Kubelet kubeconfig file!" | ||||
|     exit 1 | ||||
|   fi | ||||
|   echo "Creating Kubelet kubeconfig file" | ||||
|   local dest_dir="$(dirname "${destination}")" | ||||
|   dest_dir="$(dirname "${destination}")" | ||||
|   mkdir -p "${dest_dir}" &>/dev/null || sudo mkdir -p "${dest_dir}" | ||||
|   sudo=$(test -w "${dest_dir}" || echo "sudo -E") | ||||
|   cat <<EOF | ${sudo} tee "${destination}" > /dev/null | ||||
| @@ -85,7 +86,7 @@ EOF | ||||
|  | ||||
| function create_cluster { | ||||
|   echo "Creating a local cluster:" | ||||
|   echo -e -n "\tStarting kubelet..." | ||||
|   echo -e -n "\\tStarting kubelet..." | ||||
|   create-kubelet-kubeconfig "http://localhost:8080" "${KUBELET_KUBECONFIG}" | ||||
|   run "docker run \ | ||||
|   --volume=/:/rootfs:ro \ | ||||
| @@ -102,8 +103,8 @@ function create_cluster { | ||||
|   k8s.gcr.io/hyperkube-${arch}:${release} \ | ||||
|     /hyperkube kubelet \ | ||||
|       --containerized \ | ||||
|       --hostname-override="127.0.0.1" \ | ||||
|       --address="0.0.0.0" \ | ||||
|       --hostname-override=127.0.0.1 \ | ||||
|       --address=0.0.0.0 \ | ||||
|       --kubeconfig=${KUBELET_KUBECONFIG} \ | ||||
|       --pod-manifest-path=/etc/kubernetes/manifests \ | ||||
|       --allow-privileged=true \ | ||||
| @@ -113,7 +114,8 @@ function create_cluster { | ||||
|  | ||||
|   echo -e -n "\tWaiting for master components to start..." | ||||
|   while true; do | ||||
|     local running_count=$(kubectl -s=http://${KUBE_HOST}:8080 get pods --no-headers --namespace=kube-system 2>/dev/null | grep "Running" | wc -l) | ||||
|     local running_count | ||||
|     running_count=$(kubectl "-s=http://${KUBE_HOST}:8080" get pods --no-headers --namespace=kube-system 2>/dev/null | grep -c "Running") | ||||
|     # We expect to have 3 running pods - etcd, master and kube-proxy. | ||||
|     if [ "$running_count" -ge 3 ]; then | ||||
|       break | ||||
| @@ -124,7 +126,7 @@ function create_cluster { | ||||
|   echo_green "SUCCESS" | ||||
|   echo_green "Cluster created!" | ||||
|   echo "" | ||||
|   kubectl -s http://${KUBE_HOST}:8080 clusterinfo | ||||
|   kubectl -s "http://${KUBE_HOST}:8080" clusterinfo | ||||
| } | ||||
|  | ||||
| function get_latest_version_number { | ||||
| @@ -172,7 +174,7 @@ fi | ||||
|  | ||||
| kubectl_url="https://storage.googleapis.com/kubernetes-release/release/${release}/bin/${platform}/${arch}/kubectl" | ||||
|  | ||||
| if [[ $(ls . | grep ^kubectl$ | wc -l) -lt 1 ]]; then | ||||
| if [[ ! -f ./kubectl ]]; then | ||||
|   echo -n "Downloading kubectl binary..." | ||||
|   if [[ $(which wget) ]]; then | ||||
|     run "wget ${kubectl_url}" | ||||
| @@ -195,7 +197,7 @@ create_cluster | ||||
| echo "" | ||||
| echo "" | ||||
| echo "To list the nodes in your cluster run" | ||||
| echo_yellow "\tkubectl -s=http://${KUBE_HOST}:8080 get nodes" | ||||
| echo_yellow "\\tkubectl -s=http://${KUBE_HOST}:8080 get nodes" | ||||
| echo "" | ||||
| echo "To run your first pod run" | ||||
| echo_yellow "\tkubectl -s http://${KUBE_HOST}:8080 run nginx --image=nginx --port=80" | ||||
| echo_yellow "\\tkubectl -s http://${KUBE_HOST}:8080 run nginx --image=nginx --port=80" | ||||
|   | ||||
| @@ -85,10 +85,11 @@ KUBE_CI_VERSION_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)-([a | ||||
| #   KUBE_VERSION | ||||
| function set_binary_version() { | ||||
|   if [[ "${1}" =~ "/" ]]; then | ||||
|     export KUBE_VERSION=$(curl -fsSL --retry 5 "https://dl.k8s.io/${1}.txt") | ||||
|     KUBE_VERSION=$(curl -fsSL --retry 5 "https://dl.k8s.io/${1}.txt") | ||||
|   else | ||||
|     export KUBE_VERSION=${1} | ||||
|     KUBE_VERSION=${1} | ||||
|   fi | ||||
|   export KUBE_VERSION | ||||
| } | ||||
|  | ||||
| # Use the script from inside the Kubernetes tarball to fetch the client and | ||||
| @@ -129,7 +130,7 @@ fi | ||||
| if [[ -d "./kubernetes" ]]; then | ||||
|   if [[ -z "${KUBERNETES_SKIP_CONFIRM-}" ]]; then | ||||
|     echo "'kubernetes' directory already exist. Should we skip download step and start to create cluster based on it? [Y]/n" | ||||
|     read confirm | ||||
|     read -r confirm | ||||
|     if [[ ! "${confirm}" =~ ^[nN]$ ]]; then | ||||
|       echo "Skipping download step." | ||||
|       create_cluster | ||||
| @@ -143,10 +144,8 @@ fi | ||||
| kernel=$(uname -s) | ||||
| case "${kernel}" in | ||||
|   Darwin) | ||||
|     platform="darwin" | ||||
|     ;; | ||||
|   Linux) | ||||
|     platform="linux" | ||||
|     ;; | ||||
|   *) | ||||
|     echo "Unknown, unsupported platform: ${kernel}." >&2 | ||||
| @@ -158,16 +157,12 @@ esac | ||||
| machine=$(uname -m) | ||||
| case "${machine}" in | ||||
|   x86_64*|i?86_64*|amd64*) | ||||
|     arch="amd64" | ||||
|     ;; | ||||
|   aarch64*|arm64*) | ||||
|     arch="arm64" | ||||
|     ;; | ||||
|   arm*) | ||||
|     arch="arm" | ||||
|     ;; | ||||
|   i?86*) | ||||
|     arch="386" | ||||
|     ;; | ||||
|   *) | ||||
|     echo "Unknown, unsupported architecture (${machine})." >&2 | ||||
| @@ -224,7 +219,7 @@ fi | ||||
|  | ||||
| if [[ -z "${KUBERNETES_SKIP_CONFIRM-}" ]]; then | ||||
|   echo "Is this ok? [Y]/n" | ||||
|   read confirm | ||||
|   read -r confirm | ||||
|   if [[ "${confirm}" =~ ^[nN]$ ]]; then | ||||
|     echo "Aborting." | ||||
|     exit 0 | ||||
|   | ||||
| @@ -31,9 +31,6 @@ | ||||
| ./cluster/gce/upgrade-aliases.sh | ||||
| ./cluster/gce/upgrade.sh | ||||
| ./cluster/gce/util.sh | ||||
| ./cluster/get-kube-binaries.sh | ||||
| ./cluster/get-kube-local.sh | ||||
| ./cluster/get-kube.sh | ||||
| ./cluster/images/conformance/run_e2e.sh | ||||
| ./cluster/images/etcd-empty-dir-cleanup/etcd-empty-dir-cleanup.sh | ||||
| ./cluster/juju/prereqs/ubuntu-juju.sh | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Prow Robot
					Kubernetes Prow Robot