Skip to content

Commit 07f3600

Browse files
authored
Merge pull request #67 from d4rkstar/minio_new
Minio new + remove auto from apihost + set default schema for databases
2 parents b9703cf + 0419ead commit 07f3600

16 files changed

+180
-50
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &
137137
curl -sL "$WSK_BASE/$WSK_VERSION/OpenWhisk_CLI-$WSK_VERSION-linux-$ARCH.tgz" | tar xzvf - -C /usr/bin/ && \
138138
# install minio
139139
MINIO_BASE=https://dl.min.io/client/mc/release/linux && \
140-
MC_VER=RELEASE.2023-03-23T20-03-04Z && \
140+
MC_VER=RELEASE.2025-05-21T01-59-54Z && \
141141
curl -sL "$MINIO_BASE-$ARCH/archive/mc.${MC_VER}" -o /usr/bin/mc && chmod +x /usr/bin/mc && \
142142
# install taskfile
143143
curl -sL https://taskfile.dev/install.sh | sh -s -- -d -b /usr/bin

nuvolaris/apihost_util.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,6 @@ def extract_port(url):
161161
parsed_url = urllib.parse.urlparse(url)
162162
return parsed_url.port
163163

164-
def extract_hostname(url):
165-
"""
166-
Parse a url and extract the hostname part
167-
>>> extract_hostname('http://localhost:8080')
168-
'localhost'
169-
>>> extract_hostname('https://nuvolaris.org')
170-
'nuvolaris.org'
171-
"""
172-
parsed_url = urllib.parse.urlparse(url)
173-
return parsed_url.hostname
174-
175164
def split_hostname_port(url):
176165
"""
177166
Parse a url and extract the port part
@@ -190,9 +179,6 @@ def get_user_static_hostname(runtime, username, apihost):
190179
inside the cm/config configMap prepending the user_namespace when needed.
191180
"""
192181

193-
if apihost not in ["auto"]:
194-
return apihost
195-
196182
apihost_url = util.get_apihost_from_config_map()
197183

198184
if apihost_url:

