4
0
Fork 2
mirror of https://gerrit.hackerspace.pl/hscloud synced 2024-12-03 04:50:21 +00:00

kube/postgres: force explicit versioning, storage class, clean up

Postgres version should be stated explicitly by the user. We can't auto-upgrade all apps, so we'd never change the 10.4 default. By forcing version to be explicit, we encourage users to pick the latest version when they first deploy, or to upgrade to latest from the old 10.4.

Also, non-existent storage class default is removed in favor of explicitly asking for storageClassName.

Change-Id: I715bcde6a66ca97be757abcea93c14139d61ed5a
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1791
Reviewed-by: informatic <informatic@hackerspace.pl>
This commit is contained in:
radex 2023-11-16 22:55:45 +01:00
parent 5a12c4048f
commit ad91bd2893
7 changed files with 17 additions and 18 deletions

View file

@ -249,6 +249,7 @@ local coturn = import "./coturn.libsonnet";
local psql = self,
cfg+: {
appName: "synapse",
version: "10.4",
database: "synapse",
username: "synapse",
prefix: "waw3-",

View file

@ -85,6 +85,7 @@ local postgres = import "../../../kube/postgres.libsonnet";
postgres3: ns.Contain(postgres) {
cfg+: {
appName: "synapse",
version: "10.4",
database: "synapse",
username: "synapse",
prefix: "waw3-",

View file

@ -53,6 +53,7 @@ local postgres = import "../../kube/postgres.libsonnet";
postgres: ns.Contain(postgres) {
cfg+: {
version: "10.4",
appName: "redmine",
database: "redmine",
username: "redmine",

View file

@ -212,6 +212,7 @@ local redis = import "../../kube/redis.libsonnet";
cfg+: {
namespace: pretalx.metadata.namespace,
appName: pretalx.makeName("-pretalx"),
version: "10.4",
storageClassName: cfg.storageClassName,
prefix: pretalx.makeName("-postgres") + "-",
database: "pretalx",

View file

@ -58,7 +58,7 @@ local redis = import "../../kube/redis.libsonnet";
storageClassName: cfg.storageClassName,
storageSize: "20Gi",
image: "postgres:15.4-bookworm",
version: "15.4-bookworm",
pgupgrade+: {
enable: true,
from: "10",

View file

@ -7,11 +7,11 @@ local kube = import "kube.libsonnet";
local cfg = postgres.cfg,
cfg:: {
namespace: error "namespace must be set",
appName: error "app name must be set",
storageClassName: "waw-hdd-paranoid-2",
appName: error "appName must be set",
prefix: "", # if set, should be 'foo-'
version: "10.4", # valid version tag for https://hub.docker.com/_/postgres/
# valid version tag for https://hub.docker.com/_/postgres/
version: error "version must be set (to a valid docker hub tag, e.g. 10.4)",
image: "postgres:" + self.version,
database: error "database must be set",
@ -20,6 +20,10 @@ local kube = import "kube.libsonnet";
password: error "password must be set",
storageSize: "30Gi",
storageClassName: error "storageClassName must be set",
# Override this to set postgres resource requests and limits.
resources: {},
# This option can be used to customize initial database creation. For
# available options see: https://www.postgresql.org/docs/9.5/app-initdb.html
@ -50,7 +54,7 @@ local kube = import "kube.libsonnet";
# needs to be adjusted accordingly.
pgupgrade: {
enable: false,
from: "10",
from: error 'pgupgrade.from must be set to previous major version, e.g. 10',
# Extract target version from image name, supported:
# postgres:1.2-suffix, postgres:1-suffix, postgres:1.2, postgres:1
to: std.native('regexSubst')("^[^:]+:([^.]+).*$", cfg.image, "${1}"),
@ -87,6 +91,7 @@ local kube = import "kube.libsonnet";
storage:: cfg.storageSize,
storageClass:: cfg.storageClassName,
},
deployment: kube.Deployment(postgres.makeName("postgres")) {
metadata+: postgres.metadata,
spec+: {
@ -119,6 +124,7 @@ local kube = import "kube.libsonnet";
volumeMounts_: {
data: { mountPath: "/var/lib/postgresql/data" },
},
resources: cfg.resources,
},
},
@ -188,12 +194,6 @@ local kube = import "kube.libsonnet";
svc: kube.Service(postgres.makeName("postgres")) {
metadata+: postgres.metadata,
target:: postgres.deployment,
spec+: {
ports: [
{ name: "client", port: 5432, targetPort: 5432, protocol: "TCP" },
],
type: "ClusterIP",
},
},
bouncer: if cfg.bouncer.enable then {
@ -231,12 +231,6 @@ local kube = import "kube.libsonnet";
}
},
target:: postgres.bouncer.deployment,
spec+: {
ports: [
{ name: "client", port: 5432, targetPort: 5432, protocol: "TCP" },
],
type: "ClusterIP",
},
},
} else {},
}

View file

@ -41,6 +41,7 @@ local postgres = import '../../kube/postgres.libsonnet';
postgres: ns.Contain(postgres) {
cfg+: {
appName: 'ferretdb-postgres',
version: "10.4",
database: 'ferretdb',
username: 'username',
password: { secretKeyRef: { name: top.cfg.name, key: 'pg_password' } },
@ -59,4 +60,4 @@ local postgres = import '../../kube/postgres.libsonnet';
externalTrafficPolicy: 'Local',
},
},
}
}