Skip to content

Commit

Permalink
Merge pull request #6 from nats-io/tweaks
Browse files Browse the repository at this point in the history
Fix some lints and bugs
  • Loading branch information
wallyqs authored Nov 19, 2019
2 parents 6543f15 + 559c715 commit e005263
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
8 changes: 4 additions & 4 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions setup/destroy.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

echo "Cleaning up..."

Expand All @@ -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
Expand Down
29 changes: 16 additions & 13 deletions setup/nats-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}"
Expand All @@ -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

Expand All @@ -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() {
Expand Down

0 comments on commit e005263

Please sign in to comment.