21832: Skips installing local Postgresql when using external service.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Tue, 11 Jun 2024 19:52:23 +0000 (16:52 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Thu, 13 Jun 2024 18:14:42 +0000 (15:14 -0300)
Also, makes sure that the trigram extension is enabled.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

tools/salt-install/config_examples/multi_host/aws/pillars/postgresql_external.sls [new file with mode: 0644]
tools/salt-install/config_examples/multi_host/aws/states/postgresql_external.sls [new file with mode: 0644]
tools/salt-install/installer.sh
tools/salt-install/provision.sh

diff --git a/tools/salt-install/config_examples/multi_host/aws/pillars/postgresql_external.sls b/tools/salt-install/config_examples/multi_host/aws/pillars/postgresql_external.sls
new file mode 100644 (file)
index 0000000..2303f17
--- /dev/null
@@ -0,0 +1,11 @@
+---
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+postgresql_external_service:
+  db_host: "__DATABASE_EXTERNAL_SERVICE_HOST_OR_IP__"
+  db_port: 5432
+  db_name: "__DATABASE_NAME__"
+  db_user: "__DATABASE_USER__"
+  db_password: "__DATABASE_PASSWORD__"
diff --git a/tools/salt-install/config_examples/multi_host/aws/states/postgresql_external.sls b/tools/salt-install/config_examples/multi_host/aws/states/postgresql_external.sls
new file mode 100644 (file)
index 0000000..aaf5b6c
--- /dev/null
@@ -0,0 +1,19 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+{%- set pg_svc = pillar.get('postgresql_external_service', {}) %}
+
+{%- if pg_svc %}
+__CLUSTER___external_trgm_extension:
+  postgres_extension.present:
+    - name: pg_trgm
+    - if_not_exists: true
+    - schema: public
+    - db_host: {{ pg_svc.db_host }}
+    - db_port: 5432
+    - db_user: {{ pg_svc.db_user }}
+    - db_password: {{ pg_svc.db_password }}
+    - require:
+      - pkg: postgresql-client-libs
+{%- endif %}
\ No newline at end of file
index 36e87cca91f1e774cc20193409815cc58f5f4c9a..68ec79f816d5a2a7f67fdc85bdda83969c01d558 100755 (executable)
@@ -270,7 +270,11 @@ terraform)
   (cd terraform/vpc && terraform apply -auto-approve) 2>&1 | tee -a $logfile
   (cd terraform/data-storage && terraform apply -auto-approve) 2>&1 | tee -a $logfile
   (cd terraform/services && terraform apply -auto-approve) 2>&1 | grep -v letsencrypt_iam_secret_access_key | tee -a $logfile
-  (cd terraform/services && echo -n 'letsencrypt_iam_secret_access_key = ' && terraform output letsencrypt_iam_secret_access_key) 2>&1 | tee -a $logfile
+  (cd terraform/services && \
+    echo -n 'letsencrypt_iam_secret_access_key = ' && \
+    terraform output letsencrypt_iam_secret_access_key && \
+    echo -n 'database_password = ' && \
+    terraform output database_password) 2>&1 | tee -a $logfile
   ;;
 
 terraform-destroy)
index a57164276e28fd21a49b2fbc31801734b0117462..af48c367c2b0f9096047ad0731ae5ec655d454d4 100755 (executable)
@@ -742,6 +742,10 @@ else
   for R in ${ROLES:-}; do
     case "${R}" in
       "database")
+        # Skip if using an external service
+        if [[ "${DATABASE_EXTERNAL_SERVICE_HOST_OR_IP:-}" != "" ]]; then
+          continue
+        fi
         # States
         grep -q "\- postgres$" ${STATES_TOP} || echo "    - postgres" >> ${STATES_TOP}
         grep -q "extra.prometheus_pg_exporter" ${STATES_TOP} || echo "    - extra.prometheus_pg_exporter" >> ${STATES_TOP}
@@ -859,6 +863,9 @@ else
         fi
         echo "    - extra.passenger_rvm" >> ${STATES_TOP}
         grep -q "^    - postgres\\.client$" ${STATES_TOP} || echo "    - postgres.client" >> ${STATES_TOP}
+        if [[ "${DATABASE_EXTERNAL_SERVICE_HOST_OR_IP:-}" != "" ]]; then
+          grep -q "    - extra.postgresql_external" ${STATES_TOP} || echo "    - extra.postgresql_external" >> ${STATES_TOP}
+        fi
 
         ### If we don't install and run LE before arvados-api-server, it fails and breaks everything
         ### after it. So we add this here as we are, after all, sharing the host for api and controller
@@ -886,6 +893,10 @@ else
         grep -q "nginx_api_configuration" ${PILLARS_TOP} || echo "    - nginx_api_configuration" >> ${PILLARS_TOP}
         grep -q "nginx_controller_configuration" ${PILLARS_TOP} || echo "    - nginx_controller_configuration" >> ${PILLARS_TOP}
 
+        if [[ "${DATABASE_EXTERNAL_SERVICE_HOST_OR_IP:-}" != "" ]]; then
+          grep -q "    - postgresql_external" ${PILLARS_TOP} || echo "    - postgresql_external" >> ${PILLARS_TOP}
+        fi
+
         if [ "${ENABLE_BALANCER}" == "no" ]; then
           if [ "${SSL_MODE}" = "lets-encrypt" ]; then
             if [ "${USE_LETSENCRYPT_ROUTE53}" = "yes" ]; then