kube: standardize convention for passing postgres options

Declare options when creating postgres {}, then pass env by taking from postgres's cfg and svc. This is both to reduce chance of making a mistake, and to improve copy-pasteability of jsonnets

Change-Id: Ief16a6825af64795f3b10e1e617b96c3d1c2a578
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1807
Reviewed-by: q3k <q3k@hackerspace.pl>
master
radex 2023-11-24 12:37:37 +01:00
parent 1439fde1ba
commit 37991744d8
4 changed files with 20 additions and 28 deletions

View File

@ -11,10 +11,6 @@ local postgres = import '../../kube/postgres_v.libsonnet';
domain: 'inventory.hackerspace.pl',
image: 'registry.k0.hswaw.net/palid/spejstore:1694280421',
db: {
name: 'inventory',
username: 'inventory',
},
oauthClientId: '82fffb65-0bbd-4d18-becd-0ce0b31373cf',
storageClassName: 'waw-hdd-redundant-3',
@ -43,11 +39,11 @@ local postgres = import '../../kube/postgres_v.libsonnet';
},
env_: {
SPEJSTORE_ENV: 'prod',
SPEJSTORE_DB_NAME: cfg.db.name,
SPEJSTORE_DB_USER: cfg.db.username,
SPEJSTORE_DB_PASSWORD: top.secretRefs.postgres,
SPEJSTORE_DB_HOST: top.psql.svc.host,
SPEJSTORE_DB_PORT: top.psql.svc.port,
SPEJSTORE_DB_NAME: top.postgres.cfg.database,
SPEJSTORE_DB_USER: top.postgres.cfg.username,
SPEJSTORE_DB_PASSWORD: top.postgres.cfg.password,
SPEJSTORE_DB_HOST: top.postgres.svc.host,
SPEJSTORE_DB_PORT: top.postgres.svc.port,
SPEJSTORE_ALLOWED_HOSTS: cfg.domain,
SPEJSTORE_CLIENT_ID: cfg.oauthClientId,
SPEJSTORE_SECRET: top.secretRefs.oauth,
@ -70,15 +66,15 @@ local postgres = import '../../kube/postgres_v.libsonnet';
storageClass:: cfg.storageClassName,
},
psql: postgres {
postgres: postgres {
cfg+: {
namespace: cfg.namespace,
appName: cfg.name,
storageClassName: cfg.storageClassName,
version: '15.4',
database: cfg.db.name,
username: cfg.db.username,
database: 'inventory',
username: 'inventory',
password: top.secretRefs.postgres,
},
bouncer: {},

View File

@ -68,10 +68,10 @@ local redis = import "../../../kube/redis.libsonnet";
REDIS_URL: "redis://:$(REDIS_PASS)@%s" % [top.redis.svc.host_colon_port],
DB_HOST: top.postgres.svc.host,
DB_USER: "mastodon",
DB_NAME: "mastodon",
DB_PASS: kube.SecretKeyRef(top.config, "postgres-pass"),
DB_PORT: "5432",
DB_PORT: top.postgres.svc.port,
DB_USER: top.postgres.cfg.username,
DB_NAME: top.postgres.cfg.database,
DB_PASS: top.postgres.cfg.password,
ES_ENABLED: "false",

View File

@ -11,11 +11,7 @@ local postgres = import "../../kube/postgres.libsonnet";
domain: error "domain must be set",
storageClassName: "waw-hdd-redundant-3",
database: {
host: "postgres",
name: "redmine",
username: "redmine",
password: { secretKeyRef: { name: "redmine", key: "postgres_password" } },
port: 5432,
},
b: {
@ -59,8 +55,8 @@ local postgres = import "../../kube/postgres.libsonnet";
cfg+: {
namespace: cfg.namespace,
appName: "redmine",
database: cfg.database.name,
username: cfg.database.username,
database: "redmine",
username: "redmine",
password: cfg.database.password,
storageClassName: cfg.storageClassName,
},
@ -88,11 +84,11 @@ local postgres = import "../../kube/postgres.libsonnet";
http: { containerPort: 3000 },
},
env_: {
REDMINE_DB_POSTGRES: cfg.database.host,
REDMINE_DB_PORT: cfg.database.port,
REDMINE_DB_USERNAME: cfg.database.username,
REDMINE_DB_PASSWORD: cfg.database.password,
REDMINE_DB_DATABASE: cfg.database.name,
REDMINE_DB_POSTGRES: top.postgres.svc.host,
REDMINE_DB_PORT: top.postgres.svc.port,
REDMINE_DB_DATABASE: top.postgres.cfg.database,
REDMINE_DB_USERNAME: top.postgres.cfg.username,
REDMINE_DB_PASSWORD: top.postgres.cfg.password,
REDMINE_SECRET_KEY_BASE: { secretKeyRef: { name: "redmine", key: "secret_key" } },

View File

@ -144,7 +144,7 @@ local redis = import "../../kube/redis.libsonnet";
A_REDIS_PASSWORD: top.redis.cfg.password,
PAPERLESS_REDIS: "redis://:$(A_REDIS_PASSWORD)@redis:6379",
PAPERLESS_DBHOST: "postgres",
PAPERLESS_DBHOST: top.postgres.svc.host,
PAPERLESS_DBNAME: top.postgres.cfg.database,
PAPERLESS_DBUSER: top.postgres.cfg.username,
PAPERLESS_DBPASS: top.postgres.cfg.password,