From 72653ac2b0b57deedd276c3abc8d19f9085b3154 Mon Sep 17 00:00:00 2001 From: Pavel Zorin Date: Wed, 8 Nov 2023 19:25:12 +0100 Subject: [PATCH] [CI]Buildkite k8s tests migration (#3680) * Buildkite k8s tests * Buildkite k8s tests * Added kind setup script * Added kind setup script * Added kind setup script * Added kind setup script * Branch configuration for k8s tests * transformed to matrix build * transformed to matrix build * transformed to matrix build * transformed to matrix build * transformed to matrix build * transformed to matrix build * transformed to matrix build * Removed k8s tests from Jenkinsfile * Run k8s tests on every PR * Fix review comments * install kind: moved path update to the top * Moved PATH declaration to the top leve script * Removed junit-annotate from k8s tests * Moved k8s tests to upper level in the pipeline --- .buildkite/pipeline.yml | 25 +++++++++++ .buildkite/scripts/install-kind.sh | 45 ++++++++++++++++++++ .buildkite/scripts/install-kubectl.sh | 45 ++++++++++++++++++++ .buildkite/scripts/steps/k8s-tests.sh | 30 +++++++++++++ .buildkite/scripts/steps/unit-tests.sh | 6 ++- .ci/Jenkinsfile | 58 +------------------------- 6 files changed, 151 insertions(+), 58 deletions(-) create mode 100644 .buildkite/scripts/install-kind.sh create mode 100644 .buildkite/scripts/install-kubectl.sh create mode 100644 .buildkite/scripts/steps/k8s-tests.sh diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index cbd0ae35884..fc1ff11871a 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -122,6 +122,31 @@ steps: - unit-tests-macos-13-arm allow_dependency_failure: true + - group: "K8s tests" + key: "k8s-tests" + steps: + - label: "K8s tests: {{matrix.k8s_version}}" + env: + K8S_VERSION: "v{{matrix.k8s_version}}" + KIND_VERSION: "v0.20.0" + command: ".buildkite/scripts/steps/k8s-tests.sh" + artifact_paths: + - "build/TEST-**" + - "build/diagnostics/*" + - "coverage.out" + agents: + provider: "gcp" + image: "family/core-ubuntu-2204" + matrix: + setup: + k8s_version: + - "1.28.0" + - "1.27.3" + - "1.26.6" + retry: + manual: + allowed: true + - label: ":sonarqube: Continuous Code Inspection" env: VAULT_SONAR_TOKEN_PATH: "kv/ci-shared/platform-ingest/elastic/elastic-agent/sonar-analyze-token" diff --git a/.buildkite/scripts/install-kind.sh b/.buildkite/scripts/install-kind.sh new file mode 100644 index 00000000000..171480d7685 --- /dev/null +++ b/.buildkite/scripts/install-kind.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -exuo pipefail + +echo "--- Install Kind" + +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 "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/.buildkite/scripts/install-kubectl.sh b/.buildkite/scripts/install-kubectl.sh new file mode 100644 index 00000000000..fc558448c6c --- /dev/null +++ b/.buildkite/scripts/install-kubectl.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "--- Install kubectl" + +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 "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/.buildkite/scripts/steps/k8s-tests.sh b/.buildkite/scripts/steps/k8s-tests.sh new file mode 100644 index 00000000000..bb9affe2edc --- /dev/null +++ b/.buildkite/scripts/steps/k8s-tests.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -euo pipefail + +export PATH=$HOME/bin:${PATH} +source .buildkite/scripts/install-kubectl.sh +source .buildkite/scripts/install-kind.sh + +kind create cluster --image "kindest/node:${K8S_VERSION}" --config - <