cloud/bmaas: implement webug

Webug (pronounced: /wɛbʌɡ/, not /wiːbʌɡ/) is a web debug interface for
BMDB, inspired by the great web debug interfaces of old.

It uses the new BMDB reflection API to access most
machine/tag/work/backoff information, plus sqlc queries to access
session information.

Change-Id: If0e65b6fc33ad92baef9c6d98333f90a02efa1b3
Reviewed-on: https://review.monogon.dev/c/monogon/+/1132
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
diff --git a/cloud/shepherd/equinix/manager/server/BUILD.bazel b/cloud/shepherd/equinix/manager/server/BUILD.bazel
index 8593004..a8431fe 100644
--- a/cloud/shepherd/equinix/manager/server/BUILD.bazel
+++ b/cloud/shepherd/equinix/manager/server/BUILD.bazel
@@ -7,6 +7,7 @@
     visibility = ["//visibility:private"],
     deps = [
         "//cloud/bmaas/bmdb",
+        "//cloud/bmaas/bmdb/webug",
         "//cloud/lib/component",
         "//cloud/shepherd/equinix/manager",
         "//cloud/shepherd/equinix/wrapngo",
diff --git a/cloud/shepherd/equinix/manager/server/main.go b/cloud/shepherd/equinix/manager/server/main.go
index 567ebd7..550eea3 100644
--- a/cloud/shepherd/equinix/manager/server/main.go
+++ b/cloud/shepherd/equinix/manager/server/main.go
@@ -10,6 +10,7 @@
 	"k8s.io/klog"
 
 	"source.monogon.dev/cloud/bmaas/bmdb"
+	"source.monogon.dev/cloud/bmaas/bmdb/webug"
 	"source.monogon.dev/cloud/lib/component"
 	"source.monogon.dev/cloud/shepherd/equinix/manager"
 	"source.monogon.dev/cloud/shepherd/equinix/wrapngo"
@@ -24,6 +25,7 @@
 	AgentConfig       manager.AgentConfig
 	ProvisionerConfig manager.ProvisionerConfig
 	InitializerConfig manager.InitializerConfig
+	WebugConfig       webug.Config
 	API               wrapngo.Opts
 }
 
@@ -46,6 +48,7 @@
 	c.AgentConfig.RegisterFlags()
 	c.ProvisionerConfig.RegisterFlags()
 	c.InitializerConfig.RegisterFlags()
+	c.WebugConfig.RegisterFlags()
 	c.API.RegisterFlags()
 }
 
@@ -90,6 +93,7 @@
 	if err != nil {
 		klog.Exitf("Failed to open BMDB connection: %v", err)
 	}
+
 	go func() {
 		err = provisioner.Run(ctx, conn)
 		if err != nil {
@@ -102,6 +106,11 @@
 			klog.Exit(err)
 		}
 	}()
+	go func() {
+		if err := c.WebugConfig.Start(ctx, conn); err != nil && err != ctx.Err() {
+			klog.Exitf("Failed to start webug: %v", err)
+		}
+	}()
 
 	<-ctx.Done()
 }