From addf5f3401fcde78a4ed74caa3191b36dd1aab80 Mon Sep 17 00:00:00 2001 From: Kevin Zhao Date: Mon, 18 Dec 2017 14:20:11 +0800 Subject: [PATCH] Add architecture check when downloading helm and kubectl There is an issue that setup-kubectl.sh and setup-helm.sh can only download helm and kubectl for X86_64, but it cannot handle other architectrues like arm64 or ppc64le. This patch detects architecture and make the script architecture-aware, so the script can download proper helm and kubectl for the corresponding arm64 and ppc64le architectures, in addition to X86_64. Closes-Bug: #1738743 Change-Id: I58a39268040797fdb3e39b9ff10b2cd7e0822386 Signed-off-by: Kevin Zhao --- tools/get_arch.sh | 16 ++++++++++++++++ tools/helm_versions.sh | 2 +- tools/setup-kubectl.sh | 4 +++- tools/setup_helm.sh | 6 ++++-- tools/test.sh | 3 ++- 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100755 tools/get_arch.sh diff --git a/tools/get_arch.sh b/tools/get_arch.sh new file mode 100755 index 000000000..9e39e37d1 --- /dev/null +++ b/tools/get_arch.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +function is_arch { + [[ "$(uname -m)" == "$1" ]] +} + +if is_arch "x86_64"; then + ARCH="amd64" +elif is_arch "aarch64"; then + ARCH="arm64" +elif is_arch "ppc64le"; then + ARCH="ppc64le" +else + ARCH=$(uname -m) + exit "Kolla Kubernetes unsupported architecture $ARCH" +fi diff --git a/tools/helm_versions.sh b/tools/helm_versions.sh index 48b3cb992..f7489a9cd 100644 --- a/tools/helm_versions.sh +++ b/tools/helm_versions.sh @@ -1,4 +1,4 @@ HELM_VERSION="2.4.2" HELM_TEMPLATE_URL="https://github.com/technosophos/helm-template/releases/download/2.2.2%2B1/helm-template-linux-2.2.2.1.tgz" -HELM_URL="http://storage.googleapis.com/kubernetes-helm/helm-v$HELM_VERSION-linux-amd64.tar.gz" +HELM_URL="http://storage.googleapis.com/kubernetes-helm/helm-v$HELM_VERSION-linux-${ARCH}.tar.gz" diff --git a/tools/setup-kubectl.sh b/tools/setup-kubectl.sh index d4b4386f7..1d3e72c4a 100755 --- a/tools/setup-kubectl.sh +++ b/tools/setup-kubectl.sh @@ -2,9 +2,11 @@ # https://gist.github.com/FrankDeGroot/8cbec84eabfebcf2f2e7 echo "Finding latest kubectl" +# Returns $ARCH, which can be amd64, arm64 and ppc64le +. tools/get_arch.sh # curl -s https://github.com/kubernetes/kubernetes/releases/latest | awk -F '[<>]' '/.*/ { match($0, "tag/([^\"]+)",a); print a[1] }' LATEST=$(wget -qO- https://github.com/kubernetes/kubernetes/releases/latest | awk -F '[<>]' '/href="\/kubernetes\/kubernetes\/tree\/.*"/ { match($0, "tree/([^\"]+)",a); print a[1] }' | head -1) echo "Getting kubectl-$LATEST" -sudo wget -NP /usr/bin http://storage.googleapis.com/kubernetes-release/release/$LATEST/bin/linux/amd64/kubectl +sudo wget -NP /usr/bin http://storage.googleapis.com/kubernetes-release/release/$LATEST/bin/linux/$ARCH/kubectl sudo chmod 755 /usr/bin/kubectl diff --git a/tools/setup_helm.sh b/tools/setup_helm.sh index 9a7e27314..97f9e24a9 100755 --- a/tools/setup_helm.sh +++ b/tools/setup_helm.sh @@ -2,9 +2,11 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )" -. tools/helm_versions.sh +# Returns $ARCH, which can be amd64, arm64 and ppc64le +. tools/get_arch.sh +. tools/helm_versions.sh -curl "$HELM_URL" | sudo tar --strip-components 1 -C /usr/bin linux-amd64/helm -zxf - +curl "$HELM_URL" | sudo tar --strip-components 1 -C /usr/bin linux-$ARCH/helm -zxf - if [ ! -e ~/.kube/config ]; then mkdir -p ~/.kube sudo cat /etc/kubernetes/kubelet.conf > ~/.kube/config diff --git a/tools/test.sh b/tools/test.sh index afc0f8ee5..430fdd568 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -9,12 +9,13 @@ grep orchestration_engine etc/kolla/globals.yml || echo orchestration_engine: KU #sudo yum install -y golang-bin || sudo apt-get install -y golang #tools/build_helm_templates.sh set -x +. tools/get_arch.sh . tools/helm_versions.sh mkdir -p ~/.helm/plugins/template curl -L -o /tmp/helm-template.tar.gz "$HELM_TEMPLATE_URL" curl -L -o /tmp/helm.tar.gz "$HELM_URL" mkdir -p ~/bin -tar --strip-components 1 -C ~/bin linux-amd64/helm -zxf /tmp/helm.tar.gz +tar --strip-components 1 -C ~/bin linux-$ARCH/helm -zxf /tmp/helm.tar.gz tar -C ~/.helm/plugins/template/ -zxf /tmp/helm-template.tar.gz export PATH=$PATH:~/bin export HOME=$(cd ~; pwd)