diff --git a/.gitignore b/.gitignore index 54f741e..895d3e1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk + +# Generated by Kuttl +kubeconfig +kind-logs-* diff --git a/justfile b/justfile index 436e746..d821875 100644 --- a/justfile +++ b/justfile @@ -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 diff --git a/tests/e2e/deploy-test/00-apply-agent.yaml b/tests/e2e/deploy-test/00-apply-agent.yaml new file mode 100644 index 0000000..1d3635a --- /dev/null +++ b/tests/e2e/deploy-test/00-apply-agent.yaml @@ -0,0 +1,6 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +apply: +- agent.yaml +assert: +- agent-assert.yaml diff --git a/tests/e2e/deploy-test/01-deploy-test-pods.yaml b/tests/e2e/deploy-test/01-deploy-test-pods.yaml new file mode 100644 index 0000000..8ee9971 --- /dev/null +++ b/tests/e2e/deploy-test/01-deploy-test-pods.yaml @@ -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- diff --git a/tests/e2e/deploy-test/02-communicate-between-pods.yaml b/tests/e2e/deploy-test/02-communicate-between-pods.yaml new file mode 100644 index 0000000..e5dca2f --- /dev/null +++ b/tests/e2e/deploy-test/02-communicate-between-pods.yaml @@ -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 diff --git a/tests/e2e/deploy-test/agent-assert.yaml b/tests/e2e/deploy-test/agent-assert.yaml new file mode 100644 index 0000000..e4e2edd --- /dev/null +++ b/tests/e2e/deploy-test/agent-assert.yaml @@ -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 diff --git a/tests/e2e/deploy-test/00-install.yaml b/tests/e2e/deploy-test/agent.yaml similarity index 100% rename from tests/e2e/deploy-test/00-install.yaml rename to tests/e2e/deploy-test/agent.yaml diff --git a/tests/e2e/deploy-test/test-pods-assert.yaml b/tests/e2e/deploy-test/test-pods-assert.yaml new file mode 100644 index 0000000..1ad1a0a --- /dev/null +++ b/tests/e2e/deploy-test/test-pods-assert.yaml @@ -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 diff --git a/tests/e2e/deploy-test/01-test-pods.yaml b/tests/e2e/deploy-test/test-pods.yaml similarity index 75% rename from tests/e2e/deploy-test/01-test-pods.yaml rename to tests/e2e/deploy-test/test-pods.yaml index b46cb17..49781da 100644 --- a/tests/e2e/deploy-test/01-test-pods.yaml +++ b/tests/e2e/deploy-test/test-pods.yaml @@ -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 --- @@ -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 \ No newline at end of file + kubernetes.io/hostname: kind-worker diff --git a/tests/kuttl-test.yaml b/tests/kuttl-test.yaml new file mode 100644 index 0000000..1f6e91f --- /dev/null +++ b/tests/kuttl-test.yaml @@ -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