From 7cd3aeb29e95e3c6c6436b170d1d5e51b24392bd Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 5 Apr 2024 22:41:46 +0200 Subject: [PATCH] Allow custom pgbouncer pass and enhance volume handling --- templates/task.pgbouncer | 2 +- templates/volumes | 14 +++++++++++--- templates/volumes_mount | 13 +++++++++++++ variables.yml | 3 +++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 templates/volumes_mount diff --git a/templates/task.pgbouncer b/templates/task.pgbouncer index a94486d..94987c8 100644 --- a/templates/task.pgbouncer +++ b/templates/task.pgbouncer @@ -65,7 +65,7 @@ _EOT template { data =<<_EOT -"[[ .instance ]]" "{{ env "NOMAD_ALLOC_ID" }}" +"[[ .postgres.pooler.local_user ]]" "[[ .postgres.pooler.local_password ]]" _EOT destination = "secrets/pgbouncer.users" uid = 106432 diff --git a/templates/volumes b/templates/volumes index 98dc79f..5af93c0 100644 --- a/templates/volumes +++ b/templates/volumes @@ -10,13 +10,21 @@ [[- $volumes = . ]] [[- end ]] [[- range $volname, $volume := $volumes ]] + + [[- $type := "" ]] + [[- if has $volume "type" ]] + [[- $type = $volume.type ]] + [[- else ]] + [[- $type = "csi" ]] + [[- end ]] + volume "[[ $volname ]]" { - source = [[ $volume.source | toJSON ]] - type = [[ $volume.type | toJSON ]] + source = "[[ if has $volume "source" ]][[ $volume.source ]][[ else ]][[ $volname ]][[ end ]]" + type = "[[ $type ]]" [[- if has $volume "read_only" ]] read_only = [[ if $volume.read_only ]]true[[ else ]]false[[ end ]] [[- end ]] - [[- if ne $volume.type "host" ]] + [[- if ne $type "host" ]] access_mode = "[[ if has $volume "access_mode" ]][[ $volume.access_mode ]][[ else ]]single-node-writer[[ end ]]" attachment_mode = "file-system" [[- end ]] diff --git a/templates/volumes_mount b/templates/volumes_mount new file mode 100644 index 0000000..b3e639d --- /dev/null +++ b/templates/volumes_mount @@ -0,0 +1,13 @@ +[[- if has . "volumes" ]] + [[- range $volname, $volume := .volumes ]] + [[- if has $volume "destination" ]] + volume_mount { + volume = "[[ $volname ]]" + destination = "[[ $volume.destination ]]" + [[- if has $volume "read_only" ]] + read_only = [[ if $volume.read_only ]]true[[ else ]]false[[ end ]] + [[- end ]] + } + [[- end ]] + [[- end ]] +[[- end ]] diff --git a/variables.yml b/variables.yml index 24ddfda..f0dcea9 100644 --- a/variables.yml +++ b/variables.yml @@ -104,6 +104,9 @@ postgres: pooler: # Only none or pgbouncer supported for now engine: none + # Credentials of the local user created (for the app to auth on the pooler) + local_user: '[[ .instance ]]' + local_password: '{{ env "NOMAD_ALLOC_ID" }}' # Port on which the pooler will listen port: 6432 # Mode can be session or transaction