From 6c0470c69abce32bd5894a1b6e152bf984055f0b Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 24 Feb 2021 13:48:59 +0000 Subject: [PATCH] [CI] reuse configuration from the workers if possible (#24184) --- .ci/scripts/install-kind.sh | 21 ++++++++++++++++++--- .ci/scripts/install-kubectl.sh | 32 ++++++++++++++++++++++++++++++-- .ci/scripts/install-terraform.sh | 31 ++++++++++++++++++++++++------- 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/.ci/scripts/install-kind.sh b/.ci/scripts/install-kind.sh index a53c4b3708a..5d3259214e7 100755 --- a/.ci/scripts/install-kind.sh +++ b/.ci/scripts/install-kind.sh @@ -11,7 +11,7 @@ if command -v kind then echo "Found Kind. Checking version.." FOUND_KIND_VERSION=$(kind --version 2>&1 >/dev/null | awk '{print $3}') - if [ $FOUND_KIND_VERSION == $KIND_VERSION ] + if [ "$FOUND_KIND_VERSION" == "$KIND_VERSION" ] then echo "Versions match. No need to install Kind. Exiting." exit 0 @@ -20,7 +20,22 @@ fi echo "UNMET DEP: Installing Kind" +OS=$(uname -s| tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m| tr '[:upper:]' '[:lower:]') +if [ "${ARCH}" == "aarch64" ] ; then + ARCH_SUFFIX=arm64 +else + ARCH_SUFFIX=amd64 +fi + mkdir -p "${HOME}/bin" -curl -sSLo "${KIND_CMD}" "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64" -chmod +x "${KIND_CMD}" +if curl -sSLo "${KIND_CMD}" "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-${OS}-${ARCH_SUFFIX}" ; then + chmod +x "${KIND_CMD}" +else + echo "Something bad with the download, let's delete the corrupted binary" + if [ -e "${KIND_CMD}" ] ; then + rm "${KIND_CMD}" + fi + exit 1 +fi diff --git a/.ci/scripts/install-kubectl.sh b/.ci/scripts/install-kubectl.sh index d0b7080d188..6fbae3eb298 100755 --- a/.ci/scripts/install-kubectl.sh +++ b/.ci/scripts/install-kubectl.sh @@ -7,8 +7,36 @@ K8S_VERSION=${K8S_VERSION:?$MSG} HOME=${HOME:?$DEFAULT_HOME} KUBECTL_CMD="${HOME}/bin/kubectl" +if command -v kubectl +then + echo "Found kubectl. Checking version.." + FOUND_KUBECTL_VERSION=$(kubectl version --client --short 2>&1 >/dev/null | awk '{print $3}') + if [ "${FOUND_KUBECTL_VERSION}" == "${K8S_VERSION}" ] + then + echo "Versions match. No need to install kubectl. Exiting." + exit 0 + fi +fi + +echo "UNMET DEP: Installing kubectl" + mkdir -p "${HOME}/bin" -curl -sSLo "${KUBECTL_CMD}" "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl" -chmod +x "${KUBECTL_CMD}" +OS=$(uname -s| tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m| tr '[:upper:]' '[:lower:]') +if [ "${ARCH}" == "aarch64" ] ; then + ARCH_SUFFIX=arm64 +else + ARCH_SUFFIX=amd64 +fi + +if curl -sSLo "${KUBECTL_CMD}" "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/${OS}/${ARCH_SUFFIX}/kubectl" ; then + chmod +x "${KUBECTL_CMD}" +else + echo "Something bad with the download, let's delete the corrupted binary" + if [ -e "${KUBECTL_CMD}" ] ; then + rm "${KUBECTL_CMD}" + fi + exit 1 +fi diff --git a/.ci/scripts/install-terraform.sh b/.ci/scripts/install-terraform.sh index 4af2e91baab..56250a658a7 100755 --- a/.ci/scripts/install-terraform.sh +++ b/.ci/scripts/install-terraform.sh @@ -7,13 +7,11 @@ TERRAFORM_VERSION=${TERRAFORM_VERSION:?$MSG} HOME=${HOME:?$MSG} TERRAFORM_CMD="${HOME}/bin/terraform" -OS=$(uname -s | tr '[:upper:]' '[:lower:]') - if command -v terraform then echo "Found Terraform. Checking version.." FOUND_TERRAFORM_VERSION=$(terraform --version | awk '{print $2}' | sed s/v//) - if [ $FOUND_TERRAFORM_VERSION == $TERRAFORM_VERSION ] + if [ "$FOUND_TERRAFORM_VERSION" == "$TERRAFORM_VERSION" ] then echo "Versions match. No need to install Terraform. Exiting." exit 0 @@ -24,8 +22,27 @@ echo "UNMET DEP: Installing Terraform" mkdir -p "${HOME}/bin" -curl -sSLo - "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${OS}_amd64.zip" > ${TERRAFORM_CMD}.zip -unzip -o ${TERRAFORM_CMD}.zip -d $(dirname ${TERRAFORM_CMD}) -rm ${TERRAFORM_CMD}.zip +OS=$(uname -s| tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m| tr '[:upper:]' '[:lower:]') +if [ "${ARCH}" == "aarch64" ] ; then + ARCH_SUFFIX=arm64 +elif [ "${ARCH}" == "x86_64" ] ; then + ARCH_SUFFIX=amd64 +elif [ "${ARCH}" == "i686" ] ; then + ARCH_SUFFIX=386 +else + ARCH_SUFFIX=arm +fi + +if curl -sSLo - "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${OS}_${ARCH_SUFFIX}.zip" > "${TERRAFORM_CMD}.zip" ; then + unzip -o "${TERRAFORM_CMD}".zip -d "$(dirname ${TERRAFORM_CMD})" + rm "${TERRAFORM_CMD}".zip -chmod +x "${TERRAFORM_CMD}" + chmod +x "${TERRAFORM_CMD}" +else + echo "Something bad with the download, let's delete the corrupted binary" + if [ -e "${TERRAFORM_CMD}" ] ; then + rm "${TERRAFORM_CMD}" + fi + exit 1 +fi