treewide: switch to gomod and bump everything

This switches version resolution from fietsje to gomod and updates
all Go dependencies. It also bumps rules_go (required by gVisor) and
switches the Gazelle naming convention from go_default_xxx to the
standard Bazel convention of the default target having the package
name.

Since Kubernetes dropped upstream Bazel support and doesn't check in
all generated files I manually pregenerated the OpenAPI spec. This
should be fixed, but because of the already-huge scope of this CL
and the rebase complexity this is not in here.

Change-Id: Iec8ea613d06946882426c2f9fad5bda7e8aaf833
Reviewed-on: https://review.monogon.dev/c/monogon/+/639
Reviewed-by: Sergiusz Bazanski <serge@monogon.tech>
Reviewed-by: Leopold Schabel <leo@nexantic.com>
diff --git a/metropolis/cli/dbg/BUILD.bazel b/metropolis/cli/dbg/BUILD.bazel
index 6d2769f..4eed080 100644
--- a/metropolis/cli/dbg/BUILD.bazel
+++ b/metropolis/cli/dbg/BUILD.bazel
@@ -1,24 +1,24 @@
 load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
 
 go_library(
-    name = "go_default_library",
+    name = "dbg_lib",
     srcs = ["main.go"],
     importpath = "source.monogon.dev/metropolis/cli/dbg",
     visibility = ["//visibility:private"],
     deps = [
-        "//metropolis/pkg/logtree:go_default_library",
-        "//metropolis/proto/api:go_default_library",
-        "@com_github_spf13_pflag//:go_default_library",
-        "@io_k8s_component_base//cli/flag:go_default_library",
-        "@io_k8s_kubectl//pkg/cmd/plugin:go_default_library",
-        "@io_k8s_kubectl//pkg/util/logs:go_default_library",
-        "@io_k8s_kubernetes//pkg/kubectl/cmd:go_default_library",
+        "//metropolis/pkg/logtree",
+        "//metropolis/proto/api",
+        "@io_k8s_cli_runtime//pkg/genericclioptions",
+        "@io_k8s_component_base//cli",
+        "@io_k8s_kubectl//pkg/cmd",
+        "@io_k8s_kubectl//pkg/cmd/plugin",
+        "@io_k8s_kubectl//pkg/cmd/util",
         "@org_golang_google_grpc//:go_default_library",
     ],
 )
 
 go_binary(
     name = "dbg",
-    embed = [":go_default_library"],
+    embed = [":dbg_lib"],
     visibility = ["//visibility:private"],
 )
diff --git a/metropolis/cli/dbg/main.go b/metropolis/cli/dbg/main.go
index 99aff6c..c2c0cb9 100644
--- a/metropolis/cli/dbg/main.go
+++ b/metropolis/cli/dbg/main.go
@@ -26,12 +26,12 @@
 	"strings"
 	"time"
 
-	"github.com/spf13/pflag"
 	"google.golang.org/grpc"
-	cliflag "k8s.io/component-base/cli/flag"
+	"k8s.io/cli-runtime/pkg/genericclioptions"
+	"k8s.io/component-base/cli"
+	"k8s.io/kubectl/pkg/cmd"
 	"k8s.io/kubectl/pkg/cmd/plugin"
-	"k8s.io/kubectl/pkg/util/logs"
-	"k8s.io/kubernetes/pkg/kubectl/cmd"
+	"k8s.io/kubectl/pkg/cmd/util"
 
 	"source.monogon.dev/metropolis/pkg/logtree"
 	apb "source.monogon.dev/metropolis/proto/api"
@@ -168,14 +168,15 @@
 		//   https://github.com/kubernetes/kubernetes/blob/master/cmd/kubectl/kubectl.go
 		os.Setenv("KUBECONFIG", kubeconfigFile.Name())
 		rand.Seed(time.Now().UnixNano())
-		pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
-		pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
-		logs.InitLogs()
-		defer logs.FlushLogs()
-		command := cmd.NewDefaultKubectlCommandWithArgs(cmd.NewDefaultPluginHandler(plugin.ValidPluginFilenamePrefixes), os.Args[2:], os.Stdin, os.Stdout, os.Stderr)
-		command.SetArgs(os.Args[2:])
-		if err := command.Execute(); err != nil {
-			os.Exit(1)
+		command := cmd.NewDefaultKubectlCommandWithArgs(cmd.KubectlOptions{
+			PluginHandler: cmd.NewDefaultPluginHandler(plugin.ValidPluginFilenamePrefixes),
+			Arguments:     os.Args[2:],
+			ConfigFlags:   genericclioptions.NewConfigFlags(true).WithDiscoveryBurst(300).WithDiscoveryQPS(50.0),
+			IOStreams:     genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr},
+		})
+		if err := cli.RunNoErrOutput(command); err != nil {
+			// Pretty-print the error and exit with an error.
+			util.CheckErr(err)
 		}
 	case "trace":
 		traceCmd.Parse(os.Args[2:])
