Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare test cluster #38

Merged
merged 7 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TRAP cleanup_function EXIT to clean up tempfile

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use read to store it in a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be a file (for --from-env-file to work)
Since it is temp, I'm not that worried about it being left behind a few times. In the normal case it is now removed.

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}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qefs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If eval does not return 0 your program ends here.

{{ end }}')

if [ "${REQUIRE_LOCAL_STORAGE}" = "1" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(( REQUIRE_LOCAL_STORAGE == 1))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You had that in another script before and it broke CI.
Does this require any specific bash version?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must be bash and not dash or some other shell:) Other than that it is standard for years.

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