k0.hswaw.net: pass metallb through Calico

Previously, we had the following setup:

                          .-----------.
                          | .....     |
                        .-----------.-|
                        | dcr01s24  | |
                      .-----------.-| |
                      | dcr01s22  | | |
                  .---|-----------| |-'
    .--------.    |   |---------. | |
    | dcsw01 | <----- | metallb | |-'
    '--------'        |---------' |
                      '-----------'

Ie., each metallb on each node directly talked to dcsw01 over BGP to
announce ExternalIPs to our L3 fabric.

Now, we rejigger the configuration to instead have Calico's BIRD
instances talk BGP to dcsw01, and have metallb talk locally to Calico.

                      .-------------------------.
                      | dcr01s24                |
                      |-------------------------|
    .--------.        |---------.   .---------. |
    | dcsw01 | <----- | Calico  |<--| metallb | |
    '--------'        |---------'   '---------' |
                      '-------------------------'

This makes Calico announce our pod/service networks into our L3 fabric!

Calico and metallb talk to eachother over 127.0.0.1 (they both run with
Host Networking), but that requires one side to flip to pasive mode. We
chose to do that with Calico, by overriding its BIRD config and
special-casing any 127.0.0.1 peer to enable passive mode.

We also override Calico's Other Bird Template (bird_ipam.cfg) to fiddle
with the kernel programming filter (ie. to-kernel-routing-table filter),
where we disable programming unreachable routes. This is because routes
coming from metallb have their next-hop set to 127.0.0.1, which makes
bird mark them as unreachable. Unreachable routes in the kernel will
break local access to ExternalIPs, eg. register access from containerd.

All routes pass through without route reflectors and a full mesh as we
use eBGP over private ASNs in our fabric.

We also have to make Calico aware of metallb pools - otherwise, routes
announced by metallb end up being filtered by Calico.

This is all mildly hacky. Here's hoping that Calico will be able to some
day gain metallb-like functionality, ie. IPAM for
externalIPs/LoadBalancers/...

There seems to be however one problem with this change (but I'm not
fixing it yet as it's not critical): metallb would previously only
announce IPs from nodes that were serving that service. Now, however,
the Calico internal mesh makes those appear from every node. This can
probably be fixed by disabling local meshing, enabling route reflection
on dcsw01 (to recreate the mesh routing through dcsw01). Or, maybe by
some more hacking of the Calico BIRD config :/.

Change-Id: I3df1f6ae7fa1911dd53956ced3b073581ef0e836
diff --git a/cluster/kube/lib/calico.libsonnet b/cluster/kube/lib/calico.libsonnet
index b5c83a7..1e2d503 100644
--- a/cluster/kube/lib/calico.libsonnet
+++ b/cluster/kube/lib/calico.libsonnet
@@ -230,6 +230,17 @@
             },
         },
 
+        # ConfigMap that holds overriden bird.cfg.template and bird_ipam.cfg.template.
+        calicoMetallbBird: kube.ConfigMap("calico-metallb-bird") {
+            metadata+: {
+                namespace: cfg.namespace,
+            },
+            data: {
+                "bird.cfg.template": (importstr "calico-bird.cfg.template"),
+                "bird_ipam.cfg.template": (importstr "calico-bird-ipam.cfg.template"),
+            },
+        },
+
         nodeDaemon: kube.DaemonSet("calico-node") {
             metadata+: {
                 namespace: cfg.namespace,
@@ -258,6 +269,7 @@
                             xtables_lock: kube.HostPathVolume("/run/xtables.lock"),
                             var_run_calico: kube.HostPathVolume("/var/run/calico"),
                             var_lib_calico: kube.HostPathVolume("/var/lib/calico"),
+                            bird_cfg_template: kube.ConfigMapVolume(env.calicoMetallbBird),
                         },
                         initContainers_: {
                             installCNI: kube.Container("install-cni") {
@@ -335,6 +347,16 @@
                                     var_lib_calico: { mountPath: "/var/lib/calico" },
                                     secrets: { mountPath: env.cm.secretPrefix },
                                 },
+                                volumeMounts+: [
+                                    { name: "bird-cfg-template",
+                                      mountPath: "/etc/calico/confd/templates/bird.cfg.template",
+                                      subPath: "bird.cfg.template"
+                                    },
+                                    { name: "bird-cfg-template",
+                                      mountPath: "/etc/calico/confd/templates/bird_ipam.cfg.template",
+                                      subPath: "bird_ipam.cfg.template"
+                                    },
+                                ],
                             },
                         },
                     },