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 775af91 commit ae19254
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 9 deletions.
35 changes: 26 additions & 9 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,35 @@ 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
cat ${KUBE_STATE_METRICS_LOG_DIR}/daemonset-scraped-metrics
cat ${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-metrics
runningpod1="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/daemonset-scraped-metrics | grep "kube_pod_info" | grep "runningpod1" | wc -l)"
pendingpod2="$(cat ${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-metrics | grep "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_node_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 ae19254

Please sign in to comment.