Skip to content

Commit

Permalink
Merge pull request #171 from AkihiroSuda/coredns
Browse files Browse the repository at this point in the history
hack: add CoreDNS smoketest
  • Loading branch information
AkihiroSuda authored Jun 11, 2020
2 parents ffd1bda + 4ceea81 commit 9fdaaa4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hack/smoketest-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ if ! timeout 60 kubectl run --rm -i --image busybox --restart=Never hello echo h
journalctl -xe --no-pager
exit 1
fi

smoketest_dns
62 changes: 62 additions & 0 deletions hack/smoketest-common.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,65 @@ function INFO() {
function ERROR() {
echo >&2 -e "\e[101m\e[97m[ERROR]\e[49m\e[39m $@"
}

function smoketest_dns() {
INFO "Installing CoreDNS"
kubectl apply -f manifests/coredns.yaml

INFO "Creating StatefulSet \"dnstest\" and headless Service \"dnstest\""
kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: dnstest
labels:
run: dnstest
spec:
type: ClusterIP
clusterIP: None
ports:
- name: "http"
protocol: "TCP"
port: 80
targetPort: 80
selector:
run: dnstest
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: dnstest
spec:
serviceName: dnstest
selector:
matchLabels:
run: dnstest
replicas: 3
template:
metadata:
labels:
run: dnstest
spec:
containers:
- name: dnstest
image: nginx:alpine
ports:
- containerPort: 80
EOF
INFO "Waiting for 3 replicas to be ready"
if ! timeout 90 sh -exc "until [ \$(kubectl get pods --field-selector status.phase=Running -l run=dnstest -o name | wc -l) = "3" ]; do sleep 10; done"; then
ERROR "Pods are not ready."
set -x
kubectl get pods -o wide
kubectl get pods -o yaml
exit 1
fi

INFO "Connecting to dnstest-{0,1,2}.dnstest.default.svc.cluster.local"
kubectl run -it --rm --image=alpine --restart=Never dnstest-shell -- sh -exc 'for f in $(seq 0 2); do wget -O- http://dnstest-${f}.dnstest.default.svc.cluster.local; done'

INFO "Deleting Service \"dnstest\""
kubectl delete service dnstest
INFO "Deleting StatefulSet \"dnstest\""
kubectl delete statefulset dnstest
}
2 changes: 2 additions & 0 deletions hack/smoketest-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ for ip in $(kubectl get pods -o json -l app=$app | jq -r ".items[].status.podIP"
kubectl exec shell -- wget -O- $ip
done

smoketest_dns

INFO "PASS"
3 changes: 3 additions & 0 deletions hack/smoketest-docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
set -eu -o pipefail
source $(realpath $(dirname $0))/smoketest-common.inc.sh
if [[ $# -lt 3 ]]; then
echo "Usage: $0 NAME IMAGE ARGS"
exit 1
Expand Down Expand Up @@ -40,3 +41,5 @@ if ! timeout 60 time kubectl run --rm -i --image busybox --restart=Never hello e
docker logs $container
exit 1
fi

smoketest_dns

0 comments on commit 9fdaaa4

Please sign in to comment.