From eea0e5efddb008a6fe2e807fb77a3414b4752e83 Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Fri, 29 Dec 2023 22:47:08 +0100 Subject: [PATCH] kube/postgres: support resources specification, implement graceful shutdown Change-Id: Iaecf827a43422bd4c59b06e771273624c764f6b3 Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1856 Reviewed-by: informatic --- kube/postgres.libsonnet | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kube/postgres.libsonnet b/kube/postgres.libsonnet index 492a3ba2..259a63ee 100644 --- a/kube/postgres.libsonnet +++ b/kube/postgres.libsonnet @@ -71,6 +71,8 @@ local kube = import "kube.libsonnet"; # This exists solely for backwards compatibility with old postgres_v libsonnet # and should not be used in new deployments versionedNames: false, + + resources: {}, }, safeVersion:: std.strReplace(cfg.version, ".", "-"), @@ -101,12 +103,20 @@ local kube = import "kube.libsonnet"; volumes_: { data: postgres.volumeClaim.volume, }, + terminationGracePeriodSeconds: 120, containers_: { postgres: kube.Container(postgres.makeName("postgres")) { image: cfg.image, ports_: { client: { containerPort: 5432 }, }, + lifecycle: { + preStop: { + exec: { + command: ["/bin/sh", "-c", "pg_ctl stop -w -t 60 -m fast"] + } + }, + }, env_: { POSTGRES_DB: cfg.database, POSTGRES_USER: cfg.username, @@ -121,6 +131,7 @@ local kube = import "kube.libsonnet"; std.objectFields(cfg.opts), ), + resources: cfg.resources, volumeMounts_: { data: { mountPath: "/var/lib/postgresql/data" }, },