From ae610664d189bf7fbd47ee60ffebda65edb50ab1 Mon Sep 17 00:00:00 2001 From: PrimalPimmy Date: Fri, 18 Aug 2023 11:00:05 +0530 Subject: [PATCH] using k3s action Signed-off-by: PrimalPimmy --- .github/workflows/ci-test-ginkgo.yml | 6 ++-- .github/workflows/scripts/install_k3s.sh | 36 +++--------------------- tests/tests_suite_test.go | 4 +-- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci-test-ginkgo.yml b/.github/workflows/ci-test-ginkgo.yml index cb46ee2..a517e37 100644 --- a/.github/workflows/ci-test-ginkgo.yml +++ b/.github/workflows/ci-test-ginkgo.yml @@ -28,8 +28,10 @@ jobs: with: go-version: "v1.20" - - name: Create k3s cluster - run: ./.github/workflows/scripts/install_k3s.sh + - uses: debianmaster/actions-k3s@master + id: k3s + with: + version: 'latest' - name: Test connectivity run: kubectl get pods -A diff --git a/.github/workflows/scripts/install_k3s.sh b/.github/workflows/scripts/install_k3s.sh index b3ee34f..a34ef29 100755 --- a/.github/workflows/scripts/install_k3s.sh +++ b/.github/workflows/scripts/install_k3s.sh @@ -2,41 +2,14 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright 2021 Authors of KubeArmor -if [ "$RUNTIME" == "" ]; then - if [ -S /var/run/docker.sock ]; then - RUNTIME="docker" - elif [ -S /var/run/crio/crio.sock ]; then - RUNTIME="crio" - else # default - RUNTIME="containerd" - fi -fi +RUNTIME="containerd" + -# create a single-node K3s cluster -if [ "$RUNTIME" == "docker" ]; then # docker - CGROUP_SYSTEMD=$(docker info 2> /dev/null | grep -i cgroup | grep systemd | wc -l) - if [ $CGROUP_SYSTEMD == 1 ]; then - curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.23.9+k3s1" K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik --docker --kubelet-arg cgroup-driver=systemd" sh - - [[ $? != 0 ]] && echo "Failed to install k3s" && exit 1 - else # cgroupfs - curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.23.9+k3s1" K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik --docker" sh - - [[ $? != 0 ]] && echo "Failed to install k3s" && exit 1 - fi -elif [ "$RUNTIME" == "crio" ]; then # cri-o - curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik --container-runtime-endpoint unix:///var/run/crio/crio.sock --kubelet-arg cgroup-driver=systemd" sh - - [[ $? != 0 ]] && echo "Failed to install k3s" && exit 1 -else # use containerd by default curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik" sh - [[ $? != 0 ]] && echo "Failed to install k3s" && exit 1 -fi -if [[ $(hostname) = kubearmor-dev* ]]; then - mkdir -p /home/vagrant/.kube - sudo cp /etc/rancher/k3s/k3s.yaml /home/vagrant/.kube/config - sudo chown -R vagrant:vagrant /home/vagrant/.kube - echo "export KUBECONFIG=/home/vagrant/.kube/config" | tee -a /home/vagrant/.bashrc - PATH=$PATH:/bin:/usr/bin:/usr/local/bin -else + + KUBEDIR=$HOME/.kube KUBECONFIG=$KUBEDIR/config [[ ! -d $KUBEDIR ]] && mkdir $KUBEDIR @@ -47,7 +20,6 @@ else sudo cp /etc/rancher/k3s/k3s.yaml $KUBECONFIG sudo chown $USER:$USER $KUBECONFIG echo "export KUBECONFIG=$KUBECONFIG" | tee -a ~/.bashrc -fi echo "wait for initialization" sleep 15 diff --git a/tests/tests_suite_test.go b/tests/tests_suite_test.go index 48a4ea0..0851a50 100644 --- a/tests/tests_suite_test.go +++ b/tests/tests_suite_test.go @@ -1,4 +1,4 @@ -package test +package k8tlstest import ( "testing" @@ -9,5 +9,5 @@ import ( func TestTests(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Tests Suite") + RunSpecs(t, "K8tls Tests Suite") }