From 109c68995fee9f2a5e7e4ad436c73064e5383bac Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 8 Feb 2022 17:39:01 +0000 Subject: [PATCH] ci: simplify kind/kubectl environment (#22) --- .ci/Jenkinsfile | 33 +++---------------------- .ci/scripts/install-kind.sh | 43 --------------------------------- .ci/scripts/install-kubectl.sh | 44 ---------------------------------- .ci/scripts/kind-setup.sh | 23 ------------------ 4 files changed, 3 insertions(+), 140 deletions(-) delete mode 100755 .ci/scripts/install-kind.sh delete mode 100755 .ci/scripts/install-kubectl.sh delete mode 100755 .ci/scripts/kind-setup.sh diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index b2ccfc8c270..4f81fb5e549 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -1,6 +1,6 @@ #!/usr/bin/env groovy -@Library('apm@feature/use-internal-ci') _ +@Library('apm@current') _ pipeline { agent { label 'ubuntu-20.04 && immutable' } @@ -100,13 +100,9 @@ pipeline { steps { withGithubNotify(context: "K8s-${PLATFORM}") { withMageEnv(){ - withEnv(["K8S_VERSION=v1.23.0", "KIND_VERSION=v0.11.1", "KUBECONFIG=${env.WORKSPACE}/kubecfg"]){ + withKindEnv(k8sVersion: 'v1.23.0', kindVersion: 'v0.11.1') { dir("${BASE_DIR}"){ - retryWithSleep(retries: 2, seconds: 5, backoff: true){ sh(label: "Install kind", script: ".ci/scripts/install-kind.sh") } - retryWithSleep(retries: 2, seconds: 5, backoff: true){ sh(label: "Install kubectl", script: ".ci/scripts/install-kubectl.sh") } - withKindEnv() { - sh(label: "Deploy to kubernetes",script: "make -C deploy/kubernetes test") - } + sh(label: "Deploy to kubernetes",script: "make -C deploy/kubernetes test") } } } @@ -155,29 +151,6 @@ pipeline { } } -// See https://github.com/elastic/beats/pull/21857 -def withKindEnv(Closure body) { - try { - //sh(label: "Setup kind", script: ".ci/scripts/kind-setup.sh") - // Add some environmental resilience when setup does not work the very first time. - def i = 0 - retryWithSleep(retries: 3, seconds: 5, backoff: true){ - try { - sh(label: "Setup kind", script: ".ci/scripts/kind-setup.sh") - } catch(err) { - i++ - sh(label: 'Delete cluster', script: 'kind delete cluster') - if (i > 2) { - error("Setup kind failed with error '${err.toString()}'") - } - } - } - body() - } finally { - sh(label: 'Delete cluster', script: 'kind delete cluster') - } -} - def withPackageEnv(platform, Closure body) { if (isUnix()) { if (platform.contains('macosx')) { diff --git a/.ci/scripts/install-kind.sh b/.ci/scripts/install-kind.sh deleted file mode 100755 index 1b0aa3d7914..00000000000 --- a/.ci/scripts/install-kind.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -set -exuo pipefail - -MSG="environment variable missing." -DEFAULT_HOME="/usr/local" -KIND_VERSION=${KIND_VERSION:?$MSG} -HOME=${HOME:?$DEFAULT_HOME} -KIND_CMD="${HOME}/bin/kind" - -if command -v kind -then - set +e - echo "Found Kind. Checking version.." - FOUND_KIND_VERSION=$(kind --version 2>&1 >/dev/null | awk '{print $3}') - if [ "$FOUND_KIND_VERSION" == "$KIND_VERSION" ] - then - echo "Versions match. No need to install Kind. Exiting." - exit 0 - fi - set -e -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" - -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 deleted file mode 100755 index 647213510a8..00000000000 --- a/.ci/scripts/install-kubectl.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -set -exuo pipefail - -MSG="parameter missing." -DEFAULT_HOME="/usr/local" -K8S_VERSION=${K8S_VERSION:?$MSG} -HOME=${HOME:?$DEFAULT_HOME} -KUBECTL_CMD="${HOME}/bin/kubectl" - -if command -v kubectl -then - set +e - 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 - set -e -fi - -echo "UNMET DEP: Installing kubectl" - -mkdir -p "${HOME}/bin" - -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/kind-setup.sh b/.ci/scripts/kind-setup.sh deleted file mode 100755 index d2c9eeeb771..00000000000 --- a/.ci/scripts/kind-setup.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -set -exuo pipefail - -kind create cluster --image kindest/node:${K8S_VERSION} --config - <