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 ba7577a commit fb33dbc
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 8 deletions.
37 changes: 29 additions & 8 deletions tests/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -x
set -e
set -o pipefail

Expand Down Expand Up @@ -102,19 +103,39 @@ function test_daemonset() {
kubectl create -f ./examples/daemonsetsharding
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"
kubectl apply -f ./tests/e2e/testdata/pods.yaml
sleep 10
kubectl get deployment -n default
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
curl -s "http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics-no-node-pods:http-metrics/proxy/metrics" >${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-no-node-metrics

cat ${KUBE_STATE_METRICS_LOG_DIR}/daemonset-scraped-metrics >> ${KUBE_STATE_METRICS_LOG_DIR}/all-pod-metrics
cat ${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-metrics >> ${KUBE_STATE_METRICS_LOG_DIR}/all-pod-metrics
cat ${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-no-node-metrics >> ${KUBE_STATE_METRICS_LOG_DIR}/all-pod-metrics
runningpod1="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/all-pod-metrics | grep "kube_pod_info" | grep "runningpod1" | wc -l)"
pendingpod2="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/all-pod-metrics | grep "kube_pod_info" | grep "pendingpod2" | wc -l)"
pendingpod2_in_deployment="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-no-node-metrics | grep "kube_pod_info" | grep "pendingpod2" | wc -l)"
expected_num_pod=1
if [ "${runningpod1}" != "${expected_num_pod}" ]; then
echo "metric kube_pod_info for runningpod1 doesn't show up only once, got ${runningpod1} times"
exit 1
fi
if [[ -n "${m2}" ]]; then
echo "shouldn't find metric kube_pod_info from non-pod metrics service"
if [ "${pendingpod2}" != "${expected_num_pod}" ]; then
echo "metric kube_pod_info for pendingpod2 doesn't show up only once, got ${runningpod1} times"
exit 1
fi
if [ "${pendingpod2_in_deployment}" != "${expected_num_pod}" ]; then
echo "pendingpod2 doesn't show up in kube_pod_info metric only once from service deployment-scraped-no-node-metrics"
exit 1
fi
m1="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/all-pod-metrics | grep "# TYPE kube_node_info" | wc -l)"
if ["${m1}" != "1" ]; then
echo "metric kube_node_info doesn't show up only once, got ${m1} times"
exit 1
fi

kubectl delete -f ./tests/e2e/testdata/pods.yaml
kubectl delete -f ./examples/daemonsetsharding
sleep 20
}
Expand Down
75 changes: 75 additions & 0 deletions tests/e2e/testdata/pods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: pendingpod2
name: pendingpod2
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: pendingpod2
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: pendingpod2
spec:
nodeSelector:
debug-node: "non"
containers:
- command:
- /agnhost
- netexec
- --http-port=8080q
image: registry.k8s.io/e2e-test-images/agnhost:2.39
imagePullPolicy: IfNotPresent
name: agnhost
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
terminationGracePeriodSeconds: 30
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: runningpod1
name: runningpod1
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: runningpod1
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: runningpod1
spec:
containers:
- command:
- /agnhost
- netexec
- --http-port=8080
image: registry.k8s.io/e2e-test-images/agnhost:2.39
imagePullPolicy: IfNotPresent
name: agnhost
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
terminationGracePeriodSeconds: 30

0 comments on commit fb33dbc

Please sign in to comment.