-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BC-7024-migration-to-ionos-postgres-dev (#160)
Add option for postgres management (branch specific database creation/deletion) to calendar role
- Loading branch information
1 parent
793d7bb
commit 95f6132
Showing
8 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
ansible/roles/schulcloud-calendar-core/templates/configmap-database-init.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: pg-calendar-configmap-init | ||
namespace: {{ NAMESPACE }} | ||
labels: | ||
app: calendar-postgres-init | ||
data: | ||
config_script.sh: | | ||
#!/bin/bash | ||
echo "Create owner of the DB" | ||
echo "SELECT 'CREATE USER $DB_USER' WHERE NOT EXISTS (SELECT FROM pg_user WHERE usename = '$DB_USER')\gexec" | psql -d postgres -w | ||
echo "GRANT $DB_USER TO $PGUSER;" | psql -d postgres -w | ||
echo "Set/update password for user $DB_USER" | ||
echo "ALTER USER $DB_USER WITH ENCRYPTED PASSWORD '$DB_USER_PASSWORD';" | psql -d postgres -w | ||
echo "Create database" | ||
echo "SELECT 'CREATE DATABASE $DB_NAME OWNER $DB_USER' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '$DB_NAME')\gexec" | psql -d postgres -w | ||
echo "Revoke permissions for public role" | ||
echo "REVOKE ALL ON DATABASE $DB_NAME FROM PUBLIC;" | psql -d postgres -w |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
ansible/roles/schulcloud-calendar-core/templates/job-database-init.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: pg-calendar-init-job-{{ 1000000 | random | hash('md5') }} | ||
namespace: {{ NAMESPACE }} | ||
labels: | ||
app: calendar-postgres-init | ||
app.kubernetes.io/part-of: schulcloud-verbund | ||
app.kubernetes.io/name: calendar-postgres-init | ||
app.kubernetes.io/component: calendar | ||
app.kubernetes.io/managed-by: ansible | ||
git.repo: {{ SCHULCLOUD_CALENDAR_REPO_NAME }} | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: calendar-postgres-init | ||
app.kubernetes.io/part-of: schulcloud-verbund | ||
app.kubernetes.io/name: calendar-postgres-init | ||
app.kubernetes.io/component: calendar | ||
app.kubernetes.io/managed-by: ansible | ||
git.repo: {{ SCHULCLOUD_CALENDAR_REPO_NAME }} | ||
spec: | ||
volumes: | ||
- name: config-script | ||
configMap: | ||
name: pg-calendar-configmap-init | ||
# 711 in decimal is 457 | ||
defaultMode: 457 | ||
containers: | ||
- name: psql-calendar-config | ||
image: {{ POSTGRES_MANAGEMENT_JOB_IMAGE }} | ||
command: | ||
- /bin/bash | ||
- -c | ||
args: | ||
- /scripts/config_script.sh | ||
resources: | ||
limits: | ||
cpu: 1000m | ||
memory: 1Gi | ||
requests: | ||
cpu: 100m | ||
memory: 200Mi | ||
volumeMounts: | ||
- name: config-script | ||
mountPath: /scripts/ | ||
envFrom: | ||
- secretRef: | ||
name: pg-calendar-secret | ||
env: | ||
- name: PGHOST | ||
value: {{ POSTGRES_MANAGEMENT_HOST }} | ||
- name: PGUSER | ||
valueFrom: | ||
secretKeyRef: | ||
name: pg-cluster-secret | ||
key: username | ||
- name: PGPASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: pg-cluster-secret | ||
key: password | ||
restartPolicy: Never | ||
ttlSecondsAfterFinished: 1800 |
12 changes: 12 additions & 0 deletions
12
ansible/roles/schulcloud-calendar-core/templates/secret-database.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: pg-calendar-secret | ||
namespace: {{ NAMESPACE }} | ||
labels: | ||
app: calendar-postgres-init | ||
type: Opaque | ||
data: | ||
DB_USER: "{{ (POSTGRES_MANAGEMENT_PREFIX + 'calendar') | b64encode }}" | ||
DB_USER_PASSWORD: "{{ lookup('ansible.builtin.password', '/dev/null') | b64encode }}" | ||
DB_NAME: "{{ (POSTGRES_MANAGEMENT_PREFIX + 'calendar') | b64encode }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters