massive refactor
This commit is contained in:
parent
5934c27d2e
commit
aaa2cde425
|
|
@ -1,4 +1,14 @@
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- firefly-db.yaml
|
- fireflysecrets.yaml
|
||||||
|
- ../../../infrastructure/modules/postgres-app
|
||||||
|
|
||||||
|
patches:
|
||||||
|
- target:
|
||||||
|
kind: Job
|
||||||
|
name: postgres-init
|
||||||
|
patch: |
|
||||||
|
- op: replace
|
||||||
|
path: /metadata/name
|
||||||
|
value: postgres-init-firefly
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,3 @@ resources:
|
||||||
- pvc.yaml
|
- pvc.yaml
|
||||||
- service.yaml
|
- service.yaml
|
||||||
- db
|
- db
|
||||||
- fireflysecrets.yaml
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,6 @@ resources:
|
||||||
- db
|
- db
|
||||||
- kimaisecrets.yaml
|
- kimaisecrets.yaml
|
||||||
|
|
||||||
#spec:
|
|
||||||
# dependsOn:
|
|
||||||
# - name: secrets
|
|
||||||
|
|
||||||
namespace: kimai
|
namespace: kimai
|
||||||
|
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,4 @@ kind: Namespace
|
||||||
metadata:
|
metadata:
|
||||||
name: kimai
|
name: kimai
|
||||||
labels:
|
labels:
|
||||||
backup: true
|
backup: "true"
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,5 @@ apiVersion: v1
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
metadata:
|
metadata:
|
||||||
name: cnpg-system
|
name: cnpg-system
|
||||||
|
labels:
|
||||||
|
backup: "true"
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
resources:
|
||||||
|
- pg-cluster.yaml
|
||||||
10
infrastructure/databases/cnpg-clusters/pg-cluster.yaml
Normal file
10
infrastructure/databases/cnpg-clusters/pg-cluster.yaml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
apiVersion: postgresql.cnpg.io/v1
|
||||||
|
kind: Cluster
|
||||||
|
metadata:
|
||||||
|
name: pg-cluster
|
||||||
|
namespace: pg-databases
|
||||||
|
spec:
|
||||||
|
instances: 3
|
||||||
|
|
||||||
|
storage:
|
||||||
|
size: 20Gi
|
||||||
|
|
@ -4,3 +4,4 @@ resources:
|
||||||
- cloudnative-pg
|
- cloudnative-pg
|
||||||
- mariadb-operator
|
- mariadb-operator
|
||||||
- mariadb-clusters
|
- mariadb-clusters
|
||||||
|
- cnpg-clusters
|
||||||
|
|
|
||||||
61
infrastructure/modules/postgres-app/job.yaml
Normal file
61
infrastructure/modules/postgres-app/job.yaml
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: Job
|
||||||
|
metadata:
|
||||||
|
name: postgres-init
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
restartPolicy: OnFailure
|
||||||
|
containers:
|
||||||
|
- name: psql
|
||||||
|
image: postgres:16
|
||||||
|
env:
|
||||||
|
- name: PGHOST
|
||||||
|
value: pg-cluster-rw.pg-databases.svc.cluster.local
|
||||||
|
- name: PGUSER
|
||||||
|
value: postgres
|
||||||
|
- name: PGPASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: pg-superuser-secret
|
||||||
|
key: password
|
||||||
|
|
||||||
|
- name: APP_DB
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: app-db-secret
|
||||||
|
key: database
|
||||||
|
- name: APP_USER
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: app-db-secret
|
||||||
|
key: username
|
||||||
|
- name: APP_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: app-db-secret
|
||||||
|
key: password
|
||||||
|
|
||||||
|
command:
|
||||||
|
- sh
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
psql <<EOF
|
||||||
|
DO \$\$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${APP_USER}') THEN
|
||||||
|
CREATE USER ${APP_USER} WITH PASSWORD '${APP_PASSWORD}';
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
\$\$;
|
||||||
|
|
||||||
|
DO \$\$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (SELECT FROM pg_database WHERE datname = '${APP_DB}') THEN
|
||||||
|
CREATE DATABASE ${APP_DB} OWNER ${APP_USER};
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
\$\$;
|
||||||
|
|
||||||
|
GRANT ALL PRIVILEGES ON DATABASE ${APP_DB} TO ${APP_USER};
|
||||||
|
EOF
|
||||||
4
infrastructure/modules/postgres-app/kustomization.yaml
Normal file
4
infrastructure/modules/postgres-app/kustomization.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
resources:
|
||||||
|
- job.yaml
|
||||||
Loading…
Reference in a new issue