diff --git a/setup.sh b/setup.sh index fc2ba0f6..1b8a496f 100755 --- a/setup.sh +++ b/setup.sh @@ -1,13 +1,13 @@ #!/bin/sh -set -euo pipefail +set -eu NATS_K8S_VERSION=${DEFAULT_NATS_K8S_VERSION:=https://github.com/nats-io/k8s/blob/9fd463279f8ccafaa50d12977bad583520551852} -NATS_BOOTSTRAP_YML=${DEFAULT_NATS_BOOTSTRAP_YML:=$NATS_K8S_RELEASE/setup/bootstrap-policy.yml} +NATS_BOOTSTRAP_YML=${DEFAULT_NATS_BOOTSTRAP_YML:=$NATS_K8S_VERSION/setup/bootstrap-policy.yml} NATS_SETUP_IMAGE=${DEFAULT_NATS_SETUP_IMAGE:=synadia/nats-setup:0.1.2} # Apply policy required to be able to create the resources. -kubectl apply -f $NATS_BOOTSTRAP_YML +kubectl apply -f "$NATS_BOOTSTRAP_YML" # Run nats-setup container containing the latest set of manifests. kubectl run nats-setup --generator=run-pod/v1 --image-pull-policy=Always --serviceaccount=nats-setup --image=$NATS_SETUP_IMAGE --restart=Never @@ -22,7 +22,7 @@ kubectl exec nats-setup -- nats-setup.sh "$@" kubectl cp nats-setup:/nsc nsc # Remove the required policy for setup purposes. -kubectl delete -f $NATS_BOOTSTRAP_YML +kubectl delete -f "$NATS_BOOTSTRAP_YML" # Remove the setup pod. kubectl delete pod nats-setup --grace-period=0 --force diff --git a/setup/destroy.sh b/setup/destroy.sh index e75596bf..0d4bf9ec 100755 --- a/setup/destroy.sh +++ b/setup/destroy.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh echo "Cleaning up..." @@ -10,9 +10,9 @@ kubectl delete deployment/nats-surveyor kubectl delete deployment/nats-surveyor-grafana kubectl delete deployment/prometheus-operator kubectl delete pod nats-box -kubectl delete secrets nats-sys-creds -kubectl delete secrets nats-test-creds -kubectl delete secrets stan-creds +kubectl delete secrets nats-sys-creds +kubectl delete secrets nats-test-creds +kubectl delete secrets stan-creds kubectl delete secrets prometheus-nats-prometheus kubectl delete secrets prometheus-nats-surveyor kubectl delete prometheuses nats-prometheus diff --git a/setup/nats-setup.sh b/setup/nats-setup.sh index 593ad20c..7f16f717 100755 --- a/setup/nats-setup.sh +++ b/setup/nats-setup.sh @@ -48,9 +48,9 @@ kctl() { until [ $i -ge 10 ] do kubectl "$@" && break - i=$[$i+1] + i=$((i+1)) - if [ $i -ge 2 ]; then + if [ "$i" -ge 2 ]; then echo -ne "Retrying in 3 seconds ($i attempts so far)" else echo -ne "Retrying in 3 seconds" @@ -62,10 +62,13 @@ kctl() { echo -ne '.' sleep 1 echo -ne '.' - echo + echo done - if [ $i -ge 10 ]; then + # Try one last time. + kubectl "$@" && break + + if [ "$i" -ge 10 ]; then RED='\033[0;31m' NC='\033[0m' echo -ne "${RED}Could not finish setting up NATS due to errors in the cluster${NC}" @@ -75,9 +78,9 @@ kctl() { } create_creds() { - mkdir -p $NKEYS_PATH - mkdir -p $NSC_HOME - mkdir -p $NATS_CONFIG_HOME + mkdir -p "$NKEYS_PATH" + mkdir -p "$NSC_HOME" + mkdir -p "$NATS_CONFIG_HOME" nsc add operator --name KO @@ -95,20 +98,20 @@ create_creds() { # Generate accounts resolver config using the preload config ( - cd $NATS_CONFIG_HOME + cd "$NATS_CONFIG_HOME" nsc generate config --mem-resolver --sys-account SYS > resolver.conf ) if [ $SKIP_NSC_DIR_CHOWN != "true" ]; then - chown -R 1000:1000 $NSC_DIR + chown -R 1000:1000 "$NSC_DIR" fi } create_secrets() { - kctl create secret generic nats-sys-creds --from-file $NSC_DIR/nkeys/creds/KO/SYS/sys.creds - kctl create secret generic nats-test-creds --from-file $NSC_DIR/nkeys/creds/KO/TEST/test.creds - kctl create secret generic stan-creds --from-file $NSC_DIR/nkeys/creds/KO/STAN/stan.creds - kctl create configmap nats-accounts --from-file $NSC_DIR/config/resolver.conf + kctl create secret generic nats-sys-creds --from-file "$NSC_DIR/nkeys/creds/KO/SYS/sys.creds" + kctl create secret generic nats-test-creds --from-file "$NSC_DIR/nkeys/creds/KO/TEST/test.creds" + kctl create secret generic stan-creds --from-file "$NSC_DIR/nkeys/creds/KO/STAN/stan.creds" + kctl create configmap nats-accounts --from-file "$NSC_DIR/config/resolver.conf" } install_prometheus() {