diff --git a/metropolis/cli/metroctl/BUILD.bazel b/metropolis/cli/metroctl/BUILD.bazel
index 8d4fee4..8175ca4 100644
--- a/metropolis/cli/metroctl/BUILD.bazel
+++ b/metropolis/cli/metroctl/BUILD.bazel
@@ -1,7 +1,7 @@
 load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
 
 go_library(
-    name = "go_default_library",
+    name = "metroctl_lib",
     srcs = [
         "credentials.go",
         "install.go",
@@ -11,27 +11,27 @@
     ],
     data = [
         "//metropolis/installer:kernel",
-        "//metropolis/node",
+        "//metropolis/node:bundle",
     ],
     importpath = "source.monogon.dev/metropolis/cli/metroctl",
     visibility = ["//visibility:private"],
     deps = [
-        "//metropolis/cli/metroctl/core:go_default_library",
-        "//metropolis/cli/pkg/context:go_default_library",
-        "//metropolis/cli/pkg/datafile:go_default_library",
-        "//metropolis/node:go_default_library",
-        "//metropolis/node/core/rpc:go_default_library",
-        "//metropolis/proto/api:go_default_library",
-        "@com_github_adrg_xdg//:go_default_library",
-        "@com_github_spf13_cobra//:go_default_library",
-        "@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
-        "@io_k8s_client_go//pkg/apis/clientauthentication/v1beta1:go_default_library",
+        "//metropolis/cli/metroctl/core",
+        "//metropolis/cli/pkg/context",
+        "//metropolis/cli/pkg/datafile",
+        "//metropolis/node",
+        "//metropolis/node/core/rpc",
+        "//metropolis/proto/api",
+        "@com_github_adrg_xdg//:xdg",
+        "@com_github_spf13_cobra//:cobra",
+        "@io_k8s_apimachinery//pkg/apis/meta/v1:meta",
+        "@io_k8s_client_go//pkg/apis/clientauthentication/v1beta1",
         "@org_golang_google_grpc//:go_default_library",
     ],
 )
 
 go_binary(
     name = "metroctl",
-    embed = [":go_default_library"],
+    embed = [":metroctl_lib"],
     visibility = ["//visibility:public"],
 )
diff --git a/metropolis/cli/metroctl/core/BUILD.bazel b/metropolis/cli/metroctl/core/BUILD.bazel
index 3c59706..cdde06b 100644
--- a/metropolis/cli/metroctl/core/BUILD.bazel
+++ b/metropolis/cli/metroctl/core/BUILD.bazel
@@ -1,7 +1,7 @@
 load("@io_bazel_rules_go//go:def.bzl", "go_library")
 
 go_library(
-    name = "go_default_library",
+    name = "core",
     srcs = [
         "core.go",
         "install.go",
@@ -9,11 +9,11 @@
     importpath = "source.monogon.dev/metropolis/cli/metroctl/core",
     visibility = ["//visibility:public"],
     deps = [
-        "//metropolis/proto/api:go_default_library",
-        "@com_github_diskfs_go_diskfs//:go_default_library",
-        "@com_github_diskfs_go_diskfs//disk:go_default_library",
-        "@com_github_diskfs_go_diskfs//filesystem:go_default_library",
-        "@com_github_diskfs_go_diskfs//partition/gpt:go_default_library",
-        "@org_golang_google_protobuf//proto:go_default_library",
+        "//metropolis/proto/api",
+        "@com_github_diskfs_go_diskfs//:go-diskfs",
+        "@com_github_diskfs_go_diskfs//disk",
+        "@com_github_diskfs_go_diskfs//filesystem",
+        "@com_github_diskfs_go_diskfs//partition/gpt",
+        "@org_golang_google_protobuf//proto",
     ],
 )
diff --git a/metropolis/cli/pkg/context/BUILD.bazel b/metropolis/cli/pkg/context/BUILD.bazel
index b03a35d..2418a82 100644
--- a/metropolis/cli/pkg/context/BUILD.bazel
+++ b/metropolis/cli/pkg/context/BUILD.bazel
@@ -1,7 +1,7 @@
 load("@io_bazel_rules_go//go:def.bzl", "go_library")
 
 go_library(
-    name = "go_default_library",
+    name = "context",
     srcs = ["context.go"],
     importpath = "source.monogon.dev/metropolis/cli/pkg/context",
     visibility = ["//visibility:public"],
diff --git a/metropolis/cli/pkg/datafile/BUILD.bazel b/metropolis/cli/pkg/datafile/BUILD.bazel
index 8628d9a..8c47aeb 100644
--- a/metropolis/cli/pkg/datafile/BUILD.bazel
+++ b/metropolis/cli/pkg/datafile/BUILD.bazel
@@ -1,7 +1,7 @@
 load("@io_bazel_rules_go//go:def.bzl", "go_library")
 
 go_library(
-    name = "go_default_library",
+    name = "datafile",
     srcs = ["datafile.go"],
     importpath = "source.monogon.dev/metropolis/cli/pkg/datafile",
     visibility = ["//visibility:public"],