From 70c8fec705c6bbbfc577509fa9d929286562c888 Mon Sep 17 00:00:00 2001 From: Tullio Sebastiani Date: Thu, 10 Jul 2025 09:35:59 +0200 Subject: [PATCH] added pod-network-filter funtest (#863) * added pod-network-filter funtest Signed-off-by: Tullio Sebastiani * updated kind settings Signed-off-by: Tullio Sebastiani --------- Signed-off-by: Tullio Sebastiani --- .github/workflows/tests.yml | 2 + CI/templates/pod_network_filter.yaml | 29 ++++++++++++++ CI/tests/test_pod_network_filter.sh | 59 ++++++++++++++++++++++++++++ kind-config.yml | 2 + 4 files changed, 92 insertions(+) create mode 100644 CI/templates/pod_network_filter.yaml create mode 100755 CI/tests/test_pod_network_filter.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 756cf083..36f7a616 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -89,6 +89,7 @@ jobs: echo "test_cpu_hog" >> ./CI/tests/functional_tests echo "test_memory_hog" >> ./CI/tests/functional_tests echo "test_io_hog" >> ./CI/tests/functional_tests + echo "test_pod_network_filter" >> ./CI/tests/functional_tests # Push on main only steps + all other functional to collect coverage @@ -119,6 +120,7 @@ jobs: echo "test_cpu_hog" >> ./CI/tests/functional_tests echo "test_memory_hog" >> ./CI/tests/functional_tests echo "test_io_hog" >> ./CI/tests/functional_tests + echo "test_pod_network_filter" >> ./CI/tests/functional_tests # Final common steps - name: Run Functional tests diff --git a/CI/templates/pod_network_filter.yaml b/CI/templates/pod_network_filter.yaml new file mode 100644 index 00000000..928cdba3 --- /dev/null +++ b/CI/templates/pod_network_filter.yaml @@ -0,0 +1,29 @@ +apiVersion: v1 +kind: Pod +metadata: + name: pod-network-filter-test + labels: + app.kubernetes.io/name: pod-network-filter +spec: + containers: + - name: nginx + image: quay.io/krkn-chaos/krkn-funtests:pod-network-filter + ports: + - containerPort: 5000 + name: pod-network-prt + +--- +apiVersion: v1 +kind: Service +metadata: + name: pod-network-filter-service +spec: + selector: + app.kubernetes.io/name: pod-network-filter + type: NodePort + ports: + - name: pod-network-filter-svc + protocol: TCP + port: 80 + targetPort: pod-network-prt + nodePort: 30037 \ No newline at end of file diff --git a/CI/tests/test_pod_network_filter.sh b/CI/tests/test_pod_network_filter.sh new file mode 100755 index 00000000..6a380af0 --- /dev/null +++ b/CI/tests/test_pod_network_filter.sh @@ -0,0 +1,59 @@ +function functional_pod_network_filter { + export SERVICE_URL="http://localhost:8889" + export scenario_type="network_chaos_ng_scenarios" + export scenario_file="scenarios/kube/pod-network-filter.yml" + export post_config="" + envsubst < CI/config/common_test_config.yaml > CI/config/pod_network_filter.yaml + yq -i '.[0].test_duration=10' scenarios/kube/pod-network-filter.yml + yq -i '.[0].label_selector=""' scenarios/kube/pod-network-filter.yml + yq -i '.[0].ingress=false' scenarios/kube/pod-network-filter.yml + yq -i '.[0].egress=true' scenarios/kube/pod-network-filter.yml + yq -i '.[0].target="pod-network-filter-test"' scenarios/kube/pod-network-filter.yml + yq -i '.[0].protocols=["tcp"]' scenarios/kube/pod-network-filter.yml + yq -i '.[0].ports=[443]' scenarios/kube/pod-network-filter.yml + + + ## Test webservice deployment + kubectl apply -f ./CI/templates/pod_network_filter.yaml + COUNTER=0 + while true + do + curl $SERVICE_URL + EXITSTATUS=$? + if [ "$EXITSTATUS" -eq "0" ] + then + break + fi + sleep 1 + COUNTER=$((COUNTER+1)) + [ $COUNTER -eq "100" ] && echo "maximum number of retry reached, test failed" && exit 1 + done + + python3 -m coverage run -a run_kraken.py -c CI/config/pod_network_filter.yaml > /dev/null 2>&1 & + PID=$! + + # wait until the dns resolution starts failing and the service returns 400 + DNS_FAILURE_STATUS=0 + while true + do + OUT_STATUS_CODE=$(curl -X GET -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL) + if [ "$OUT_STATUS_CODE" -eq "404" ] + then + DNS_FAILURE_STATUS=404 + fi + + if [ "$DNS_FAILURE_STATUS" -eq "404" ] && [ "$OUT_STATUS_CODE" -eq "200" ] + then + echo "service restored" + break + fi + COUNTER=$((COUNTER+1)) + [ $COUNTER -eq "100" ] && echo "maximum number of retry reached, test failed" && exit 1 + sleep 2 + done + + wait $PID +} + +functional_pod_network_filter + diff --git a/kind-config.yml b/kind-config.yml index 2fb7e1ac..8363cc1d 100644 --- a/kind-config.yml +++ b/kind-config.yml @@ -5,6 +5,8 @@ nodes: extraPortMappings: - containerPort: 30036 hostPort: 8888 + - containerPort: 30037 + hostPort: 8889 - role: control-plane - role: control-plane - role: worker