Skip to content

Commit

Permalink
Merge pull request #8 from 21kyu/test/setup-e2e
Browse files Browse the repository at this point in the history
test(e2e): setup e2e tests using kuttl
  • Loading branch information
wqld authored Feb 5, 2024
2 parents 3226fe0 + 4f729a0 commit a6c97c5
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# Generated by Kuttl
kubeconfig
kind-logs-*
13 changes: 9 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
setup-kind-cluster:
kind create cluster --config tests/e2e/kind-config.yaml
build-image:
cargo xtask build-ebpf
cargo build --target $(uname -m)-unknown-linux-musl
docker build --build-arg ARCH=$(uname -m) -t sinabro:test .

setup-kind-cluster: build-image
kind create cluster --config tests/e2e/kind-config.yaml
kind load docker-image sinabro:test

clean-kind-cluster:
kind delete cluster

deploy-agent: setup-kind-cluster
kubectl apply -f tests/e2e/deploy-test/00-install.yaml
kubectl apply -f tests/e2e/deploy-test/agent.yaml

deploy-test-pods: deploy-agent
kubectl taint nodes kind-control-plane node-role.kubernetes.io/control-plane-
kubectl apply -f tests/e2e/deploy-test/01-test-pods.yaml
kubectl apply -f tests/e2e/deploy-test/test-pods.yaml

e2e-test: build-image
kubectl kuttl test --config ./tests/kuttl-test.yaml
6 changes: 6 additions & 0 deletions tests/e2e/deploy-test/00-apply-agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- agent.yaml
assert:
- agent-assert.yaml
8 changes: 8 additions & 0 deletions tests/e2e/deploy-test/01-deploy-test-pods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- test-pods.yaml
assert:
- test-pods-assert.yaml
commands:
- command: kubectl taint nodes kind-control-plane node-role.kubernetes.io/control-plane-
9 changes: 9 additions & 0 deletions tests/e2e/deploy-test/02-communicate-between-pods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: POD_IP=$(kubectl get pod nginx-master -n $NAMESPACE -o jsonpath='{.status.podIP}') && kubectl exec -n $NAMESPACE curl-worker -c curl -- curl $POD_IP
- script: POD_IP=$(kubectl get pod nginx-worker -n $NAMESPACE -o jsonpath='{.status.podIP}') && kubectl exec -n $NAMESPACE curl-worker -c curl -- curl $POD_IP
- script: POD_IP=$(kubectl get pod nginx-master -n $NAMESPACE -o jsonpath='{.status.podIP}') && kubectl exec -n $NAMESPACE curl-master -c curl -- curl $POD_IP
- script: POD_IP=$(kubectl get pod nginx-worker -n $NAMESPACE -o jsonpath='{.status.podIP}') && kubectl exec -n $NAMESPACE curl-master -c curl -- curl $POD_IP
- command: kubectl exec -n $NAMESPACE curl-worker -c curl -- curl google.com
- command: kubectl exec -n $NAMESPACE curl-master -c curl -- curl google.com
12 changes: 12 additions & 0 deletions tests/e2e/deploy-test/agent-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: agent
namespace: kube-system
status:
currentNumberScheduled: 2
desiredNumberScheduled: 2
numberAvailable: 2
numberMisscheduled: 0
numberReady: 2
updatedNumberScheduled: 2
File renamed without changes.
27 changes: 27 additions & 0 deletions tests/e2e/deploy-test/test-pods-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: Pod
metadata:
name: curl-worker
status:
phase: Running
---
apiVersion: v1
kind: Pod
metadata:
name: nginx-worker
status:
phase: Running
---
apiVersion: v1
kind: Pod
metadata:
name: curl-master
status:
phase: Running
---
apiVersion: v1
kind: Pod
metadata:
name: nginx-master
status:
phase: Running
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ spec:
apiVersion: v1
kind: Pod
metadata:
name: bash-master
name: curl-master
spec:
containers:
- name: ubuntu
image: nicolaka/netshoot
- name: curl
image: curlimages/curl
command:
- "sh"
- "-c"
- "sleep 10000"
- "sleep 1000"
nodeSelector:
kubernetes.io/hostname: kind-control-plane
---
Expand All @@ -42,14 +42,14 @@ spec:
apiVersion: v1
kind: Pod
metadata:
name: bash-worker
name: curl-worker
spec:
containers:
- name: ubuntu
image: nicolaka/netshoot
- name: curl
image: curlimages/curl
command:
- "sh"
- "-c"
- "sleep 10000"
- "sleep 1000"
nodeSelector:
kubernetes.io/hostname: kind-worker
kubernetes.io/hostname: kind-worker
12 changes: 12 additions & 0 deletions tests/kuttl-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kuttl.dev/v1beta1
kind: TestSuite
startKIND: true
skipDelete: true
kindConfig: ./tests/e2e/kind-config.yaml
kindNodeCache: true
kindContainers:
- sinabro:test
testDirs:
- ./tests/e2e/
suppress:
- events

0 comments on commit a6c97c5

Please sign in to comment.