kube/postgres: support resources specification, implement graceful shutdown

Change-Id: Iaecf827a43422bd4c59b06e771273624c764f6b3
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1856
Reviewed-by: informatic <informatic@hackerspace.pl>
changes/56/1856/3
informatic 2023-12-29 22:47:08 +01:00 committed by informatic
parent 63fb77f6e3
commit eea0e5efdd
1 changed files with 11 additions and 0 deletions

View File

@ -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" },
},