Skip to content

Commit

Permalink
Merge pull request #38 from arangodb/prepare-cluster-for-test
Browse files Browse the repository at this point in the history
Prepare test cluster
  • Loading branch information
ewoutp authored Mar 9, 2018
2 parents afa315a + c3156e2 commit bb71fd6
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 6 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ endif
kubectl create namespace $(TESTNAMESPACE)
$(ROOTDIR)/examples/setup-rbac.sh --namespace=$(TESTNAMESPACE)
$(ROOTDIR)/scripts/kube_create_operator.sh $(TESTNAMESPACE) $(OPERATORIMAGE)
$(ROOTDIR)/scripts/kube_create_storage.sh $(TESTNAMESPACE)
kubectl --namespace $(TESTNAMESPACE) \
run arangodb-operator-test -i --rm --quiet --restart=Never \
--image=$(TESTIMAGE) \
Expand Down
16 changes: 16 additions & 0 deletions docs/design/test_clusters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Test clusters

The ArangoDB operator is tested on various types of kubernetes clusters.

To prepare a cluster for running the ArangoDB operator tests,
do the following:

- Create a `kubectl` config file for accessing the cluster.
- Use that config file.
- Run `./scripts/kube_configure_test_cluster.sh`. This creates a `ConfigMap`
named `arango-operator-test` in the `kube-system` namespace containing the
following environment variables.

```bash
REQUIRE_LOCAL_STORAGE=1
```
28 changes: 28 additions & 0 deletions scripts/kube_configure_test_cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Sets the configuration of the cluster in a ConfigMap in kube-system.

cluster=$(kubectl config current-context)
echo "Configuring cluster $cluster"

read -p "Does the cluster require local storage (Y/n)? " answer
case ${answer:0:1} in
n|N )
REQUIRE_LOCAL_STORAGE=
;;
* )
REQUIRE_LOCAL_STORAGE=1
;;
esac

mapname="arango-operator-test"
configfile=$(mktemp)
cat <<EOF > $configfile
REQUIRE_LOCAL_STORAGE=${REQUIRE_LOCAL_STORAGE}
EOF
kubectl delete configmap $mapname -n kube-system --ignore-not-found
kubectl create configmap $mapname -n kube-system --from-env-file=$configfile || exit 1

echo Stored configuration:
cat $configfile
rm $configfile
26 changes: 24 additions & 2 deletions scripts/kube_create_operator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [ ! -z $USESHA256 ]; then
IMAGE=$(docker inspect --format='{{index .RepoDigests 0}}' ${IMAGE})
fi

kubectl --namespace=$NS create -f - << EOYAML
config=$(cat << EOYAML
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
Expand All @@ -46,5 +46,27 @@ spec:
fieldPath: metadata.name
EOYAML
)
echo "$config" | kubectl --namespace=$NS create -f - || exit 1

exit $?
# Wait until custom resources are available

while :; do
response=$(kubectl get crd arangodeployments.database.arangodb.com --template="non-empty" --ignore-not-found)
if [ ! -z $response ]; then
break
fi
sleep 1
echo -n .
done

while :; do
response=$(kubectl get crd arangolocalstorages.storage.arangodb.com --template="non-empty" --ignore-not-found)
if [ ! -z $response ]; then
break
fi
sleep 1
echo -n .
done

echo "Arango Operator deployed"
22 changes: 22 additions & 0 deletions scripts/kube_create_storage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Create the local storage in the cluster if the cluster needs it.

NS=$1

if [ -z $NS ]; then
echo "Specify a namespace argument"
exit 1
fi

# Fetch cluster config
mapname="arango-operator-test"
eval $(kubectl get configmap $mapname -n kube-system --ignore-not-found --template='{{ range $key, $value := .data }}export {{$key}}={{$value}}
{{ end }}')

if [ "${REQUIRE_LOCAL_STORAGE}" = "1" ]; then
echo "Preparing local storage"
kubectl apply -n $NS -f examples/arango-local-storage.yaml || exit 1
else
echo "No local storage needed for this cluster"
fi
12 changes: 8 additions & 4 deletions scripts/kube_delete_namespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ if [ -z $NS ]; then
fi

kubectl delete namespace $NS --now --ignore-not-found
response=$(kubectl get namespace $NS --template="non-empty" --ignore-not-found)
while [ ! -z $response ]; do
sleep 1
response=$(kubectl get namespace $NS --template="non-empty" --ignore-not-found)

# Wait until its really gone
while :; do
response=$(kubectl get namespace $NS --template="non-empty" --ignore-not-found)
if [ -z $response ]; then
break
fi
sleep 0.5
done

0 comments on commit bb71fd6

Please sign in to comment.