From 98f12274a68d4e1d37057285a86b91f3808a98fd Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Thu, 26 Sep 2024 09:50:54 +0200 Subject: [PATCH] feat(postgres): adding pgbouncer support for cnpg component Mandatory for large scale deployements --- .../hydra-cnpg-database/kustomization.yaml | 40 +++++++++---------- .../patches/hydra-deployment.yaml | 11 +++-- .../patches/hydra-janitor-cronjob.yaml | 14 +++++-- .../patches/hydra-migrate-job.yaml | 14 +++++-- .../resources/hydra-cnpg-cluster.yaml | 6 +-- .../resources/hydra-postgres-pooler-rw.yaml | 14 +++++++ 6 files changed, 65 insertions(+), 34 deletions(-) create mode 100644 components/hydra-cnpg-database/resources/hydra-postgres-pooler-rw.yaml diff --git a/components/hydra-cnpg-database/kustomization.yaml b/components/hydra-cnpg-database/kustomization.yaml index 4ebccef..b9de1f6 100644 --- a/components/hydra-cnpg-database/kustomization.yaml +++ b/components/hydra-cnpg-database/kustomization.yaml @@ -6,28 +6,28 @@ configurations: resources: - ./resources/hydra-cnpg-cluster.yaml +- ./resources/hydra-postgres-pooler-rw.yaml -secretGenerator: -- name: hydra-postgres-admin - type: Secret - literals: - - username=postgres - - password=NotSoSecret -- name: hydra-postgres-user - type: Secret - literals: - - username=hydra - - password=NotSoSecret +#secretGenerator: +#- name: hydra-postgres-admin +# type: Secret +# literals: +# - username=postgres +# - password=NotSoSecret +#- name: hydra-postgres-user +# type: Secret +# literals: +# - username=hydra +# - password=NotSoSecret - -vars: -- name: HYDRA_DATABASE_SERVICE_NAME - objref: - name: hydra-postgres - kind: Cluster - apiVersion: postgresql.cnpg.io/v1 - fieldref: - fieldpath: metadata.name +#vars: +#- name: HYDRA_DATABASE_SERVICE_NAME +# objref: +# name: hydra-postgres +# kind: Cluster +# apiVersion: postgresql.cnpg.io/v1 +# fieldref: +# fieldpath: metadata.name patches: - target: diff --git a/components/hydra-cnpg-database/patches/hydra-deployment.yaml b/components/hydra-cnpg-database/patches/hydra-deployment.yaml index 6185612..54fdd1b 100644 --- a/components/hydra-cnpg-database/patches/hydra-deployment.yaml +++ b/components/hydra-cnpg-database/patches/hydra-deployment.yaml @@ -4,7 +4,7 @@ name: HYDRA_DATABASE_USER valueFrom: secretKeyRef: - name: hydra-postgres-user + name: hydra-postgres-app key: username - op: add path: "/spec/template/spec/containers/0/env/-" @@ -12,10 +12,15 @@ name: HYDRA_DATABASE_PASSWORD valueFrom: secretKeyRef: - name: hydra-postgres-user + name: hydra-postgres-app key: password +- op: add + path: "/spec/template/spec/containers/0/env/-" + value: + name: HYDRA_DATABASE_SERVICE_NAME + value: hydra-postgres-pooler-rw - op: add path: "/spec/template/spec/containers/0/env/-" value: name: DSN - value: "postgres://$(HYDRA_DATABASE_USER):$(HYDRA_DATABASE_PASSWORD)@$(HYDRA_DATABASE_SERVICE_NAME)-rw:5432/hydra?sslmode=disable" \ No newline at end of file + value: "postgres://$(HYDRA_DATABASE_USER):$(HYDRA_DATABASE_PASSWORD)@$(HYDRA_DATABASE_SERVICE_NAME):5432/hydra?sslmode=disable" diff --git a/components/hydra-cnpg-database/patches/hydra-janitor-cronjob.yaml b/components/hydra-cnpg-database/patches/hydra-janitor-cronjob.yaml index a8f576e..467742b 100644 --- a/components/hydra-cnpg-database/patches/hydra-janitor-cronjob.yaml +++ b/components/hydra-cnpg-database/patches/hydra-janitor-cronjob.yaml @@ -4,7 +4,7 @@ name: HYDRA_DATABASE_USER valueFrom: secretKeyRef: - name: hydra-postgres-user + name: hydra-postgres-app key: username - op: add path: "/spec/jobTemplate/spec/template/spec/containers/0/env/-" @@ -12,10 +12,18 @@ name: HYDRA_DATABASE_PASSWORD valueFrom: secretKeyRef: - name: hydra-postgres-user + name: hydra-postgres-app key: password +- op: add + path: "/spec/jobTemplate/spec/template/spec/containers/0/env/-" + value: + name: HYDRA_DATABASE_SERVICE_NAME + valueFrom: + secretKeyRef: + name: hydra-postgres-app + key: host - op: add path: "/spec/jobTemplate/spec/template/spec/containers/0/env/-" value: name: DSN - value: "postgres://$(HYDRA_DATABASE_USER):$(HYDRA_DATABASE_PASSWORD)@$(HYDRA_DATABASE_SERVICE_NAME)-rw:5432/hydra?sslmode=disable" \ No newline at end of file + value: "postgres://$(HYDRA_DATABASE_USER):$(HYDRA_DATABASE_PASSWORD)@$(HYDRA_DATABASE_SERVICE_NAME):5432/hydra?sslmode=disable" diff --git a/components/hydra-cnpg-database/patches/hydra-migrate-job.yaml b/components/hydra-cnpg-database/patches/hydra-migrate-job.yaml index 6185612..c5e4447 100644 --- a/components/hydra-cnpg-database/patches/hydra-migrate-job.yaml +++ b/components/hydra-cnpg-database/patches/hydra-migrate-job.yaml @@ -4,7 +4,7 @@ name: HYDRA_DATABASE_USER valueFrom: secretKeyRef: - name: hydra-postgres-user + name: hydra-postgres-app key: username - op: add path: "/spec/template/spec/containers/0/env/-" @@ -12,10 +12,18 @@ name: HYDRA_DATABASE_PASSWORD valueFrom: secretKeyRef: - name: hydra-postgres-user + name: hydra-postgres-app key: password +- op: add + path: "/spec/template/spec/containers/0/env/-" + value: + name: HYDRA_DATABASE_SERVICE_NAME + valueFrom: + secretKeyRef: + name: hydra-postgres-app + key: host - op: add path: "/spec/template/spec/containers/0/env/-" value: name: DSN - value: "postgres://$(HYDRA_DATABASE_USER):$(HYDRA_DATABASE_PASSWORD)@$(HYDRA_DATABASE_SERVICE_NAME)-rw:5432/hydra?sslmode=disable" \ No newline at end of file + value: "postgres://$(HYDRA_DATABASE_USER):$(HYDRA_DATABASE_PASSWORD)@$(HYDRA_DATABASE_SERVICE_NAME):5432/hydra?sslmode=disable" diff --git a/components/hydra-cnpg-database/resources/hydra-cnpg-cluster.yaml b/components/hydra-cnpg-database/resources/hydra-cnpg-cluster.yaml index 7f48955..8d910f1 100644 --- a/components/hydra-cnpg-database/resources/hydra-cnpg-cluster.yaml +++ b/components/hydra-cnpg-database/resources/hydra-cnpg-cluster.yaml @@ -5,13 +5,9 @@ metadata: spec: instances: 3 primaryUpdateStrategy: unsupervised - superuserSecret: - name: hydra-postgres-admin bootstrap: initdb: database: hydra owner: hydra - secret: - name: hydra-postgres-user storage: - size: 2Gi \ No newline at end of file + size: 2Gi diff --git a/components/hydra-cnpg-database/resources/hydra-postgres-pooler-rw.yaml b/components/hydra-cnpg-database/resources/hydra-postgres-pooler-rw.yaml new file mode 100644 index 0000000..45fa942 --- /dev/null +++ b/components/hydra-cnpg-database/resources/hydra-postgres-pooler-rw.yaml @@ -0,0 +1,14 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Pooler +metadata: + name: hydra-postgres-pooler-rw +spec: + cluster: + name: hydra-postgres + instances: 3 + type: rw + pgbouncer: + poolMode: session + parameters: + max_client_conn: "1000" + default_pool_size: "50"