Skip to content

Commit

Permalink
Check if database is empty before considering it
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Sep 9, 2020
1 parent 43c0dd9 commit 03b90e7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions engine/add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ if [[ "$?" == "1" ]] ; then
do
isDatabaseFree=$(kubectl get configmap redis-database-assignment-operator-in-use-dbs-list -o json | jq -r '.data.dbs' | jq ".[\"${uri_host_port}\"].db${i}" | grep free | wc -l)
if [[ "$isDatabaseFree" == "1" ]] ; then
echo "Database ${i} is available"
kubectl create secret generic "${secret}" -n "${namespace}" --from-literal=DATABASE="${i}" --from-literal=READ="${read_dsn}${i}" --from-literal=WRITE="${write_dsn}${i}"
kubectl create configmap redis-database-assignment-operator-in-use-dbs-list --from-literal=dbs=$(kubectl get configmap redis-database-assignment-operator-in-use-dbs-list -o json | jq -r '.data.dbs' | jq -r ". * {\"${uri_host_port}\": {\"db${i}\": \"${namespace}/${secret}\"}}" | jq -c) --dry-run -o yaml | kubectl apply -f -
echo "Database ${i} has now been claimed"
break
isDatabaseEmpty=$(redis-cli -u "${write}" INFO keyspace | grep -v Keyspace | grep "db${i}" | wc -l)
if [[ "$isDatabaseEmpty" == "0" ]] ; then
echo "Database ${i} is available"
kubectl create secret generic "${secret}" -n "${namespace}" --from-literal=DATABASE="${i}" --from-literal=READ="${read_dsn}${i}" --from-literal=WRITE="${write_dsn}${i}"
kubectl create configmap redis-database-assignment-operator-in-use-dbs-list --from-literal=dbs=$(kubectl get configmap redis-database-assignment-operator-in-use-dbs-list -o json | jq -r '.data.dbs' | jq -r ". * {\"${uri_host_port}\": {\"db${i}\": \"${namespace}/${secret}\"}}" | jq -c) --dry-run -o yaml | kubectl apply -f -
echo "Database ${i} has now been claimed"
break
fi
fi
done
else
Expand Down

0 comments on commit 03b90e7

Please sign in to comment.