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