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/third_party/go/patches/k8s-native-mounter.patch b/third_party/go/patches/k8s-native-mounter.patch
index 2f754b6..a5ced4d 100644
--- a/third_party/go/patches/k8s-native-mounter.patch
+++ b/third_party/go/patches/k8s-native-mounter.patch
@@ -1,69 +1,33 @@
-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 8335005ed1983ca5ac036af15dd04b8717898c35 Mon Sep 17 00:00:00 2001
+From 6c346b4fbfd800af47ffa2ec24456f9f58a1b0f2 Mon Sep 17 00:00:00 2001
From: Lorenz Brun <lorenz@brun.one>
Date: Mon, 16 Mar 2020 22:13:08 +0100
-Subject: [PATCH 1/3] Provide native mounter implementation for Linux
+Subject: [PATCH 1/7] Provide native mounter implementation for Linux
---
- BUILD.bazel | 2 +
- mount/mount_linux.go | 141 ++++++++++++++++++++++-
- 2 files changed, 139 insertions(+), 4 deletions(-)
+ mount_linux.go | 148 +++++++++++++++++-
+ 1 file changed, 144 insertions(+), 4 deletions(-)
-diff --git a/mount/BUILD b/mount/BUILD.bazel
-index bef3ec2cf55..6f997103dac 100644
---- a/mount/BUILD.bazel
-+++ b/mount/BUILD.bazel
-@@ -21,6 +21,7 @@ go_library(
- "//exec:go_default_library",
- ] + select({
- "@io_bazel_rules_go//go/platform:android": [
-+ "@org_golang_x_sys//unix:go_default_library",
- "//io:go_default_library",
- ],
- "@io_bazel_rules_go//go/platform:darwin": [
-@@ -36,6 +37,7 @@ go_library(
- "//io:go_default_library",
- ],
- "@io_bazel_rules_go//go/platform:linux": [
-+ "@org_golang_x_sys//unix:go_default_library",
- "//io:go_default_library",
- ],
- "@io_bazel_rules_go//go/platform:nacl": [
-diff --git a/mount/mount_linux.go b/mount/mount_linux.go
-index 41f69efe3f0..01182684653 100644
---- a/mount/mount_linux.go
-+++ b/mount/mount_linux.go
-@@ -20,6 +20,7 @@ package mount
-
+diff --git a/mount_linux.go b/mount_linux.go
+index aaa592161d4..517bf0b2541 100644
+--- a/mount_linux.go
++++ b/mount_linux.go
+@@ -22,6 +22,7 @@ package mount
import (
+ "context"
"fmt"
+ "io/ioutil"
"os"
"os/exec"
"path/filepath"
-@@ -27,6 +28,7 @@ import (
- "strings"
+@@ -30,6 +31,7 @@ import (
"syscall"
+ "time"
+ "golang.org/x/sys/unix"
"k8s.io/klog/v2"
utilexec "k8s.io/utils/exec"
utilio "k8s.io/utils/io"
-@@ -49,8 +51,10 @@ const (
+@@ -54,8 +56,10 @@ const (
// for the linux platform. This implementation assumes that the
// kubelet is running in the host's root mount namespace.
type Mounter struct {
@@ -75,8 +39,8 @@
+ nativeSupportedFstypes map[string]struct{}
}
- // New returns a mount.Interface for the current system.
-@@ -58,8 +62,10 @@ type Mounter struct {
+ var _ MounterForceUnmounter = &Mounter{}
+@@ -65,11 +69,36 @@ var _ MounterForceUnmounter = &Mounter{}
// mounterPath allows using an alternative to `/bin/mount` for mounting.
func New(mounterPath string) Interface {
return &Mounter{
@@ -89,38 +53,55 @@
}
}
-@@ -78,6 +84,29 @@ func (mounter *Mounter) Mount(source string, target string, fstype string, optio
++func (mounter *Mounter) mountNative(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
++ flags, pflags, fsoptions := parseMountOptions(options)
++ if len(pflags) > 0 {
++ return fmt.Errorf("the native mounter is active and does not support mount propagation at the moment")
++ }
++
++ if !mounter.nativeSupportsFstype(fstype) && flags&unix.MS_BIND == 0 {
++ return fmt.Errorf("the native mounter is active and cannot mount filesystems of type \"%v\"", fstype)
++ }
++
++ if flags&unix.MS_BIND != 0 && flags & ^uintptr(unix.MS_BIND) != 0 {
++ if err := unix.Mount(source, target, "", unix.MS_BIND, ""); err != nil {
++ return fmt.Errorf("bind pre-mount failed: %w", err)
++ }
++ flags |= unix.MS_REMOUNT
++ }
++
++ if err := unix.Mount(source, target, fstype, flags, fsoptions); err != nil {
++ return fmt.Errorf("failed to mount filesystem: %w", err)
++ }
++ return nil
++}
++
+ // Mount mounts source to target as fstype with given options. 'source' and 'fstype' must
+ // be an empty string in case it's not required, e.g. for remount, or for auto filesystem
+ // type, where kernel handles fstype for you. The mount 'options' is a list of options,
+@@ -85,6 +114,10 @@ func (mounter *Mounter) Mount(source string, target string, fstype string, optio
// method should be used by callers that pass sensitive material (like
// passwords) as mount options.
func (mounter *Mounter) MountSensitive(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
+ if !mounter.withLinuxUtils {
-+ flags, pflags, fsoptions := parseMountOptions(options)
-+ if len(pflags) > 0 {
-+ return fmt.Errorf("the native mounter is active and does not support mount propagation at the moment")
-+ }
-+
-+ if !mounter.nativeSupportsFstype(fstype) && flags&unix.MS_BIND == 0 {
-+ return fmt.Errorf("the native mounter is active and cannot mount filesystems of type \"%v\"", fstype)
-+ }
-+
-+ if flags&unix.MS_BIND != 0 && flags & ^uintptr(unix.MS_BIND) != 0 {
-+ if err := unix.Mount(source, target, "", unix.MS_BIND, ""); err != nil {
-+ return fmt.Errorf("bind pre-mount failed: %w", err)
-+ }
-+ flags |= unix.MS_REMOUNT
-+ }
-+
-+ if err := unix.Mount(source, target, fstype, flags, fsoptions); err != nil {
-+ return fmt.Errorf("failed to mount filesystem: %w", err)
-+ }
-+ return nil
++ return mounter.mountNative(source, target, fstype, options, sensitiveOptions)
+ }
+
// Path to mounter binary if containerized mounter is needed. Otherwise, it is set to empty.
// All Linux distros are expected to be shipped with a mount utility that a support bind mounts.
mounterPath := ""
-@@ -102,6 +131,80 @@ func (mounter *Mounter) MountSensitive(source string, target string, fstype stri
- return mounter.doMount(mounterPath, defaultMountCommand, source, target, fstype, options, sensitiveOptions)
+@@ -116,6 +149,9 @@ func (mounter *Mounter) MountSensitiveWithoutSystemd(source string, target strin
+
+ // MountSensitiveWithoutSystemdWithMountFlags is the same as MountSensitiveWithoutSystemd with additional mount flags.
+ func (mounter *Mounter) MountSensitiveWithoutSystemdWithMountFlags(source string, target string, fstype string, options []string, sensitiveOptions []string, mountFlags []string) error {
++ if !mounter.withLinuxUtils {
++ return mounter.mountNative(source, target, fstype, options, sensitiveOptions)
++ }
+ mounterPath := ""
+ bind, bindOpts, bindRemountOpts, bindRemountOptsSensitive := MakeBindOptsSensitive(options, sensitiveOptions)
+ if bind {
+@@ -138,6 +174,80 @@ func (mounter *Mounter) MountSensitiveWithoutSystemdWithMountFlags(source string
+ return mounter.doMount(mounterPath, defaultMountCommand, source, target, fstype, options, sensitiveOptions, mountFlags, false)
}
+// nativeSupportsFstype checks if the native mounter can mount the given fstype
@@ -198,9 +179,9 @@
+}
+
// doMount runs the mount command. mounterPath is the path to mounter binary if containerized mounter is used.
- // sensitiveOptions is an extention of options except they will not be logged (because they may contain sensitive material)
- func (mounter *Mounter) doMount(mounterPath string, mountCmd string, source string, target string, fstype string, options []string, sensitiveOptions []string) error {
-@@ -179,6 +282,30 @@ func detectSystemd() bool {
+ // sensitiveOptions is an extension of options except they will not be logged (because they may contain sensitive material)
+ // systemdMountRequired is an extension of option to decide whether uses systemd mount.
+@@ -223,6 +333,30 @@ func detectSystemd() bool {
return true
}
@@ -231,7 +212,7 @@
// MakeMountArgs makes the arguments to the mount(8) command.
// options MUST not contain sensitive material (like passwords).
func MakeMountArgs(source, target, fstype string, options []string) (mountArgs []string) {
-@@ -236,6 +363,12 @@ func AddSystemdScopeSensitive(systemdRunPath, mountName, command string, args []
+@@ -292,6 +426,12 @@ func AddSystemdScopeSensitive(systemdRunPath, mountName, command string, args []
// Unmount unmounts the target.
func (mounter *Mounter) Unmount(target string) error {
klog.V(4).Infof("Unmounting %s", target)