Skip to content

Commit

Permalink
Add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
CatherineF-dev committed Jun 5, 2024
1 parent 13b681f commit 5ddfbea
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/daemonsetsharding/deployment-no-node-pods.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
containers:
- args:
- --resources=pods
- --node=""
- --node=
image: registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.12.0
livenessProbe:
httpGet:
Expand Down
31 changes: 22 additions & 9 deletions tests/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,34 @@ function test_daemonset() {

kubectl get deployment -n kube-system
kubectl create -f ./examples/daemonsetsharding
kubectl apply -f ./tests/e2e/testdata/pods.yaml
kubectl get deployment -n default
ls ./examples/daemonsetsharding
kube_state_metrics_up
curl -s "http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics-shard:http-metrics/proxy/metrics" >${KUBE_STATE_METRICS_LOG_DIR}/pod-metrics
curl -s "http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics:http-metrics/proxy/metrics" >${KUBE_STATE_METRICS_LOG_DIR}/nonpod-metrics
m1="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/pod-metrics | grep "# TYPE kube_pod_info" || true)"
m2="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/nonpod-metrics | grep "# TYPE kube_pod_info" || true)"
if [[ -z "${m1}" ]]; then
echo "can't found metric kube_pod_info from pod metrics service"
curl -s "http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics-shard:http-metrics/proxy/metrics" >${KUBE_STATE_METRICS_LOG_DIR}/daemonset-scraped-metrics
curl -s "http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics:http-metrics/proxy/metrics" >${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-metrics
runningpod1="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/daemonset-scraped-metrics | grep "# TYPE kube_pod_info" | grep "runningpod1" | wc -l)"
pendingpod2="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-metrics | grep "# TYPE kube_pod_info" | grep "pendingpod2" | wc -l)"
expected_num_pod=1
if [ "${runningpod1}" == "${expected_num_pod}" ]; then
echo "runningpod1 doesn't show up in kube_pod_info metric only once"
exit 1
fi
if [[ -n "${m2}" ]]; then
echo "shouldn't find metric kube_pod_info from non-pod metrics service"
if [ "${pendingpod2}" -ne "${expected_num_pod}" ]; then
echo "pendingpod2 doesn't show up in kube_pod_info metric only once"
exit 1
fi

m1="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/daemonset-scraped-metrics | grep "# TYPE kube_node_info" | wc -l)"
m2="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-metrics | grep "# TYPE kube_node_info" | wc -l)"
if [[ -z "${m2}" ]]; then
echo "can't found metric kube_node_info from deployment metrics service"
exit 1
fi
if [[ -n "${m1}" ]]; then
echo "shouldn't find metric kube_pod_info from daemonset metrics service"
exit 1
fi
kubectl delete -f ./tests/e2e/testdata/pods.yaml
kubectl delete -f ./examples/daemonsetsharding
sleep 20
}
Expand Down
85 changes: 85 additions & 0 deletions tests/e2e/testdata/pods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: pod1
name: pod1
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: pod1
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: pod1
spec:
nodeSelector:
debug-node: "non"
containers:
- command:
- /agnhost
- netexec
- --http-port=8080
image: registry.k8s.io/e2e-test-images/agnhost:2.39
imagePullPolicy: IfNotPresent
name: agnhost
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: pod2
name: pod2
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: pod2
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: pod2
spec:
containers:
- command:
- /agnhost
- netexec
- --http-port=8080
image: registry.k8s.io/e2e-test-images/agnhost:2.39
imagePullPolicy: IfNotPresent
name: agnhost
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30

0 comments on commit 5ddfbea

Please sign in to comment.