Skip to content

Commit

Permalink
avoid sub-shell creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ObiWahn committed Feb 26, 2018
1 parent 08dfddd commit fa3a08a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 35 deletions.
59 changes: 27 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,10 @@ rules:
verbs:
- "*"
EOYAML
)
echo "$yaml" | kubectl apply -f -
}

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

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
4 changes: 1 addition & 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,3 @@ spec:
fieldPath: metadata.name
EOYAML
)
echo "$yaml" | kubectl --namespace=$NS create -f -

0 comments on commit fa3a08a

Please sign in to comment.