Skip to content

Commit

Permalink
Merge pull request #15 from arangodb/test-framework-shell
Browse files Browse the repository at this point in the history
avoid sub-shell creation
  • Loading branch information
ewoutp authored Feb 27, 2018
2 parents 9c4059d + 551669e commit 91c65dc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
69 changes: 37 additions & 32 deletions examples/setup-rbac.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/bash

ROLE_NAME="${ROLE_NAME:-arangodb-operator}"
ROLE_BINDING_NAME="${ROLE_BINDING_NAME:-arangodb-operator}"
NAMESPACE="${NAMESPACE:-default}"

function usage {
echo "$(basename "$0") - Create Kubernetes RBAC role and bindings for ArangoDB operator
echo "$(basename "$0") - Create Kubernetes RBAC role and bindings for ArangoDB operator
Usage: $(basename "$0") [options...]
Options:
--role-name=STRING Name of ClusterRole to create
Expand All @@ -13,12 +17,8 @@ Options:
" >&2
}

ROLE_NAME="${ROLE_NAME:-arangodb-operator}"
ROLE_BINDING_NAME="${ROLE_BINDING_NAME:-arangodb-operator}"
NAMESPACE="${NAMESPACE:-default}"

function setupRole {
yaml=$(cat << EOYAML
kubectl apply -f - << EOYAML
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
Expand Down Expand Up @@ -54,12 +54,15 @@ rules:
verbs:
- "*"
EOYAML
)
echo "$yaml" | kubectl apply -f -

local code=$?
if (code != 0); then
exit $code
fi
}

function setupRoleBinding {
yaml=$(cat << EOYAML
kubectl apply -f - << EOYAML
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
Expand All @@ -73,31 +76,33 @@ subjects:
name: default
namespace: ${NAMESPACE}
EOYAML
)
echo "$yaml" | kubectl apply -f -

local code=$?
if (code != 0); then
exit $code
fi
}

for i in "$@"
do
case $i in
--role-name=*)
ROLE_NAME="${i#*=}"
;;
--role-binding-name=*)
ROLE_BINDING_NAME="${i#*=}"
;;
--namespace=*)
NAMESPACE="${i#*=}"
;;
-h|--help)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
for i in "$@"; do
case $i in
--role-name=*)
ROLE_NAME="${i#*=}"
;;
--role-binding-name=*)
ROLE_BINDING_NAME="${i#*=}"
;;
--namespace=*)
NAMESPACE="${i#*=}"
;;
-h|--help)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done

setupRole
Expand Down
6 changes: 3 additions & 3 deletions scripts/kube_create_operator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ -z $IMAGE ]; then
exit 1
fi

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

exit $?

0 comments on commit 91c65dc

Please sign in to comment.