app/matrix: enable wal=logical for postgres, add tmp mount

This is quite hacky, but we intend to remove that postgres soon anyway.
The changes to synapse's resource limits are to reflect current state of
prod.

Change-Id: Ic7beaa3e7ee378c0e10ba24f9a5a3aee67c2ccf2
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1468
Reviewed-by: q3k <q3k@hackerspace.pl>
diff --git a/app/matrix/lib/matrix-ng.libsonnet b/app/matrix/lib/matrix-ng.libsonnet
index ac895bc..91c92d2 100644
--- a/app/matrix/lib/matrix-ng.libsonnet
+++ b/app/matrix/lib/matrix-ng.libsonnet
@@ -242,6 +242,7 @@
             opts: {
                 max_connections: "300",
                 shared_buffers: "80MB",
+                wal_level: "logical",
             },
         },
     },
diff --git a/app/matrix/matrix.hackerspace.pl.jsonnet b/app/matrix/matrix.hackerspace.pl.jsonnet
index 4199e0e..931901a 100644
--- a/app/matrix/matrix.hackerspace.pl.jsonnet
+++ b/app/matrix/matrix.hackerspace.pl.jsonnet
@@ -1,6 +1,7 @@
 local matrix = import "lib/matrix-ng.libsonnet";
 local irc = import "lib/appservice-irc.libsonnet";
 local telegram = import "lib/appservice-telegram.libsonnet";
+local kube = import "../../kube/kube.libsonnet";
 
 matrix {
     local app = self,
@@ -77,12 +78,24 @@
                 },
             },
         },
+        // local changes
+        main+: {
+            deployment+: {
+                cfg+: {
+                    resources+: {
+                        limits+: { cpu: "2", memory: "8Gi" },
+                        requests+: { cpu: "2", memory: "8Gi" },
+                    },
+                },
+            },
+        },
     },
 
     // Bump up storage to 200Gi from default 100Gi, use different name.  The
     // new name corresponds to a manually migrated and sized-up PVC that
     // contains data from the original waw3-postgres PVC.
     postgres3+: {
+        local psql = self,
         volumeClaim+: {
             metadata+: {
                 name: "waw3-postgres-2",
@@ -95,6 +108,36 @@
                 },
             },
         },
+        tempVC: kube.PersistentVolumeClaim(psql.makeName("tempvc")) {
+            metadata+: psql.metadata,
+            spec+: {
+                storageClassName: psql.cfg.storageClassName,
+                accessModes: [ "ReadWriteOnce" ],
+                resources: {
+                    requests: {
+                        storage: "200Gi",
+                    },
+                },
+            },
+        },
+        deployment+: {
+            spec+: {
+                template+: {
+                    spec+: {
+                        volumes_+: {
+                            temp: kube.PersistentVolumeClaimVolume(psql.tempVC),
+                        },
+                        containers_+: {
+                            postgres+: {
+                                volumeMounts_+: {
+                                    temp: { mountPath: "/mnt/tmp/" },
+                                },
+                            },
+                        },
+                    },
+                },
+            },
+        },
     },
 
     appservices: {