Skip to content

Commit

Permalink
A few updates to bootstrap script.
Browse files Browse the repository at this point in the history
* Use linux REALPATH(1) to reduce sub-shells in $ROOT assignment
* Use case/switch statements instead of repeated if/elif on $MODE
* Break ARGO_CD_URL into multi-lines to avoid long line side-scrolling
* Remove kustomize dependency, it's now part of `kubectl apply -k`

Signed-off-by: Jon Disnard <[email protected]>
  • Loading branch information
parasense committed Feb 28, 2022
1 parent 964a4a2 commit 628f4d4
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions hack/bootstrap-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

MODE=$1

ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/..
ROOT=$( realpath "${BASH_SOURCE[0]%/*}/.." )

if [ "$(oc auth can-i '*' '*' --all-namespaces)" != "yes" ]; then
if [[ "$(oc auth can-i '*' '*' --all-namespaces)" != "yes" ]]; then
echo
echo "[ERROR] User '$(oc whoami)' does not have the required 'cluster-admin' role." 1>&2
echo "Log into the cluster with a user with the required privileges (e.g. kubeadmin) and retry."
Expand All @@ -17,17 +17,15 @@ kubectl apply -f $ROOT/openshift-gitops/subscription-openshift-gitops.yaml

echo
echo -n "Waiting for default project (and namespace) to exist: "
while : ; do
kubectl get appproject/default -n openshift-gitops >/dev/null 2>&1 && break
while ! kubectl get appproject/default -n openshift-gitops &> /dev/null ; do
echo -n .
sleep 1
done
echo "OK"

echo
echo -n "Waiting for OpenShift GitOps Route: "
while : ; do
kubectl get route/openshift-gitops-server -n openshift-gitops >/dev/null 2>&1 && break
while ! kubectl get route/openshift-gitops-server -n openshift-gitops &> /dev/null ; do
echo -n .
sleep 1
done
Expand All @@ -45,21 +43,26 @@ kubectl patch argocd/openshift-gitops -n openshift-gitops -p '{"spec":{"rbac":{"

echo
echo "Add Role/RoleBindings for OpenShift GitOps:"
kustomize build $ROOT/openshift-gitops/cluster-rbac | kubectl apply -f -
kubectl apply --kustomize $ROOT/openshift-gitops/cluster-rbac

echo
if [ "$MODE" == "" ] || [ "$MODE" == "upstream" ]; then
echo "Setting Cluster Mode: Upstream"
kubectl apply -f $ROOT/argo-cd-apps/app-of-apps/all-applications-staging.yaml
elif [ "$MODE" == "development" ]; then
echo "Setting Cluster Mode: Development"
$ROOT/hack/development-mode.sh
elif [ "$MODE" == "preview" ]; then
echo "Setting Cluster Mode: Preview"
$ROOT/hack/preview.sh
fi
echo "Setting Cluster Mode: ${MODE:-Upstream}"
case $MODE in
""|"upstream")
kubectl apply -f $ROOT/argo-cd-apps/app-of-apps/all-applications-staging.yaml ;;
"development")
$ROOT/hack/development-mode.sh ;;
"preview")
$ROOT/hack/preview.sh ;;
esac

ARGO_CD_URL="https://$(kubectl get route/openshift-gitops-server -n openshift-gitops -o template --template={{.spec.host}})"
printf -v ARGO_CD_URL "https://%s" \
$(
kubectl get route/openshift-gitops-server \
-n openshift-gitops \
-o template \
--template={{.spec.host}}
)

echo
echo "========================================================================="
Expand Down

0 comments on commit 628f4d4

Please sign in to comment.