Add Kubernetes Worker and infrastructure

Adds Kubernetes Kubelet with patches for syscall-based mounting and
syscall-based (and much faster) metrics. fsquota patches have been
deferred to a further revision (for robust emptyDir capacity isolation).

Changes encoding of the node ID to hex since Base64-URL is not supported
as a character set for K8s names. Also adds `/etc/machine-id` and
`/etc/os-release` since Kubernetes wants them. `os-release` is generated
by stamping, `machine-id` is the hex-encoded node ID derived from the
public key.

Also includes a primitive reconciler which automatically ensures a set of
built-in Kubernetes objects are always present. Currently this includes
a PSP and some basic RBAC policies that are elementary to proper cluster
operations.

Adds an additional gRPC service (NodeDebugService) to cleanly
communicate with external debug and test tooling. It supports reading
from logbuffers for all externally-run components, checking conditions
(for replacing log matching in testing and debugging) and getting
debug credentials for the Kubernetes cluster.

A small utility (dbg) is provided that interfaces with NodeDebugService
and provides access to its functions from the CLI. It also incorporates
a kubectl wrapper which directly grabs credentials from the Debug API
and passes them to kubectl
(e.g. `bazel run //core/cmd/dbg -- kubectl describe node`).

Test Plan:
Manually tested.
Kubernetes:
`bazel run //core/cmd/dbg -- kubectl create -f test.yml`

Checked that pods run, logs are accessible and exec works.

Reading buffers:
`bazel run //core/cmd/dbg -- logs containerd`

Outputs containerd logs in the right order.

Automated testing is in the works, but has been deferred to a future
revision because this one is already too big again.

