From e299ffb2ec044e21eae9f2d26a3eeb0d637fd617 Mon Sep 17 00:00:00 2001 From: Robert Bost Date: Fri, 6 Aug 2021 16:52:58 -0600 Subject: [PATCH] GitHub Action for unit tests and e2e test on k3s/k3d and minikube (docker and cri-o). (#118) --- .github/workflows/assets/busybox-pod.yaml | 11 +++ .../assets/placeholder-kubeconfig.yaml | 17 +++++ .github/workflows/k3d-e2e.yml | 74 +++++++++++++++++++ .github/workflows/minikube-e2e-crio.yaml | 65 ++++++++++++++++ .github/workflows/minikube-e2e-docker.yaml | 64 ++++++++++++++++ .github/workflows/unit-test.yml | 25 +++++++ 6 files changed, 256 insertions(+) create mode 100644 .github/workflows/assets/busybox-pod.yaml create mode 100644 .github/workflows/assets/placeholder-kubeconfig.yaml create mode 100644 .github/workflows/k3d-e2e.yml create mode 100644 .github/workflows/minikube-e2e-crio.yaml create mode 100644 .github/workflows/minikube-e2e-docker.yaml create mode 100644 .github/workflows/unit-test.yml diff --git a/.github/workflows/assets/busybox-pod.yaml b/.github/workflows/assets/busybox-pod.yaml new file mode 100644 index 0000000..4091410 --- /dev/null +++ b/.github/workflows/assets/busybox-pod.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Pod +metadata: + name: busybox-sleep +spec: + containers: + - name: busybox + image: busybox + args: + - sleep + - "10000" diff --git a/.github/workflows/assets/placeholder-kubeconfig.yaml b/.github/workflows/assets/placeholder-kubeconfig.yaml new file mode 100644 index 0000000..e424d1d --- /dev/null +++ b/.github/workflows/assets/placeholder-kubeconfig.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +clusters: +- cluster: + server: http://example.com + name: example +contexts: +- context: + cluster: example + user: test + name: test +current-context: test +kind: Config +preferences: {} +users: +- name: test + user: + token: xxxxx diff --git a/.github/workflows/k3d-e2e.yml b/.github/workflows/k3d-e2e.yml new file mode 100644 index 0000000..6118b28 --- /dev/null +++ b/.github/workflows/k3d-e2e.yml @@ -0,0 +1,74 @@ +# This is a basic workflow to help you get started with Actions + +name: k3s-e2e + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - uses: AbsaOSS/k3d-action@v1.5.0 + name: "Create Single Cluster" + with: + cluster-name: "test-cluster-1" + args: --agents 1 + + - name: Deploy test pod + run: | + kubectl config use-context k3d-test-cluster-1 + kubectl create -f .github/workflows/assets/busybox-pod.yaml + kubectl wait --for=condition=Ready pod/busybox-sleep + + - name: Build + run: | + make + + - name: Run ksniff privileged + run: | + kubectl config use-context k3d-test-cluster-1 + sleep 60 && pkill kubectl-sniff & + set +e + ./kubectl-sniff busybox-sleep --privileged --namespace default --socket /run/k3s/containerd/containerd.sock --output-file /tmp/output.pcap + set -e + if [ ! -f /tmp/output.pcap ]; then + echo "PCAP not created" + exit 1 + fi + + - if: failure() + name: Check pod and events + run: | + kubectl get pods + kubectl get events + + - name: Build static-tcpdmp + run: | + sudo apt-get install libpcap-dev + make static-tcpdump + make install + + - name: Run ksniff with static tcpdump + run: | + kubectl config use-context k3d-test-cluster-1 + sleep 60 && pkill kubectl-sniff & + set +e + ./kubectl-sniff busybox-sleep --namespace default --output-file /tmp/output.pcap + set -e + if [ ! -f /tmp/output.pcap ]; then + echo "PCAP not created" + exit 1 + fi + diff --git a/.github/workflows/minikube-e2e-crio.yaml b/.github/workflows/minikube-e2e-crio.yaml new file mode 100644 index 0000000..7fb2d45 --- /dev/null +++ b/.github/workflows/minikube-e2e-crio.yaml @@ -0,0 +1,65 @@ +name: minikube-e2e-crio + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Minikube + uses: manusa/actions-setup-minikube@v2.4.2 + with: + minikube version: 'v1.22.0' + kubernetes version: 'v1.21.2' + driver: docker + start args: --wait=all --container-runtime=cri-o + # github token: ${{ secrets.GITHUB_TOKEN }} Uncomment if we have API limit issues + - name: Deploy test pod + run: | + kubectl create -f .github/workflows/assets/busybox-pod.yaml + kubectl wait --for=condition=Ready pod/busybox-sleep + - name: Build + run: | + make + - name: Run ksniff privileged + run: | + sleep 60 && pkill kubectl-sniff & + set +e + ./kubectl-sniff busybox-sleep --privileged --namespace default --output-file /tmp/output.pcap + set -e + if [ ! -f /tmp/output.pcap ]; then + echo "PCAP not created" + exit 1 + fi + - if: failure() + name: Check pod and events + run: | + kubectl get pods + kubectl get events + + - name: Build static-tcpdmp + run: | + sudo apt-get install libpcap-dev + make static-tcpdump + make install + + - name: Run ksniff with static tcpdump + run: | + sleep 60 && pkill kubectl-sniff & + set +e + ./kubectl-sniff busybox-sleep --namespace default --output-file /tmp/output.pcap + set -e + if [ ! -f /tmp/output.pcap ]; then + echo "PCAP not created" + exit 1 + fi diff --git a/.github/workflows/minikube-e2e-docker.yaml b/.github/workflows/minikube-e2e-docker.yaml new file mode 100644 index 0000000..d429686 --- /dev/null +++ b/.github/workflows/minikube-e2e-docker.yaml @@ -0,0 +1,64 @@ +name: minikube-e2e-docker + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Minikube + uses: manusa/actions-setup-minikube@v2.4.2 + with: + minikube version: 'v1.22.0' + kubernetes version: 'v1.21.2' + start args: --wait=all + # github token: ${{ secrets.GITHUB_TOKEN }} Uncomment if we have API limit issues + - name: Deploy test pod + run: | + kubectl create -f .github/workflows/assets/busybox-pod.yaml + kubectl wait --for=condition=Ready pod/busybox-sleep + - name: Build + run: | + make + - name: Run ksniff privileged + run: | + sleep 60 && pkill kubectl-sniff & + set +e + ./kubectl-sniff busybox-sleep --privileged --namespace default --output-file /tmp/output.pcap + set -e + if [ ! -f /tmp/output.pcap ]; then + echo "PCAP not created" + exit 1 + fi + - if: failure() + name: Check pod and events + run: | + kubectl get pods + kubectl get events + + - name: Build static-tcpdmp + run: | + sudo apt-get install libpcap-dev + make static-tcpdump + make install + + - name: Run ksniff with static tcpdump + run: | + sleep 60 && pkill kubectl-sniff & + set +e + ./kubectl-sniff busybox-sleep --namespace default --output-file /tmp/output.pcap + set -e + if [ ! -f /tmp/output.pcap ]; then + echo "PCAP not created" + exit 1 + fi diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 0000000..0778a89 --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,25 @@ +name: unit-test + +on: + # Triggers the workflow on push or pull request events but only for the master branch + push: + branches: [ master ] + pull_request: + branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + - name: Copy kubeconfig + run: | + mkdir ~/.kube + cp .github/workflows/assets/placeholder-kubeconfig.yaml ~/.kube/config + # Run the tests + - name: Run make test + run: make test