Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IBCDPE-1004] Create connection pooler #27

Merged
merged 14 commits into from
Aug 20, 2024
2 changes: 1 addition & 1 deletion deployments/stacks/dpe-k8s-deployments/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module "postgres-cloud-native-operator" {
module "postgres-cloud-native-database" {
depends_on = [module.postgres-cloud-native-operator, module.airflow, module.argo-cd]
source = "spacelift.io/sagebionetworks/postgres-cloud-native-database/aws"
version = "0.3.1"
version = "0.4.0"
auto_deploy = true
auto_prune = true
git_revision = var.git_revision
Expand Down
2 changes: 1 addition & 1 deletion modules/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ locals {
description = "Helm chart deployment for a postgres database instance using the postgres-cloud-native-operator."
project_root = "modules/postgres-cloud-native"
space_id = "root"
version_number = "0.3.1"
version_number = "0.4.0"
}

postgres-cloud-native-operator = {
Expand Down
27 changes: 22 additions & 5 deletions modules/postgres-cloud-native/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ spec:
- repoURL: 'https://github.com/Sage-Bionetworks-Workflows/eks-stack.git'
targetRevision: ${var.git_revision}
ref: values
- repoURL: 'https://github.com/Sage-Bionetworks-Workflows/eks-stack.git'
targetRevision: ${var.git_revision}
path: modules/postgres-cloud-native/resources
kustomize:
patches:
- target:
kind: Pooler
patch: |-
- op: replace
path: /spec/cluster/name
value: ${var.argo_deployment_name}-cluster
- op: replace
path: /spec/instances
value: 2
- op: replace
path: /metadata/name
value: ${var.argo_deployment_name}-pooler-rw
destination:
server: 'https://kubernetes.default.svc'
namespace: ${var.namespace}
Expand All @@ -54,14 +71,14 @@ resource "kubernetes_secret" "connection-secret" {

data = {
"dbname" = "application-database"
"host" = "${var.argo_deployment_name}-cluster-rw.${var.namespace}"
"jdbc-uri" = "jdbc:postgresql://${var.argo_deployment_name}-cluster-rw.${var.namespace}:5432/application-database?password=${random_password.pg-password.result}&user=application-database"
"host" = "${var.argo_deployment_name}-pooler-rw.${var.namespace}"
"jdbc-uri" = "jdbc:postgresql://${var.argo_deployment_name}-pooler-rw.${var.namespace}:5432/application-database?password=${random_password.pg-password.result}&user=application-database"
"password" = random_password.pg-password.result
"pgpass" = "${var.argo_deployment_name}-cluster-rw:5432:application-database:application-database:${random_password.pg-password.result}"
"pgpass" = "${var.argo_deployment_name}-pooler-rw:5432:application-database:application-database:${random_password.pg-password.result}"
"port" = "5432"
"uri" = "postgresql://application-database:${random_password.pg-password.result}@${var.argo_deployment_name}-cluster-rw.${var.namespace}:5432/application-database"
"uri" = "postgresql://application-database:${random_password.pg-password.result}@${var.argo_deployment_name}-pooler-rw.${var.namespace}:5432/application-database"
"user" = "application-database"
"username" = "application-database"
"connection" = "postgresql://application-database:${random_password.pg-password.result}@${var.argo_deployment_name}-cluster-rw.${var.namespace}:5432/application-database"
"connection" = "postgresql://application-database:${random_password.pg-password.result}@${var.argo_deployment_name}-pooler-rw.${var.namespace}:5432/application-database"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A future enhancement would be to allow the person using this module to create a connection pooler or not. Likely they would have a sensible application that doesn't take every connection to the DB possible.

}
}
4 changes: 4 additions & 0 deletions modules/postgres-cloud-native/resources/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- pooler.yaml
15 changes: 15 additions & 0 deletions modules/postgres-cloud-native/resources/pooler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: postgresql.cnpg.io/v1
kind: Pooler
metadata:
name: replaced-by-kustomize
spec:
cluster:
name: replaced-by-kustomize-2

instances: 2
type: rw
pgbouncer:
poolMode: session
parameters:
max_client_conn: "1000"
default_pool_size: "20"