kube/postgres: disable bouncer by default

Change-Id: I29b3be1394545998409cf11cc1702d9976be0f5c
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1790
Reviewed-by: informatic <informatic@hackerspace.pl>
Reviewed-by: q3k <q3k@hackerspace.pl>
diff --git a/kube/postgres.libsonnet b/kube/postgres.libsonnet
index 9ae1ccf..a3c6415 100644
--- a/kube/postgres.libsonnet
+++ b/kube/postgres.libsonnet
@@ -56,6 +56,13 @@
             to: std.native('regexSubst')("^[^:]+:([^.]+).*$", cfg.image, "${1}"),
         },
 
+        # Optional pgbouncer
+        # if enabled, use `postgres.bouncer.host` as database host
+        bouncer: {
+            enable: false,
+            image: "edoburu/pgbouncer:1.11.0",
+        },
+
         # If set to true, resources will be suffixed with postgres version (and will have versioned labels)
         # This exists solely for backwards compatibility with old postgres_v libsonnet
         # and should not be used in new deployments
@@ -189,7 +196,7 @@
         },
     },
 
-    bouncer: {
+    bouncer: if cfg.bouncer.enable then {
         deployment: kube.Deployment(postgres.makeName("bouncer")) {
             metadata+: postgres.metadata {
                 labels+: {
@@ -202,7 +209,7 @@
                     spec+: {
                         containers_: {
                             bouncer: kube.Container(postgres.makeName("bouncer")) {
-                                image: "edoburu/pgbouncer:1.11.0",
+                                image: cfg.bouncer.image,
                                 ports_: {
                                     client: { containerPort: 5432 },
                                 },
@@ -216,6 +223,7 @@
                 },
             },
         },
+        host:: self.svc.host,
         svc: kube.Service(postgres.makeName("bouncer")) {
             metadata+: postgres.metadata {
                 labels+: {
@@ -230,5 +238,5 @@
                 type: "ClusterIP",
             },
         },
-    },
+    } else {},
 }