Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/fylr/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type: application
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)

version: 0.1.154
version: 0.1.155

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
25 changes: 25 additions & 0 deletions charts/fylr/templates/autodbDeletion-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if .Values.autoManageDB.enabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: autodb-delete-{{ .Values.autoManageDB.name }}
labels:
{{- include "fylr.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": "post-delete"
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template:
spec:
restartPolicy: Never
containers:
- name: psql-delete
image: postgres:17.5
env:
- name: PGPASSWORD
value: "{{ .Values.autoManageDB.pgPass }}"
command: ["/bin/sh", "-c"]
args:
- psql -h {{ .Values.autoManageDB.pghost }} -U {{ .Values.autoManageDB.pgUser }} -d postgres -c "DROP DATABASE IF EXISTS \"{{ .Values.autoManageDB.name }}\";" -c "DROP ROLE IF EXISTS \"{{ .Values.autoManageDB.user }}\";"
{{- end }}
52 changes: 52 additions & 0 deletions charts/fylr/templates/autodbcreation-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{- if .Values.autoManageDB.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: autodb-create-{{ .Values.autoManageDB.name }}
labels:
{{- include "fylr.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
data:
init-role-db.sh: |
#!/bin/bash

# Wait for PostgreSQL to be ready
until psql -h "$PGHOST" -U "$PGUSER" -c '\l'; do
echo "Waiting for PostgreSQL to be ready..."
sleep 2
done

# Check if role exists
echo "Checking if role $DB_USER exists..."
ROLE_EXISTS=$(psql -h "$PGHOST" -U "$PGUSER" -t -c "SELECT 1 FROM pg_roles WHERE rolname = '$DB_USER'")

# Check if database exists
echo "Checking if database $DB_NAME exists..."
DB_EXISTS=$(psql -h "$PGHOST" -U "$PGUSER" -t -c "SELECT 1 FROM pg_database WHERE datname = '$DB_NAME'")

# Check both conditions together
if [ -z "$ROLE_EXISTS" ] || [ -z "$DB_EXISTS" ]; then
# Create role if it doesn't exist
if [ -z "$ROLE_EXISTS" ]; then
echo "Creating role $DB_USER..."
psql -h "$PGHOST" -U "$PGUSER" -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASSWORD';"
else
echo "Role $DB_USER already exists"
fi

# Create database if it doesn't exist
if [ -z "$DB_EXISTS" ]; then
echo "Creating database $DB_NAME..."
psql -h "$PGHOST" -U "$PGUSER" -c "CREATE DATABASE $DB_NAME OWNER $DB_USER;"
else
echo "Database $DB_NAME already exists"
fi
else
echo "Both role $DB_USER and database $DB_NAME already exist, nothing to do."
fi

echo "Role and database creation complete. Job finished."
{{- end }}
48 changes: 48 additions & 0 deletions charts/fylr/templates/autodbcreation-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{- if .Values.autoManageDB.enabled -}}
apiVersion: batch/v1
kind: Job
metadata:
name: autodb-create-{{ .Values.autoManageDB.name }}
labels:
{{- include "fylr.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template:
spec:
restartPolicy: Never
containers:
- name: psql-init
image: postgres:17.5 # should match the postgres cluster image to avoid compatibility issues
env:
- name: PGPASSWORD
value: {{ .Values.autoManageDB.pgPass }}

- name: PGHOST
value: {{ .Values.autoManageDB.pghost }}

- name: PGUSER
value: {{ .Values.autoManageDB.pgUser }}

- name: DB_NAME
value: {{ .Values.autoManageDB.name }}

- name: DB_USER
value: {{ .Values.autoManageDB.user }}

- name: DB_PASSWORD
value: {{ .Values.autoManageDB.password }}

command: ["/bin/sh", "-c"]
args:
- "sh /scripts/init-role-db.sh"
volumeMounts:
- name: scripts
mountPath: /scripts
volumes:
- name: scripts
configMap:
name: autodb-create-{{ .Values.autoManageDB.name }}
{{- end }}
17 changes: 17 additions & 0 deletions charts/fylr/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ fylr:
driver: "postgres"
# -- (object) postgresql connection settings
# NOTE: this is ignored if postgresql-ha.enabled is set to true.
# If you enable autoManageDB, please fill the db info here.
postgres:
# -- (string) host is the host of the postgres server.
host: "localhost"
Expand Down Expand Up @@ -600,6 +601,22 @@ minio:
conditions:
- StringEquals: '"aws:username": "fylr"'

# If enabled, the chart will create a database on the provided database server URL $pghost using a Helm pre-install hook with the given details.
# It will also delete the database when the chart is uninstalled using a Helm post-delete hook.
autoManageDB:
# Set to true to enable auto creation/deletion
enabled: false
# Database Postgres URl
pghost: "url"
pgUser: "super user"
pgPass: "super pass"
# database name to create in the $pghost database server.
name: "fylr_db"
# The user owning the database to create in the $pghost database server.
user: "fylr_user"
# The password to assign to the user $user created in the $pghost database server.
password: "securepassword"

# @ignored defines the settings for the postgresql application
# for more information see: https://github.com/bitnami/charts/tree/master/bitnami/postgresql-ha
postgresql-ha:
Expand Down