Adding helm test hooks for mongodb-replicaset (#609)

* Adding helm test hooks for mongodb-replicaset

* Fix truncation 24->63, whitespace and merge conflicts

* Removed wrapper and cleaned up

* Use image from template

* Remove dockerfile and custom image

* Moved to new locatio
This commit is contained in:
Anirudh Ramanathan
2017-05-03 20:11:34 -07:00
committed by Sean Knox
parent 70ef71ce61
commit 73f98f56d2
2 changed files with 122 additions and 0 deletions
@@ -0,0 +1,37 @@
apiVersion: v1
kind: Pod
metadata:
name: {{ template "fullname" . }}-test
annotations:
"helm.sh/hook": test-success
"pod.beta.kubernetes.io/init-containers": '[
{
"name": "test-framework",
"image": "dduportal/bats:0.4.0",
"command": ["bash", "-c", "
set -ex\n
# copy bats to tools dir\n
cp -R /usr/local/libexec/ /tools/bats/\n
"],
"volumeMounts": [
{"name": "tools", "mountPath": "/tools"}
]
}
]'
spec:
containers:
- name: mongo
image: "{{ .Values.image.name }}:{{ .Values.image.tag }}"
command: ["/tools/bats/bats", "-t", "/tests/mongo-up-test.sh"]
volumeMounts:
- name: tools
mountPath: /tools
- name: tests
mountPath: /tests
volumes:
- name: tools
emptyDir: {}
- name: tests
configMap:
name: {{ template "fullname" . }}-tests
restartPolicy: Never
@@ -0,0 +1,85 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "fullname" . }}-tests
labels:
app: {{ template "fullname" . }}-tests
data:
mongo-up-test.sh: |
pod_name() {
echo {{ template "fullname" . }}-$1.{{ template "fullname" . }}.default.svc.cluster.local
}
master_pod() {
for i in {0..2}
do
response=$(mongo \
--host=$(pod_name $i) \
--eval="rs.isMaster().ismaster")
if [[ $response =~ "true" ]]; then
echo $(pod_name $i)
break
fi
done
}
setup() {
ready=0
until [[ $ready -eq 3 ]];
do
echo "Waiting for application to become ready" >&2
sleep 1
ready=0
for i in {0..2}
do
response=$(mongo \
--host=$(pod_name $i) \
--eval="rs.status()") || true
if [[ $response =~ .*ok.* ]]; then
ready=$((ready+1))
fi
done
done
}
@test "Testing mongodb client is accessible" {
mongo -h
[ "$?" -eq 0 ]
}
@test "Connect mongodb client to mongodb pods" {
for i in {0..2}
do
response=$(mongo \
--host=$(pod_name $i) \
--eval="rs.status()")
if [[ ! $response =~ .*ok.* ]]; then
exit 1
fi
done
}
@test "Write key to master" {
response=$(mongo \
--host=$(master_pod) \
--eval="db.test.insert({\"abc\": \"def\"}).nInserted")
if [[ ! $response =~ "1" ]]; then
exit 1
fi
}
@test "Read key from slaves" {
# wait for slaves to catch up
sleep 10
for i in {0..2}
do
response=$(mongo \
--host=$(pod_name $i) \
--eval="rs.slaveOk(); db.test.find({\"abc\":\"def\"})")
if [[ ! $response =~ .*def.* ]]; then
exit 1
fi
done
}