From 843b7dd1294342ec257aa4c1ce30fa60df8db790 Mon Sep 17 00:00:00 2001 From: Sylvain Baubeau Date: Sat, 17 Jul 2021 21:15:34 +0200 Subject: [PATCH] Replace minikube with kind --- jenkins/common.yml | 40 +++++++++++++++++ jenkins/skydive.yml | 19 ++++---- scripts/cleanup.sh | 2 +- scripts/{install-istio.sh => istio.sh} | 0 scripts/kind.sh | 47 ++++++++++++++++++++ scripts/{install-minikube.sh => minikube.sh} | 24 +--------- scripts/utils.sh | 27 +++++++++++ 7 files changed, 125 insertions(+), 34 deletions(-) rename scripts/{install-istio.sh => istio.sh} (100%) create mode 100755 scripts/kind.sh rename scripts/{install-minikube.sh => minikube.sh} (89%) create mode 100755 scripts/utils.sh diff --git a/jenkins/common.yml b/jenkins/common.yml index 04d4587..f4b74cf 100644 --- a/jenkins/common.yml +++ b/jenkins/common.yml @@ -186,6 +186,22 @@ cd src/github.com/skydive-project/skydive-ci {script} +- builder: + name: bootstrap-k8s-environment + builders: + - ci-script: + script: | + case "$K8S_PROVIDER" in + minikube) + scripts/minikube.sh install + scripts/minikube.sh start + ;; + *) + scripts/kind.sh install + scripts/kind.sh start + ;; + esac + - parameter: name: skydive-parameters parameters: @@ -318,3 +334,27 @@ run-if-job-successful: "{only-if-successful}" script: | {script} + +- publisher: + name: cleanup-k8s-environment + publishers: + - post-tasks: + - matches: + - log-text: .* + operator: AND + run-if-job-successful: "{only-if-successful}" + script: | + set -v + cd src/github.com/skydive-project/skydive-ci + + if [ "$KEEP_RESOURCES" != "true" ] + then + case "$K8S_PROVIDER" in + minikube) + scripts/minikube.sh stop + ;; + *) + scripts/kind.sh stop + ;; + esac + fi diff --git a/jenkins/skydive.yml b/jenkins/skydive.yml index 62b6443..b8d6644 100644 --- a/jenkins/skydive.yml +++ b/jenkins/skydive.yml @@ -114,26 +114,23 @@ - skydive-default-parameters - skydive-labels: slave-name: baremetal + - string: + name: K8S_PROVIDER + default: "kind" + description: Provider to use to install k8s builders: - skydive-cleanup + - bootstrap-k8s-environment - ci-script: script: | - sudo systemctl restart libvirtd || true - WITH_ISTIO=true . scripts/install-minikube.sh start + . scripts/istio.sh start - skydive-test: - test: BACKEND=elasticsearch scripts/ci/run-istio-tests.sh + test: BACKEND=elasticsearch KUBECONFIG=$HOME/.kube/config scripts/ci/run-istio-tests.sh publishers: - junit: results: tests.xml + - cleanup-k8s-environment - skydive-publishers - - skydive-post-script: - only-if-successful: true - script: | - [ "$KEEP_RESOURCES" = "true" ] || . src/github.com/skydive-project/skydive-ci/scripts/install-minikube.sh stop - - skydive-post-script: - only-if-successful: false - script: | - [ "$KEEP_RESOURCES" = "true" ] || . src/github.com/skydive-project/skydive-ci/scripts/install-minikube.sh delete - job: name: skydive-ovn-k8s-tests diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh index de14b21..d180e57 100755 --- a/scripts/cleanup.sh +++ b/scripts/cleanup.sh @@ -30,7 +30,7 @@ function docker_volume_rm() { function cleanup() { # cleanup minikube - "${CURDIR}/install-minikube.sh" stop + "${CURDIR}/minikube.sh" stop # cleanup podman/runc podman stop -a diff --git a/scripts/install-istio.sh b/scripts/istio.sh similarity index 100% rename from scripts/install-istio.sh rename to scripts/istio.sh diff --git a/scripts/kind.sh b/scripts/kind.sh new file mode 100755 index 0000000..66a2af2 --- /dev/null +++ b/scripts/kind.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + +. $DIR/utils.sh + +install() { + install_binary kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64 +} + +start() { + kind create cluster +} + +stop() { + kind delete cluster +} + +delete() { + kind delete cluster +} + +uninstall() { + uninstall_binary kind +} + +case "$1" in + install) + install + ;; + uninstall) + uninstall + ;; + start) + start + ;; + stop) + stop + ;; + delete) + delete + ;; + *) + echo "$0 [install|uninstall|start|stop|status]" + exit 1 + ;; +esac diff --git a/scripts/install-minikube.sh b/scripts/minikube.sh similarity index 89% rename from scripts/install-minikube.sh rename to scripts/minikube.sh index 61ba8fc..cdb8429 100755 --- a/scripts/install-minikube.sh +++ b/scripts/minikube.sh @@ -2,6 +2,8 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +. $DIR/utils.sh + OS=linux ARCH=amd64 TARGET_DIR=/usr/bin @@ -13,7 +15,6 @@ K8S_VERSION="v1.15.12" KUBECTL_URL="https://storage.googleapis.com/kubernetes-release/release/$K8S_VERSION/bin/$OS/$ARCH/kubectl" [ -z "$WITH_CALICO" ] && WITH_CALICO=false -[ -z "$WITH_ISTIO" ] && WITH_ISTIO=true CALICO_VERSION="v2.6" CALICO_URL="https://docs.projectcalico.org/$CALICO_VERSION/getting-started/kubernetes/installation/hosted/calico.yaml" @@ -32,25 +33,6 @@ case "$MINIKUBE_DRIVER" in ;; esac -uninstall_binary() { - local prog=$1 - sudo rm -f $TARGET_DIR/$prog -} - -install_binary() { - local prog=$1 - local url=$2 - - wget --no-check-certificate -O $prog $url - if [ $? != 0 ]; then - echo "failed to download $url" - exit 1 - fi - - chmod a+x $prog - sudo mv $prog $TARGET_DIR/$prog -} - check_minikube() { minikube version | grep $MINIKUBE_VERSION 2>/dev/null if [ $? != 0 ]; then @@ -127,8 +109,6 @@ start() { $WITH_CALICO && kubectl apply -f $CALICO_URL - $WITH_ISTIO && $DIR/install-istio.sh start - kubectl get services kubernetes kubectl get pods -n kube-system } diff --git a/scripts/utils.sh b/scripts/utils.sh new file mode 100755 index 0000000..bbba34b --- /dev/null +++ b/scripts/utils.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +export PATH=${HOME}/bin:${PATH} + +download_file() { + local path=$1 + local url=$2 + + curl -z $path -o $path -L $url + if [ $? != 0 ]; then + echo "failed to download $url" + exit 1 + fi +} + +uninstall_binary() { + local prog=$1 + sudo rm -f $TARGET_DIR/$prog +} + +install_binary() { + local prog=$1 + local url=$2 + + download_file $HOME/bin/$prog $url + chmod a+x $HOME/bin/$prog +}