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>
diff --git a/kube/postgres.libsonnet b/kube/postgres.libsonnet
index a3c6415..492a3ba 100644
--- a/kube/postgres.libsonnet
+++ b/kube/postgres.libsonnet
@@ -7,11 +7,11 @@
     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 @@
         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 @@
         # 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 @@
         storage:: cfg.storageSize,
         storageClass:: cfg.storageClassName,
     },
+
     deployment: kube.Deployment(postgres.makeName("postgres")) {
         metadata+: postgres.metadata,
         spec+: {
@@ -119,6 +124,7 @@
                             volumeMounts_: {
                                 data: { mountPath: "/var/lib/postgresql/data" },
                             },
+                            resources: cfg.resources,
                         },
                     },
 
@@ -188,12 +194,6 @@
     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 @@
                 }
             },
             target:: postgres.bouncer.deployment,
-            spec+: {
-                ports: [
-                    { name: "client", port: 5432, targetPort: 5432, protocol: "TCP" },
-                ],
-                type: "ClusterIP",
-            },
         },
     } else {},
 }