From 347c8e9a128014ed1cbcf34d85ba2a34103cf38c Mon Sep 17 00:00:00 2001
From: David Hoese <david.hoese@ssec.wisc.edu>
Date: Sun, 20 Dec 2020 09:31:22 -0600
Subject: [PATCH] Add really basic attempt at enabling postgis extension on
 postgres db

---
 ci_tests/basic_postgres/values-postgis.yaml |  2 ++
 helpers/deploy_postgis.sh                   | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/ci_tests/basic_postgres/values-postgis.yaml b/ci_tests/basic_postgres/values-postgis.yaml
index e69de29..f3e2348 100644
--- a/ci_tests/basic_postgres/values-postgis.yaml
+++ b/ci_tests/basic_postgres/values-postgis.yaml
@@ -0,0 +1,2 @@
+persistence:
+  enabled: false
\ No newline at end of file
diff --git a/helpers/deploy_postgis.sh b/helpers/deploy_postgis.sh
index d97a047..e47a5bf 100755
--- a/helpers/deploy_postgis.sh
+++ b/helpers/deploy_postgis.sh
@@ -17,6 +17,11 @@ else
     release_prefix="$2"
 fi
 
+get_pod_name() {
+    release_name="$1"
+    kubectl -n $ns get pods --selector=app.kubernetes.io/instance=${release_name} -o name
+}
+
 
 ns=$(./helpers/get_namespace.sh)
 # get password from any previous installation
@@ -41,4 +46,18 @@ echo "Start waiting for postgres: $(date +%Y%m%dT%H%M%S)"
 kubectl wait -n $ns --selector=app.kubernetes.io/instance=${release_name} --timeout 120s --for=condition=Ready pod
 status=$?
 echo "Done waiting for postgis: $(date +%Y%m%dT%H%M%S) : $status"
+
+if [[ ${status} -ne 0 ]]; then
+    exit $status
+fi
+
+# This is the first time we've installed this
+if [[ "$sec_info" == "" ]]; then
+    # Enable PostGIS extension
+    POSTGRES_PASSWORD=$(kubectl get secret -n $ns ${auth_sec} -o jsonpath-"{.data.postgresql-password}" | base64 --decode)
+    pod_name=$(get_pod_name ${release_name})
+    kubectl exec -n $ns ${pod_name} -- bash -c "PGPASSWORD=$POSTGRES_PASSWORD; psql -U postgres -d postgres -c 'CREATE EXTENSION postgis;'"
+    status=$?
+fi
+
 exit $status
-- 
GitLab