X-Origin-Diff: phab/D525
GitOrigin-RevId: 0fbfa0c433de405526c7f09ef10c466896331328
diff --git a/third_party/go/patches/k8s-use-native.patch b/third_party/go/patches/k8s-use-native.patch
new file mode 100644
index 0000000..61001da
--- /dev/null
+++ b/third_party/go/patches/k8s-use-native.patch
@@ -0,0 +1,153 @@
+Copyright 2020 The Monogon Project Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+
+From ee4a7df588550ee5cbc3b8419e1ce185a8abb302 Mon Sep 17 00:00:00 2001
+From: Lorenz Brun <lorenz@brun.one>
+Date: Tue, 17 Mar 2020 22:07:24 +0100
+Subject: [PATCH 3/3] Use StatFS and Native volume metrics instead of du
+
+---
+ pkg/kubelet/stats/log_metrics_provider.go | 2 +-
+ pkg/volume/configmap/configmap.go         | 4 ++--
+ pkg/volume/downwardapi/downwardapi.go     | 4 ++--
+ pkg/volume/emptydir/empty_dir.go          | 4 ++--
+ pkg/volume/projected/projected.go         | 4 ++--
+ pkg/volume/secret/secret.go               | 4 ++--
+ 6 files changed, 11 insertions(+), 11 deletions(-)
+
+diff --git a/pkg/kubelet/stats/log_metrics_provider.go b/pkg/kubelet/stats/log_metrics_provider.go
+index 4a53eef74a3..ff87fec5ec3 100644
+--- a/pkg/kubelet/stats/log_metrics_provider.go
++++ b/pkg/kubelet/stats/log_metrics_provider.go
+@@ -33,5 +33,5 @@ func NewLogMetricsService() LogMetricsService {
+ }
+ 
+ func (l logMetrics) createLogMetricsProvider(path string) volume.MetricsProvider {
+-	return volume.NewMetricsDu(path)
++	return volume.NewMetricsNative(path)
+ }
+diff --git a/pkg/volume/configmap/configmap.go b/pkg/volume/configmap/configmap.go
+index 0e74dd0a1d8..430d739aab7 100644
+--- a/pkg/volume/configmap/configmap.go
++++ b/pkg/volume/configmap/configmap.go
+@@ -97,7 +97,7 @@ func (plugin *configMapPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, opts v
+ 			pod.UID,
+ 			plugin,
+ 			plugin.host.GetMounter(plugin.GetPluginName()),
+-			volume.NewCachedMetrics(volume.NewMetricsDu(getPath(pod.UID, spec.Name(), plugin.host))),
++			volume.NewCachedMetrics(volume.NewMetricsNative(getPath(pod.UID, spec.Name(), plugin.host))),
+ 		},
+ 		source:       *spec.Volume.ConfigMap,
+ 		pod:          *pod,
+@@ -113,7 +113,7 @@ func (plugin *configMapPlugin) NewUnmounter(volName string, podUID types.UID) (v
+ 			podUID,
+ 			plugin,
+ 			plugin.host.GetMounter(plugin.GetPluginName()),
+-			volume.NewCachedMetrics(volume.NewMetricsDu(getPath(podUID, volName, plugin.host))),
++			volume.NewCachedMetrics(volume.NewMetricsNative(getPath(podUID, volName, plugin.host))),
+ 		},
+ 	}, nil
+ }
+diff --git a/pkg/volume/downwardapi/downwardapi.go b/pkg/volume/downwardapi/downwardapi.go
+index a1779c0dac9..f0a0f99b318 100644
+--- a/pkg/volume/downwardapi/downwardapi.go
++++ b/pkg/volume/downwardapi/downwardapi.go
+@@ -99,7 +99,7 @@ func (plugin *downwardAPIPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, opts
+ 		pod:             pod,
+ 		podUID:          pod.UID,
+ 		plugin:          plugin,
+-		MetricsProvider: volume.NewCachedMetrics(volume.NewMetricsDu(getPath(pod.UID, spec.Name(), plugin.host))),
++		MetricsProvider: volume.NewCachedMetrics(volume.NewMetricsStatFS(getPath(pod.UID, spec.Name(), plugin.host))),
+ 	}
+ 	return &downwardAPIVolumeMounter{
+ 		downwardAPIVolume: v,
+@@ -114,7 +114,7 @@ func (plugin *downwardAPIPlugin) NewUnmounter(volName string, podUID types.UID)
+ 			volName:         volName,
+ 			podUID:          podUID,
+ 			plugin:          plugin,
+-			MetricsProvider: volume.NewCachedMetrics(volume.NewMetricsDu(getPath(podUID, volName, plugin.host))),
++			MetricsProvider: volume.NewCachedMetrics(volume.NewMetricsStatFS(getPath(podUID, volName, plugin.host))),
+ 		},
+ 	}, nil
+ }
+diff --git a/pkg/volume/emptydir/empty_dir.go b/pkg/volume/emptydir/empty_dir.go
+index 0a25d2b684c..5dc83b90c5b 100644
+--- a/pkg/volume/emptydir/empty_dir.go
++++ b/pkg/volume/emptydir/empty_dir.go
+@@ -121,7 +121,7 @@ func (plugin *emptyDirPlugin) newMounterInternal(spec *volume.Spec, pod *v1.Pod,
+ 		mounter:         mounter,
+ 		mountDetector:   mountDetector,
+ 		plugin:          plugin,
+-		MetricsProvider: volume.NewMetricsDu(getPath(pod.UID, spec.Name(), plugin.host)),
++		MetricsProvider: volume.NewMetricsNative(getPath(pod.UID, spec.Name(), plugin.host)),
+ 	}, nil
+ }
+ 
+@@ -138,7 +138,7 @@ func (plugin *emptyDirPlugin) newUnmounterInternal(volName string, podUID types.
+ 		mounter:         mounter,
+ 		mountDetector:   mountDetector,
+ 		plugin:          plugin,
+-		MetricsProvider: volume.NewMetricsDu(getPath(podUID, volName, plugin.host)),
++		MetricsProvider: volume.NewMetricsNative(getPath(podUID, volName, plugin.host)),
+ 	}
+ 	return ed, nil
+ }
+diff --git a/pkg/volume/projected/projected.go b/pkg/volume/projected/projected.go
+index 0f65a97610c..890f9c1c7bc 100644
+--- a/pkg/volume/projected/projected.go
++++ b/pkg/volume/projected/projected.go
+@@ -114,7 +114,7 @@ func (plugin *projectedPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, opts v
+ 			sources:         spec.Volume.Projected.Sources,
+ 			podUID:          pod.UID,
+ 			plugin:          plugin,
+-			MetricsProvider: volume.NewCachedMetrics(volume.NewMetricsDu(getPath(pod.UID, spec.Name(), plugin.host))),
++			MetricsProvider: volume.NewCachedMetrics(volume.NewMetricsStatFS(getPath(pod.UID, spec.Name(), plugin.host))),
+ 		},
+ 		source: *spec.Volume.Projected,
+ 		pod:    pod,
+@@ -128,7 +128,7 @@ func (plugin *projectedPlugin) NewUnmounter(volName string, podUID types.UID) (v
+ 			volName:         volName,
+ 			podUID:          podUID,
+ 			plugin:          plugin,
+-			MetricsProvider: volume.NewCachedMetrics(volume.NewMetricsDu(getPath(podUID, volName, plugin.host))),
++			MetricsProvider: volume.NewCachedMetrics(volume.NewMetricsStatFS(getPath(podUID, volName, plugin.host))),
+ 		},
+ 	}, nil
+ }
+diff --git a/pkg/volume/secret/secret.go b/pkg/volume/secret/secret.go
+index a195c59ddd8..4c290cb8f24 100644
+--- a/pkg/volume/secret/secret.go
++++ b/pkg/volume/secret/secret.go
+@@ -100,7 +100,7 @@ func (plugin *secretPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, opts volu
+ 			pod.UID,
+ 			plugin,
+ 			plugin.host.GetMounter(plugin.GetPluginName()),
+-			volume.NewCachedMetrics(volume.NewMetricsDu(getPath(pod.UID, spec.Name(), plugin.host))),
++			volume.NewCachedMetrics(volume.NewMetricsStatFS(getPath(pod.UID, spec.Name(), plugin.host))),
+ 		},
+ 		source:    *spec.Volume.Secret,
+ 		pod:       *pod,
+@@ -116,7 +116,7 @@ func (plugin *secretPlugin) NewUnmounter(volName string, podUID types.UID) (volu
+ 			podUID,
+ 			plugin,
+ 			plugin.host.GetMounter(plugin.GetPluginName()),
+-			volume.NewCachedMetrics(volume.NewMetricsDu(getPath(podUID, volName, plugin.host))),
++			volume.NewCachedMetrics(volume.NewMetricsStatFS(getPath(podUID, volName, plugin.host))),
+ 		},
+ 	}, nil
+ }
+-- 
+2.25.1
+