This is an automated email from the ASF dual-hosted git repository.

sciabarracom pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openserverless-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new b849e6b  db fixes
b849e6b is described below

commit b849e6ba1bcd82d5282d03bf92aa8a6126a7bdee
Author: Michele Sciabarra <[email protected]>
AuthorDate: Sat Jul 4 23:13:53 2026 +0000

    db fixes
---
 nuvolaris/kustomize.py                           | 16 ++++++++-----
 nuvolaris/runtimes_preloader.py                  | 11 +++++++--
 nuvolaris/runtimes_util.py                       |  5 +++-
 nuvolaris/templates/postgres_manage_user_tpl.sql | 30 +++++++++++++++++++-----
 4 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/nuvolaris/kustomize.py b/nuvolaris/kustomize.py
index 9bc4ed7..9ade46a 100644
--- a/nuvolaris/kustomize.py
+++ b/nuvolaris/kustomize.py
@@ -22,6 +22,13 @@ import nuvolaris.kube as kube
 import nuvolaris.kustomize as nku
 import nuvolaris.template as ntp
 
+def _build(dir):
+    res = subprocess.run(["kustomize", "build", dir], capture_output=True)
+    if res.returncode != 0:
+        error = res.stderr.decode("utf-8")
+        raise Exception(error)
+    return res.stdout.decode("utf-8")
+
 # execute the kustomization of a folder under "deploy"
 # specified with `where`
 # it generate a kustomization.yaml, adding the header 
@@ -66,8 +73,7 @@ def kustomize(where, *what, templates=[], data={}):
             out = f"deploy/{where}/__{template}"
             file = ntp.spool_template(template, out, data)
             f.write(f"- __{template}\n")
-    res = subprocess.run(["kustomize", "build", dir], capture_output=True)
-    return res.stdout.decode("utf-8")
+    return _build(dir)
 
 # execute the kustomization of a folder under "deploy"
 # specified with `where` returning the expanded kustomization
@@ -76,8 +82,7 @@ def kustomize(where, *what, templates=[], data={}):
 # the nuvolaris operator needs to delete a component
 def build(where):
     dir = f"deploy/{where}"
-    res = subprocess.run(["kustomize", "build", dir], capture_output=True)
-    return res.stdout.decode("utf-8")   
+    return _build(dir)
 
 # execute the kustomization of a folder under "deploy"
 # specified with `where`
@@ -125,8 +130,7 @@ def restricted_kustomize(where, *what, templates=[], 
templates_filter=[],data={}
             out = f"deploy/{where}/__{template}"
             file = ntp.spool_template(template, out, data)
             f.write(f"- __{template}\n")
-    res = subprocess.run(["kustomize", "build", dir], capture_output=True)
-    return res.stdout.decode("utf-8")    
+    return _build(dir)
 
 # generate image kustomization
 def image(name, newName=None, newTag=None):
diff --git a/nuvolaris/runtimes_preloader.py b/nuvolaris/runtimes_preloader.py
index af57df4..f0433ad 100644
--- a/nuvolaris/runtimes_preloader.py
+++ b/nuvolaris/runtimes_preloader.py
@@ -25,10 +25,17 @@ import json
 
 def create(owner=None):
     logging.info(f"*** configuring runtime preloader")
-    only_apache = cfg.get("nuvolaris.preloader.only_apache", defval=True)
+    config = cfg.getall()
+    only_apache = config.get(
+        "nuvolaris.preload.only-apache",
+        config.get("nuvolaris.preloader.only_apache", True)
+    )
 
     runtimes_as_json = util.get_runtimes_json_from_config_map()
     data=rutil.parse_runtimes(json.loads(runtimes_as_json), only_apache)
+    if not data['containers']:
+        logging.info("*** skipped runtime preloader: no valid runtime images 
found")
+        return "skipped runtime preloader"
     
     kust = kus.patchTemplates("runtimes", 
["runtimes-job-container-attach.yaml"], data)
     spec = kus.kustom_list("runtimes", kust, templates=[], data=data)
@@ -61,4 +68,4 @@ def delete(owner=None):
     if owner:        
         return delete_by_owner()
     else:
-        return delete_by_spec()
\ No newline at end of file
+        return delete_by_spec()
diff --git a/nuvolaris/runtimes_util.py b/nuvolaris/runtimes_util.py
index 621acee..fe6d509 100644
--- a/nuvolaris/runtimes_util.py
+++ b/nuvolaris/runtimes_util.py
@@ -32,6 +32,9 @@ def find_default_container(containers: list, container_name, 
runtime_list, only_
             img = runtime['image']
             is_apache = img['prefix'] == 'apache'
             if not only_apache or is_apache:
+                if not img.get('tag'):
+                    logging.warning(f"skipping runtime preloader for 
{container_name}: missing image tag")
+                    continue
                 container = {
                     "name": container_name,
                     "image": f"{img['prefix']}/{img['name']}:{img['tag']}"
@@ -54,4 +57,4 @@ def parse_runtimes(runtimes_as_json, only_apache=True):
         find_default_container(containers, name, 
runtimes_as_json["runtimes"][name], only_apache)
            
     data['containers']=containers
-    return data
\ No newline at end of file
+    return data
diff --git a/nuvolaris/templates/postgres_manage_user_tpl.sql 
b/nuvolaris/templates/postgres_manage_user_tpl.sql
index ab5640e..a5ba5f0 100644
--- a/nuvolaris/templates/postgres_manage_user_tpl.sql
+++ b/nuvolaris/templates/postgres_manage_user_tpl.sql
@@ -18,14 +18,32 @@
  */
 
 {% if mode == 'create' %}
-CREATE DATABASE {{database}};
-CREATE USER {{username}} WITH PASSWORD '{{password}}';
+SELECT 'CREATE DATABASE {{database}}'
+WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '{{database}}')\gexec
+
+DO $$
+BEGIN
+    IF EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = '{{username}}') 
THEN
+        ALTER USER {{username}} WITH PASSWORD '{{password}}';
+    ELSE
+        CREATE USER {{username}} WITH PASSWORD '{{password}}';
+    END IF;
+END
+$$;
+
 GRANT ALL PRIVILEGES ON DATABASE {{database}} to {{username}};
 REVOKE CONNECT ON DATABASE {{database}} from public;
 {% endif %}
 
 {% if mode == 'delete' %}
-DROP DATABASE {{database}};
-DROP OWNED BY {{username}};
-DROP USER {{username}};
-{% endif %}
\ No newline at end of file
+DROP DATABASE IF EXISTS {{database}};
+
+DO $$
+BEGIN
+    IF EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = '{{username}}') 
THEN
+        DROP OWNED BY {{username}};
+        DROP USER {{username}};
+    END IF;
+END
+$$;
+{% endif %}

Reply via email to