nuvolaris/kube.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# default output is text
3838
# if you specify jsonpath it will filter and parse the json output
3939
# returns exceptions if errors
40-
def kubectl(*args, namespace="nuvolaris", input=None, jsonpath=None, debugresult=True):
40+
def kubectl(*args, namespace="nuvolaris", input=None, jsonpath=None, debugresult=True, timeout=None):
4141
# support for mocked requests
4242
mres = mocker.invoke(*args)
4343
if mres:
@@ -55,7 +55,7 @@ def kubectl(*args, namespace="nuvolaris", input=None, jsonpath=None, debugresult
5555

5656
# executing
5757
logging.debug(cmd)
58-
res = subprocess.run(cmd, capture_output=True, input=input)
58+
res = subprocess.run(cmd, capture_output=True, input=input, timeout=timeout)
5959

6060
global returncode, output, error
6161
returncode = res.returncode

nuvolaris/minio_util.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,23 @@ def mc(self, *kwargs):
5454
error = res.stderr.decode()
5555

5656
if returncode != 0:
57+
self.last_output = error
5758
logging.error(error)
5859
else:
60+
self.last_output = output
5961
logging.info(output)
6062

6163
return returncode == 0
6264
except Exception as e:
63-
logging.error(e)
64-
return e
65+
logging.error(e)
66+
return e
67+
68+
def get_last_output(self):
69+
"""
70+
returns the last output of the executed command
71+
"""
72+
return self.last_output if hasattr(self, 'last_output') else None
73+
6574

6675
def add_user(self, username, secret_key):
6776
"""
@@ -101,6 +110,7 @@ def assign_quota_to_bucket(self, bucket_name, quota):
101110
assign the specified quota on the given bucket
102111
"""
103112
return util.check(self.mc("quota","set",f"{self.alias}/{bucket_name}","--size", f"{quota}m"),"assign_quota_to_bucket",True)
113+
104114

105115
def assign_policy_to_user(self, username, policy):
106116
"""

nuvolaris/policies/minio_rw_policy_tpl.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77
],
88
"Effect": "Allow",
99
"Resource": [
10-
{% for bucket_arn in bucket_arns -%}
11-
"arn:aws:s3:::{{bucket_arn}}"
12-
{% if not loop.last %}
13-
,
14-
{% endif %}
15-
{% endfor %}
10+
{% for bucket_arn in bucket_arns %}"arn:aws:s3:::{{ bucket_arn }}"{{ "," if not loop.last }}{% endfor %}
1611
]
1712
}
1813
]

nuvolaris/postgres_operator.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,16 @@ def render_postgres_script(namespace,template,data):
178178
file = ntp.spool_template(template, out, data)
179179
return os.path.abspath(file)
180180

181-
def exec_psql_command(pod_name,path_to_psql_script,path_to_pgpass):
181+
def exec_psql_command(pod_name,path_to_psql_script,path_to_pgpass,additional_psql_args=''):
182182
logging.info(f"passing script {path_to_psql_script} to pod {pod_name}")
183183
res = kube.kubectl("cp",path_to_psql_script,f"{pod_name}:{path_to_psql_script}")
184184
res = kube.kubectl("cp",path_to_pgpass,f"{pod_name}:/tmp/.pgpass")
185185
res = kube.kubectl("exec","-it",pod_name,"--","/bin/bash","-c",f"chmod 600 /tmp/.pgpass")
186-
res = kube.kubectl("exec","-it",pod_name,"--","/bin/bash","-c",f"PGPASSFILE='/tmp/.pgpass' psql --username postgres --dbname postgres -f {path_to_psql_script}")
186+
187+
cmd = f"PGPASSFILE='/tmp/.pgpass' psql --username postgres --dbname postgres {additional_psql_args} -f {path_to_psql_script}"
188+
logging.info(f"executing command: {cmd}")
189+
res = kube.kubectl("exec","-it",pod_name,"--","/bin/bash","-c",cmd)
190+
187191
os.remove(path_to_psql_script)
188192
os.remove(path_to_pgpass)
189193
return res
@@ -209,6 +213,10 @@ def create_db_user(ucfg: UserConfig, user_metadata: UserMetadata):
209213
if res:
210214
_add_pdb_user_metadata(ucfg, user_metadata)
211215

216+
path_to_pgpass = render_postgres_script(ucfg.get('namespace'),"dbname_pgpass_tpl.properties",data)
217+
path_to_schema_script = render_postgres_script(ucfg.get('namespace'),"postgres_manage_user_schema_tpl.sql",data)
218+
res = exec_psql_command_in_db(database,pod_name,path_to_schema_script,path_to_pgpass)
219+
212220
data["extensions"]=["vector"]
213221
path_to_pgpass = render_postgres_script(ucfg.get('namespace'),"dbname_pgpass_tpl.properties",data)
214222
path_to_extensions_script = render_postgres_script(ucfg.get('namespace'),"postgres_manage_user_extension_tpl.sql",data)
@@ -232,12 +240,17 @@ def delete_db_user(namespace, database):
232240
data["database"]=database
233241
data["mode"]="delete"
234242

235-
path_to_pgpass = render_postgres_script(namespace,"pgpass_tpl.properties",data)
236-
path_to_mdb_script = render_postgres_script(namespace,"postgres_manage_user_tpl.sql",data)
243+
237244
pod_name = util.get_pod_name_by_selector("app=nuvolaris-postgres","{.items[?(@.metadata.labels.replicationRole == 'primary')].metadata.name}")
238245

239246
if(pod_name):
240-
res = exec_psql_command(pod_name,path_to_mdb_script,path_to_pgpass)
247+
path_to_pgpass = render_postgres_script(namespace,"pgpass_tpl.properties",data)
248+
path_to_ter_script = render_postgres_script(namespace,"postgres_terminate_tpl.sql",data)
249+
res = exec_psql_command(pod_name,path_to_ter_script,path_to_pgpass,' -q -t ')
250+
251+
path_to_pgpass = render_postgres_script(namespace,"pgpass_tpl.properties",data)
252+
path_to_mdb_script = render_postgres_script(namespace,"postgres_manage_user_tpl.sql",data)
253+
res += exec_psql_command(pod_name,path_to_mdb_script,path_to_pgpass)
241254
return res
242255

243256
return None

nuvolaris/templates/01-minio-dep.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ spec:
4343
{% endif %}
4444
containers:
4545
- name: minio
46-
image: bitnami/minio:2023.3.24
46+
image: bitnami/minio:2025.6.13
4747
securityContext:
4848
capabilities:
4949
drop:
@@ -53,11 +53,7 @@ spec:
5353
allowPrivilegeEscalation: false
5454
readOnlyRootFilesystem: false
5555
runAsNonRoot: true
56-
command:
57-
- /bin/bash
58-
- -c
59-
args:
60-
- minio server /data --console-address :9090
56+
command: ["/bin/bash", "-c", "minio server /data --console-address :9090"]
6157
env:
6258
- name: MINIO_ROOT_USER
6359
value: {{minio_root_user}}

nuvolaris/templates/postgres_manage_user_extension_tpl.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
{% if mode == 'create' %}
2121
{% for extension in extensions -%}
22-
CREATE EXTENSION IF NOT EXISTS {{extension}};
22+
CREATE EXTENSION IF NOT EXISTS {{extension}} WITH SCHEMA {{username}}_schema;
2323
{% endfor %}
2424
{% endif %}
2525

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
{% if mode == 'create' %}
21+
-- Create schema only if not exists and owned by correct user
22+
CREATE SCHEMA IF NOT EXISTS {{username}}_schema;
23+
ALTER SCHEMA {{username}}_schema OWNER TO {{username}};
24+
ALTER DATABASE {{database}} SET search_path TO {{username}}_schema, pg_catalog;
25+
{% endif %}

nuvolaris/templates/postgres_manage_user_tpl.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ REVOKE CONNECT ON DATABASE {{database}} from public;
2525
{% endif %}
2626

2727
{% if mode == 'delete' %}
28-
SELECT pg_terminate_backend(pg_stat_activity.pid)
29-
FROM pg_stat_activity
30-
WHERE pg_stat_activity.datname = '{{database}}';
31-
3228
DROP DATABASE {{database}};
33-
3429
DROP OWNED BY {{username}};
3530
DROP USER {{username}};
3631
{% endif %}

0 commit comments

Comments
 (0)