mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
Remove nsenter packages from vendor
Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
70d49b4e47
commit
d4a67c05f3
22
vendor/k8s.io/cloud-provider/cloud.go
generated
vendored
22
vendor/k8s.io/cloud-provider/cloud.go
generated
vendored
@ -104,6 +104,21 @@ func GetInstanceProviderID(ctx context.Context, cloud Interface, nodeName types.
|
||||
}
|
||||
|
||||
// LoadBalancer is an abstract, pluggable interface for load balancers.
|
||||
//
|
||||
// Cloud provider may chose to implement the logic for
|
||||
// constructing/destroying specific kinds of load balancers in a
|
||||
// controller separate from the ServiceController. If this is the case,
|
||||
// then {Ensure,Update}LoadBalancer must return the ImplementedElsewhere error.
|
||||
// For the given LB service, the GetLoadBalancer must return "exists=True" if
|
||||
// there exists a LoadBalancer instance created by ServiceController.
|
||||
// In all other cases, GetLoadBalancer must return a NotFound error.
|
||||
// EnsureLoadBalancerDeleted must not return ImplementedElsewhere to ensure
|
||||
// proper teardown of resources that were allocated by the ServiceController.
|
||||
// This can happen if a user changes the type of LB via an update to the resource
|
||||
// or when migrating from ServiceController to alternate implementation.
|
||||
// The finalizer on the service will be added and removed by ServiceController
|
||||
// irrespective of the ImplementedElsewhere error. Additional finalizers for
|
||||
// LB services must be managed in the alternate implementation.
|
||||
type LoadBalancer interface {
|
||||
// TODO: Break this up into different interfaces (LB, etc) when we have more than one type of service
|
||||
// GetLoadBalancer returns whether the specified load balancer exists, and
|
||||
@ -199,9 +214,10 @@ type Routes interface {
|
||||
}
|
||||
|
||||
var (
|
||||
InstanceNotFound = errors.New("instance not found")
|
||||
DiskNotFound = errors.New("disk is not found")
|
||||
NotImplemented = errors.New("unimplemented")
|
||||
DiskNotFound = errors.New("disk is not found")
|
||||
ImplementedElsewhere = errors.New("implemented by alternate to cloud provider")
|
||||
InstanceNotFound = errors.New("instance not found")
|
||||
NotImplemented = errors.New("unimplemented")
|
||||
)
|
||||
|
||||
// Zone represents the location of a particular machine.
|
||||
|
124
vendor/k8s.io/klog/klog.go
generated
vendored
124
vendor/k8s.io/klog/klog.go
generated
vendored
@ -20,17 +20,17 @@
|
||||
//
|
||||
// Basic examples:
|
||||
//
|
||||
// glog.Info("Prepare to repel boarders")
|
||||
// klog.Info("Prepare to repel boarders")
|
||||
//
|
||||
// glog.Fatalf("Initialization failed: %s", err)
|
||||
// klog.Fatalf("Initialization failed: %s", err)
|
||||
//
|
||||
// See the documentation for the V function for an explanation of these examples:
|
||||
//
|
||||
// if glog.V(2) {
|
||||
// glog.Info("Starting transaction...")
|
||||
// if klog.V(2) {
|
||||
// klog.Info("Starting transaction...")
|
||||
// }
|
||||
//
|
||||
// glog.V(2).Infoln("Processed", nItems, "elements")
|
||||
// klog.V(2).Infoln("Processed", nItems, "elements")
|
||||
//
|
||||
// Log output is buffered and written periodically using Flush. Programs
|
||||
// should call Flush before exiting to guarantee all log output is written.
|
||||
@ -142,7 +142,7 @@ func (s *severity) Set(value string) error {
|
||||
if v, ok := severityByName(value); ok {
|
||||
threshold = v
|
||||
} else {
|
||||
v, err := strconv.Atoi(value)
|
||||
v, err := strconv.ParseInt(value, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -226,7 +226,7 @@ func (l *Level) Get() interface{} {
|
||||
|
||||
// Set is part of the flag.Value interface.
|
||||
func (l *Level) Set(value string) error {
|
||||
v, err := strconv.Atoi(value)
|
||||
v, err := strconv.ParseInt(value, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -294,7 +294,7 @@ func (m *moduleSpec) Set(value string) error {
|
||||
return errVmoduleSyntax
|
||||
}
|
||||
pattern := patLev[0]
|
||||
v, err := strconv.Atoi(patLev[1])
|
||||
v, err := strconv.ParseInt(patLev[1], 10, 32)
|
||||
if err != nil {
|
||||
return errors.New("syntax error: expect comma-separated list of filename=N")
|
||||
}
|
||||
@ -396,30 +396,23 @@ type flushSyncWriter interface {
|
||||
io.Writer
|
||||
}
|
||||
|
||||
// init sets up the defaults and runs flushDaemon.
|
||||
func init() {
|
||||
// Default stderrThreshold is ERROR.
|
||||
logging.stderrThreshold = errorLog
|
||||
|
||||
logging.stderrThreshold = errorLog // Default stderrThreshold is ERROR.
|
||||
logging.setVState(0, nil, false)
|
||||
logging.logDir = ""
|
||||
logging.logFile = ""
|
||||
logging.logFileMaxSizeMB = 1800
|
||||
logging.toStderr = true
|
||||
logging.alsoToStderr = false
|
||||
logging.skipHeaders = false
|
||||
logging.addDirHeader = false
|
||||
logging.skipLogHeaders = false
|
||||
go logging.flushDaemon()
|
||||
}
|
||||
|
||||
var initDefaultsOnce sync.Once
|
||||
|
||||
// InitFlags is for explicitly initializing the flags.
|
||||
func InitFlags(flagset *flag.FlagSet) {
|
||||
|
||||
// Initialize defaults.
|
||||
initDefaultsOnce.Do(func() {
|
||||
logging.logDir = ""
|
||||
logging.logFile = ""
|
||||
logging.logFileMaxSizeMB = 1800
|
||||
logging.toStderr = true
|
||||
logging.alsoToStderr = false
|
||||
logging.skipHeaders = false
|
||||
logging.skipLogHeaders = false
|
||||
})
|
||||
|
||||
if flagset == nil {
|
||||
flagset = flag.CommandLine
|
||||
}
|
||||
@ -432,6 +425,7 @@ func InitFlags(flagset *flag.FlagSet) {
|
||||
flagset.BoolVar(&logging.toStderr, "logtostderr", logging.toStderr, "log to standard error instead of files")
|
||||
flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", logging.alsoToStderr, "log to standard error as well as files")
|
||||
flagset.Var(&logging.verbosity, "v", "number for the log level verbosity")
|
||||
flagset.BoolVar(&logging.skipHeaders, "add_dir_header", logging.addDirHeader, "If true, adds the file directory to the header")
|
||||
flagset.BoolVar(&logging.skipHeaders, "skip_headers", logging.skipHeaders, "If true, avoid header prefixes in the log messages")
|
||||
flagset.BoolVar(&logging.skipLogHeaders, "skip_log_headers", logging.skipLogHeaders, "If true, avoid headers when opening log files")
|
||||
flagset.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr")
|
||||
@ -500,6 +494,9 @@ type loggingT struct {
|
||||
|
||||
// If true, do not add the headers to log files
|
||||
skipLogHeaders bool
|
||||
|
||||
// If true, add the file directory to the header
|
||||
addDirHeader bool
|
||||
}
|
||||
|
||||
// buffer holds a byte Buffer for reuse. The zero value is ready for use.
|
||||
@ -585,9 +582,14 @@ func (l *loggingT) header(s severity, depth int) (*buffer, string, int) {
|
||||
file = "???"
|
||||
line = 1
|
||||
} else {
|
||||
slash := strings.LastIndex(file, "/")
|
||||
if slash >= 0 {
|
||||
file = file[slash+1:]
|
||||
if slash := strings.LastIndex(file, "/"); slash >= 0 {
|
||||
path := file
|
||||
file = path[slash+1:]
|
||||
if l.addDirHeader {
|
||||
if dirsep := strings.LastIndex(path[:slash], "/"); dirsep >= 0 {
|
||||
file = path[dirsep+1:]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return l.formatHeader(s, file, line), file, line
|
||||
@ -736,6 +738,8 @@ func (rb *redirectBuffer) Write(bytes []byte) (n int, err error) {
|
||||
|
||||
// SetOutput sets the output destination for all severities
|
||||
func SetOutput(w io.Writer) {
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
for s := fatalLog; s >= infoLog; s-- {
|
||||
rb := &redirectBuffer{
|
||||
w: w,
|
||||
@ -746,6 +750,8 @@ func SetOutput(w io.Writer) {
|
||||
|
||||
// SetOutputBySeverity sets the output destination for specific severity
|
||||
func SetOutputBySeverity(name string, w io.Writer) {
|
||||
logging.mu.Lock()
|
||||
defer logging.mu.Unlock()
|
||||
sev, ok := severityByName(name)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("SetOutputBySeverity(%q): unrecognized severity name", name))
|
||||
@ -771,24 +777,38 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo
|
||||
if alsoToStderr || l.alsoToStderr || s >= l.stderrThreshold.get() {
|
||||
os.Stderr.Write(data)
|
||||
}
|
||||
if l.file[s] == nil {
|
||||
if err := l.createFiles(s); err != nil {
|
||||
os.Stderr.Write(data) // Make sure the message appears somewhere.
|
||||
l.exit(err)
|
||||
|
||||
if logging.logFile != "" {
|
||||
// Since we are using a single log file, all of the items in l.file array
|
||||
// will point to the same file, so just use one of them to write data.
|
||||
if l.file[infoLog] == nil {
|
||||
if err := l.createFiles(infoLog); err != nil {
|
||||
os.Stderr.Write(data) // Make sure the message appears somewhere.
|
||||
l.exit(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
switch s {
|
||||
case fatalLog:
|
||||
l.file[fatalLog].Write(data)
|
||||
fallthrough
|
||||
case errorLog:
|
||||
l.file[errorLog].Write(data)
|
||||
fallthrough
|
||||
case warningLog:
|
||||
l.file[warningLog].Write(data)
|
||||
fallthrough
|
||||
case infoLog:
|
||||
l.file[infoLog].Write(data)
|
||||
} else {
|
||||
if l.file[s] == nil {
|
||||
if err := l.createFiles(s); err != nil {
|
||||
os.Stderr.Write(data) // Make sure the message appears somewhere.
|
||||
l.exit(err)
|
||||
}
|
||||
}
|
||||
|
||||
switch s {
|
||||
case fatalLog:
|
||||
l.file[fatalLog].Write(data)
|
||||
fallthrough
|
||||
case errorLog:
|
||||
l.file[errorLog].Write(data)
|
||||
fallthrough
|
||||
case warningLog:
|
||||
l.file[warningLog].Write(data)
|
||||
fallthrough
|
||||
case infoLog:
|
||||
l.file[infoLog].Write(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
if s == fatalLog {
|
||||
@ -827,7 +847,7 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo
|
||||
|
||||
// timeoutFlush calls Flush and returns when it completes or after timeout
|
||||
// elapses, whichever happens first. This is needed because the hooks invoked
|
||||
// by Flush may deadlock when glog.Fatal is called from a hook that holds
|
||||
// by Flush may deadlock when klog.Fatal is called from a hook that holds
|
||||
// a lock.
|
||||
func timeoutFlush(timeout time.Duration) {
|
||||
done := make(chan bool, 1)
|
||||
@ -838,7 +858,7 @@ func timeoutFlush(timeout time.Duration) {
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(timeout):
|
||||
fmt.Fprintln(os.Stderr, "glog: Flush took longer than", timeout)
|
||||
fmt.Fprintln(os.Stderr, "klog: Flush took longer than", timeout)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1094,9 +1114,9 @@ type Verbose bool
|
||||
// The returned value is a boolean of type Verbose, which implements Info, Infoln
|
||||
// and Infof. These methods will write to the Info log if called.
|
||||
// Thus, one may write either
|
||||
// if glog.V(2) { glog.Info("log this") }
|
||||
// if klog.V(2) { klog.Info("log this") }
|
||||
// or
|
||||
// glog.V(2).Info("log this")
|
||||
// klog.V(2).Info("log this")
|
||||
// The second form is shorter but the first is cheaper if logging is off because it does
|
||||
// not evaluate its arguments.
|
||||
//
|
||||
@ -1170,7 +1190,7 @@ func InfoDepth(depth int, args ...interface{}) {
|
||||
}
|
||||
|
||||
// Infoln logs to the INFO log.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Infoln(args ...interface{}) {
|
||||
logging.println(infoLog, args...)
|
||||
}
|
||||
@ -1194,7 +1214,7 @@ func WarningDepth(depth int, args ...interface{}) {
|
||||
}
|
||||
|
||||
// Warningln logs to the WARNING and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Warningln(args ...interface{}) {
|
||||
logging.println(warningLog, args...)
|
||||
}
|
||||
@ -1218,7 +1238,7 @@ func ErrorDepth(depth int, args ...interface{}) {
|
||||
}
|
||||
|
||||
// Errorln logs to the ERROR, WARNING, and INFO logs.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Errorln(args ...interface{}) {
|
||||
logging.println(errorLog, args...)
|
||||
}
|
||||
@ -1244,7 +1264,7 @@ func FatalDepth(depth int, args ...interface{}) {
|
||||
|
||||
// Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs,
|
||||
// including a stack trace of all running goroutines, then calls os.Exit(255).
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
|
||||
// Arguments are handled in the manner of fmt.Println; a newline is always appended.
|
||||
func Fatalln(args ...interface{}) {
|
||||
logging.println(fatalLog, args...)
|
||||
}
|
||||
|
345
vendor/k8s.io/kubernetes/pkg/volume/util/nsenter/nsenter_mount.go
generated
vendored
345
vendor/k8s.io/kubernetes/pkg/volume/util/nsenter/nsenter_mount.go
generated
vendored
@ -1,345 +0,0 @@
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2014 The Kubernetes 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.
|
||||
*/
|
||||
|
||||
package nsenter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/utils/nsenter"
|
||||
utilpath "k8s.io/utils/path"
|
||||
)
|
||||
|
||||
const (
|
||||
// hostProcMountsPath is the default mount path for rootfs
|
||||
hostProcMountsPath = "/rootfs/proc/1/mounts"
|
||||
// hostProcMountinfoPath is the default mount info path for rootfs
|
||||
hostProcMountinfoPath = "/rootfs/proc/1/mountinfo"
|
||||
)
|
||||
|
||||
// Mounter implements mount.Interface
|
||||
// Currently, all docker containers receive their own mount namespaces.
|
||||
// Mounter works by executing nsenter to run commands in
|
||||
// the host's mount namespace.
|
||||
type Mounter struct {
|
||||
ne *nsenter.Nsenter
|
||||
// rootDir is location of /var/lib/kubelet directory.
|
||||
rootDir string
|
||||
}
|
||||
|
||||
// NewMounter creates a new mounter for kubelet that runs as a container.
|
||||
func NewMounter(rootDir string, ne *nsenter.Nsenter) *Mounter {
|
||||
return &Mounter{
|
||||
rootDir: rootDir,
|
||||
ne: ne,
|
||||
}
|
||||
}
|
||||
|
||||
// Mounter implements mount.Interface
|
||||
var _ = mount.Interface(&Mounter{})
|
||||
|
||||
// Mount runs mount(8) in the host's root mount namespace. Aside from this
|
||||
// aspect, Mount has the same semantics as the mounter returned by mount.New()
|
||||
func (n *Mounter) Mount(source string, target string, fstype string, options []string) error {
|
||||
bind, bindOpts, bindRemountOpts := mount.IsBind(options)
|
||||
|
||||
if bind {
|
||||
err := n.doNsenterMount(source, target, fstype, bindOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return n.doNsenterMount(source, target, fstype, bindRemountOpts)
|
||||
}
|
||||
|
||||
return n.doNsenterMount(source, target, fstype, options)
|
||||
}
|
||||
|
||||
// doNsenterMount nsenters the host's mount namespace and performs the
|
||||
// requested mount.
|
||||
func (n *Mounter) doNsenterMount(source, target, fstype string, options []string) error {
|
||||
klog.V(5).Infof("nsenter mount %s %s %s %v", source, target, fstype, options)
|
||||
cmd, args := n.makeNsenterArgs(source, target, fstype, options)
|
||||
outputBytes, err := n.ne.Exec(cmd, args).CombinedOutput()
|
||||
if len(outputBytes) != 0 {
|
||||
klog.V(5).Infof("Output of mounting %s to %s: %v", source, target, string(outputBytes))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// makeNsenterArgs makes a list of argument to nsenter in order to do the
|
||||
// requested mount.
|
||||
func (n *Mounter) makeNsenterArgs(source, target, fstype string, options []string) (string, []string) {
|
||||
mountCmd := n.ne.AbsHostPath("mount")
|
||||
mountArgs := mount.MakeMountArgs(source, target, fstype, options)
|
||||
|
||||
if systemdRunPath, hasSystemd := n.ne.SupportsSystemd(); hasSystemd {
|
||||
// Complete command line:
|
||||
// nsenter --mount=/rootfs/proc/1/ns/mnt -- /bin/systemd-run --description=... --scope -- /bin/mount -t <type> <what> <where>
|
||||
// Expected flow is:
|
||||
// * nsenter breaks out of container's mount namespace and executes
|
||||
// host's systemd-run.
|
||||
// * systemd-run creates a transient scope (=~ cgroup) and executes its
|
||||
// argument (/bin/mount) there.
|
||||
// * mount does its job, forks a fuse daemon if necessary and finishes.
|
||||
// (systemd-run --scope finishes at this point, returning mount's exit
|
||||
// code and stdout/stderr - thats one of --scope benefits).
|
||||
// * systemd keeps the fuse daemon running in the scope (i.e. in its own
|
||||
// cgroup) until the fuse daemon dies (another --scope benefit).
|
||||
// Kubelet container can be restarted and the fuse daemon survives.
|
||||
// * When the daemon dies (e.g. during unmount) systemd removes the
|
||||
// scope automatically.
|
||||
mountCmd, mountArgs = mount.AddSystemdScope(systemdRunPath, target, mountCmd, mountArgs)
|
||||
} else {
|
||||
// Fall back to simple mount when the host has no systemd.
|
||||
// Complete command line:
|
||||
// nsenter --mount=/rootfs/proc/1/ns/mnt -- /bin/mount -t <type> <what> <where>
|
||||
// Expected flow is:
|
||||
// * nsenter breaks out of container's mount namespace and executes host's /bin/mount.
|
||||
// * mount does its job, forks a fuse daemon if necessary and finishes.
|
||||
// * Any fuse daemon runs in cgroup of kubelet docker container,
|
||||
// restart of kubelet container will kill it!
|
||||
|
||||
// No code here, mountCmd and mountArgs use /bin/mount
|
||||
}
|
||||
|
||||
return mountCmd, mountArgs
|
||||
}
|
||||
|
||||
// Unmount runs umount(8) in the host's mount namespace.
|
||||
func (n *Mounter) Unmount(target string) error {
|
||||
args := []string{target}
|
||||
// No need to execute systemd-run here, it's enough that unmount is executed
|
||||
// in the host's mount namespace. It will finish appropriate fuse daemon(s)
|
||||
// running in any scope.
|
||||
klog.V(5).Infof("nsenter unmount args: %v", args)
|
||||
outputBytes, err := n.ne.Exec("umount", args).CombinedOutput()
|
||||
if len(outputBytes) != 0 {
|
||||
klog.V(5).Infof("Output of unmounting %s: %v", target, string(outputBytes))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// List returns a list of all mounted filesystems in the host's mount namespace.
|
||||
func (*Mounter) List() ([]mount.MountPoint, error) {
|
||||
return mount.ListProcMounts(hostProcMountsPath)
|
||||
}
|
||||
|
||||
// IsMountPointMatch tests if dir and mp are the same path
|
||||
func (*Mounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool {
|
||||
deletedDir := fmt.Sprintf("%s\\040(deleted)", dir)
|
||||
return (mp.Path == dir) || (mp.Path == deletedDir)
|
||||
}
|
||||
|
||||
// IsLikelyNotMountPoint determines whether a path is a mountpoint by calling findmnt
|
||||
// in the host's root mount namespace.
|
||||
func (n *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
|
||||
file, err := filepath.Abs(file)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
// Check the directory exists
|
||||
if _, err = os.Stat(file); os.IsNotExist(err) {
|
||||
klog.V(5).Infof("findmnt: directory %s does not exist", file)
|
||||
return true, err
|
||||
}
|
||||
|
||||
// Resolve any symlinks in file, kernel would do the same and use the resolved path in /proc/mounts
|
||||
resolvedFile, err := n.EvalHostSymlinks(file)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
|
||||
// Add --first-only option: since we are testing for the absence of a mountpoint, it is sufficient to get only
|
||||
// the first of multiple possible mountpoints using --first-only.
|
||||
// Also add fstype output to make sure that the output of target file will give the full path
|
||||
// TODO: Need more refactoring for this function. Track the solution with issue #26996
|
||||
args := []string{"-o", "target,fstype", "--noheadings", "--first-only", "--target", resolvedFile}
|
||||
klog.V(5).Infof("nsenter findmnt args: %v", args)
|
||||
out, err := n.ne.Exec("findmnt", args).CombinedOutput()
|
||||
if err != nil {
|
||||
klog.V(2).Infof("Failed findmnt command for path %s: %s %v", resolvedFile, out, err)
|
||||
// Different operating systems behave differently for paths which are not mount points.
|
||||
// On older versions (e.g. 2.20.1) we'd get error, on newer ones (e.g. 2.26.2) we'd get "/".
|
||||
// It's safer to assume that it's not a mount point.
|
||||
return true, nil
|
||||
}
|
||||
mountTarget, err := parseFindMnt(string(out))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
klog.V(5).Infof("IsLikelyNotMountPoint findmnt output for path %s: %v:", resolvedFile, mountTarget)
|
||||
|
||||
if mountTarget == resolvedFile {
|
||||
klog.V(5).Infof("IsLikelyNotMountPoint: %s is a mount point", resolvedFile)
|
||||
return false, nil
|
||||
}
|
||||
klog.V(5).Infof("IsLikelyNotMountPoint: %s is not a mount point", resolvedFile)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// parse output of "findmnt -o target,fstype" and return just the target
|
||||
func parseFindMnt(out string) (string, error) {
|
||||
// cut trailing newline
|
||||
out = strings.TrimSuffix(out, "\n")
|
||||
// cut everything after the last space - it's the filesystem type
|
||||
i := strings.LastIndex(out, " ")
|
||||
if i == -1 {
|
||||
return "", fmt.Errorf("error parsing findmnt output, expected at least one space: %q", out)
|
||||
}
|
||||
return out[:i], nil
|
||||
}
|
||||
|
||||
// DeviceOpened checks if block device in use by calling Open with O_EXCL flag.
|
||||
// Returns true if open returns errno EBUSY, and false if errno is nil.
|
||||
// Returns an error if errno is any error other than EBUSY.
|
||||
// Returns with error if pathname is not a device.
|
||||
func (n *Mounter) DeviceOpened(pathname string) (bool, error) {
|
||||
return mount.ExclusiveOpenFailsOnDevice(pathname)
|
||||
}
|
||||
|
||||
// PathIsDevice uses FileInfo returned from os.Stat to check if path refers
|
||||
// to a device.
|
||||
func (n *Mounter) PathIsDevice(pathname string) (bool, error) {
|
||||
pathType, err := n.GetFileType(pathname)
|
||||
isDevice := pathType == mount.FileTypeCharDev || pathType == mount.FileTypeBlockDev
|
||||
return isDevice, err
|
||||
}
|
||||
|
||||
//GetDeviceNameFromMount given a mount point, find the volume id from checking /proc/mounts
|
||||
func (n *Mounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) {
|
||||
return mount.GetDeviceNameFromMountLinux(n, mountPath, pluginMountDir)
|
||||
}
|
||||
|
||||
// MakeRShared checks if path is shared and bind-mounts it as rshared if needed.
|
||||
func (n *Mounter) MakeRShared(path string) error {
|
||||
return mount.DoMakeRShared(path, hostProcMountinfoPath)
|
||||
}
|
||||
|
||||
// GetFileType checks for file/directory/socket/block/character devices.
|
||||
func (n *Mounter) GetFileType(pathname string) (mount.FileType, error) {
|
||||
var pathType mount.FileType
|
||||
outputBytes, err := n.ne.Exec("stat", []string{"-L", "--printf=%F", pathname}).CombinedOutput()
|
||||
if err != nil {
|
||||
if strings.Contains(string(outputBytes), "No such file") {
|
||||
err = fmt.Errorf("%s does not exist", pathname)
|
||||
} else {
|
||||
err = fmt.Errorf("stat %s error: %v", pathname, string(outputBytes))
|
||||
}
|
||||
return pathType, err
|
||||
}
|
||||
|
||||
switch string(outputBytes) {
|
||||
case "socket":
|
||||
return mount.FileTypeSocket, nil
|
||||
case "character special file":
|
||||
return mount.FileTypeCharDev, nil
|
||||
case "block special file":
|
||||
return mount.FileTypeBlockDev, nil
|
||||
case "directory":
|
||||
return mount.FileTypeDirectory, nil
|
||||
case "regular file", "regular empty file":
|
||||
return mount.FileTypeFile, nil
|
||||
}
|
||||
|
||||
return pathType, fmt.Errorf("only recognise file, directory, socket, block device and character device")
|
||||
}
|
||||
|
||||
// MakeDir creates a new directory.
|
||||
func (n *Mounter) MakeDir(pathname string) error {
|
||||
args := []string{"-p", pathname}
|
||||
if _, err := n.ne.Exec("mkdir", args).CombinedOutput(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MakeFile creates an empty file.
|
||||
func (n *Mounter) MakeFile(pathname string) error {
|
||||
args := []string{pathname}
|
||||
if _, err := n.ne.Exec("touch", args).CombinedOutput(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExistsPath checks if pathname exists.
|
||||
// Error is returned on any other error than "file not found".
|
||||
func (n *Mounter) ExistsPath(pathname string) (bool, error) {
|
||||
// Resolve the symlinks but allow the target not to exist. EvalSymlinks
|
||||
// would return an generic error when the target does not exist.
|
||||
hostPath, err := n.ne.EvalSymlinks(pathname, false /* mustExist */)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
kubeletpath := n.ne.KubeletPath(hostPath)
|
||||
return utilpath.Exists(utilpath.CheckFollowSymlink, kubeletpath)
|
||||
}
|
||||
|
||||
// EvalHostSymlinks returns the path name after evaluating symlinks.
|
||||
func (n *Mounter) EvalHostSymlinks(pathname string) (string, error) {
|
||||
return n.ne.EvalSymlinks(pathname, true)
|
||||
}
|
||||
|
||||
// GetMountRefs finds all mount references to the path, returns a
|
||||
// list of paths. Path could be a mountpoint path, device or a normal
|
||||
// directory (for bind mount).
|
||||
func (n *Mounter) GetMountRefs(pathname string) ([]string, error) {
|
||||
pathExists, pathErr := mount.PathExists(pathname)
|
||||
if !pathExists || mount.IsCorruptedMnt(pathErr) {
|
||||
return []string{}, nil
|
||||
} else if pathErr != nil {
|
||||
return nil, fmt.Errorf("Error checking path %s: %v", pathname, pathErr)
|
||||
}
|
||||
hostpath, err := n.ne.EvalSymlinks(pathname, true /* mustExist */)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mount.SearchMountPoints(hostpath, hostProcMountinfoPath)
|
||||
}
|
||||
|
||||
// GetFSGroup returns FSGroup of pathname.
|
||||
func (n *Mounter) GetFSGroup(pathname string) (int64, error) {
|
||||
hostPath, err := n.ne.EvalSymlinks(pathname, true /* mustExist */)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
kubeletpath := n.ne.KubeletPath(hostPath)
|
||||
return mount.GetFSGroupLinux(kubeletpath)
|
||||
}
|
||||
|
||||
// GetSELinuxSupport tests if pathname is on a mount that supports SELinux.
|
||||
func (n *Mounter) GetSELinuxSupport(pathname string) (bool, error) {
|
||||
return mount.GetSELinux(pathname, hostProcMountsPath)
|
||||
}
|
||||
|
||||
// GetMode returns permissions of pathname.
|
||||
func (n *Mounter) GetMode(pathname string) (os.FileMode, error) {
|
||||
hostPath, err := n.ne.EvalSymlinks(pathname, true /* mustExist */)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
kubeletpath := n.ne.KubeletPath(hostPath)
|
||||
return mount.GetModeLinux(kubeletpath)
|
||||
}
|
139
vendor/k8s.io/kubernetes/pkg/volume/util/nsenter/nsenter_mount_unsupported.go
generated
vendored
139
vendor/k8s.io/kubernetes/pkg/volume/util/nsenter/nsenter_mount_unsupported.go
generated
vendored
@ -1,139 +0,0 @@
|
||||
// +build !linux
|
||||
|
||||
/*
|
||||
Copyright 2014 The Kubernetes 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.
|
||||
*/
|
||||
|
||||
package nsenter
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"k8s.io/utils/nsenter"
|
||||
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
)
|
||||
|
||||
// Mounter provides the mount.Interface implementation for unsupported
|
||||
// platforms.
|
||||
type Mounter struct{}
|
||||
|
||||
// NewMounter returns a new Mounter for the current system
|
||||
func NewMounter(rootDir string, ne *nsenter.Nsenter) *Mounter {
|
||||
return &Mounter{}
|
||||
}
|
||||
|
||||
var _ = mount.Interface(&Mounter{})
|
||||
|
||||
// Mount mounts the source to the target. It is a noop for unsupported systems
|
||||
func (*Mounter) Mount(source string, target string, fstype string, options []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unmount unmounts the target path from the system. it is a noop for unsupported
|
||||
// systems
|
||||
func (*Mounter) Unmount(target string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// List returns a list of all mounted filesystems. It is a noop for unsupported systems
|
||||
func (*Mounter) List() ([]mount.MountPoint, error) {
|
||||
return []mount.MountPoint{}, nil
|
||||
}
|
||||
|
||||
// IsMountPointMatch tests if dir and mp are the same path
|
||||
func (*Mounter) IsMountPointMatch(mp mount.MountPoint, dir string) bool {
|
||||
return (mp.Path == dir)
|
||||
}
|
||||
|
||||
// IsLikelyNotMountPoint determines if a directory is not a mountpoint.
|
||||
// It is a noop on unsupported systems
|
||||
func (*Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// DeviceOpened checks if block device in use. I tis a noop for unsupported systems
|
||||
func (*Mounter) DeviceOpened(pathname string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// PathIsDevice checks if pathname refers to a device. It is a noop for unsupported
|
||||
// systems
|
||||
func (*Mounter) PathIsDevice(pathname string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// GetDeviceNameFromMount finds the device name from its global mount point using the
|
||||
// given mountpath and plugin location. It is a noop of unsupported platforms
|
||||
func (*Mounter) GetDeviceNameFromMount(mountPath, pluginMountDir string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// MakeRShared checks if path is shared and bind-mounts it as rshared if needed.
|
||||
// It is a noop on unsupported platforms
|
||||
func (*Mounter) MakeRShared(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetFileType checks for file/directory/socket/block/character devices.
|
||||
// Always returns an error and "fake" filetype on unsupported platforms
|
||||
func (*Mounter) GetFileType(_ string) (mount.FileType, error) {
|
||||
return mount.FileType("fake"), errors.New("not implemented")
|
||||
}
|
||||
|
||||
// MakeDir creates a new directory. Noop on unsupported platforms
|
||||
func (*Mounter) MakeDir(pathname string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MakeFile creats an empty file. Noop on unsupported platforms
|
||||
func (*Mounter) MakeFile(pathname string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExistsPath checks if pathname exists. Always returns an error on unsupported
|
||||
// platforms
|
||||
func (*Mounter) ExistsPath(pathname string) (bool, error) {
|
||||
return true, errors.New("not implemented")
|
||||
}
|
||||
|
||||
// EvalHostSymlinks returns the path name after evaluating symlinks. Always
|
||||
// returns an error on unsupported platforms
|
||||
func (*Mounter) EvalHostSymlinks(pathname string) (string, error) {
|
||||
return "", errors.New("not implemented")
|
||||
}
|
||||
|
||||
// GetMountRefs finds all mount references to the path, returns a
|
||||
// list of paths. Always returns an error on unsupported platforms
|
||||
func (*Mounter) GetMountRefs(pathname string) ([]string, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
// GetFSGroup returns FSGroup of pathname. Always returns an error on unsupported platforms
|
||||
func (*Mounter) GetFSGroup(pathname string) (int64, error) {
|
||||
return -1, errors.New("not implemented")
|
||||
}
|
||||
|
||||
// GetSELinuxSupport tests if pathname is on a mount that supports SELinux.
|
||||
// Always returns an error on unsupported platforms
|
||||
func (*Mounter) GetSELinuxSupport(pathname string) (bool, error) {
|
||||
return false, errors.New("not implemented")
|
||||
}
|
||||
|
||||
// GetMode returns permissions of pathname. Always returns an error on unsupported platforms
|
||||
func (*Mounter) GetMode(pathname string) (os.FileMode, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
49
vendor/k8s.io/utils/net/net.go
generated
vendored
49
vendor/k8s.io/utils/net/net.go
generated
vendored
@ -17,8 +17,11 @@ limitations under the License.
|
||||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"net"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// ParseCIDRs parses a list of cidrs and return error if any is invalid.
|
||||
@ -132,3 +135,49 @@ func IsIPv6CIDR(cidr *net.IPNet) bool {
|
||||
ip := cidr.IP
|
||||
return IsIPv6(ip)
|
||||
}
|
||||
|
||||
// ParsePort parses a string representing an IP port. If the string is not a
|
||||
// valid port number, this returns an error.
|
||||
func ParsePort(port string, allowZero bool) (int, error) {
|
||||
portInt, err := strconv.ParseUint(port, 10, 16)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if portInt == 0 && !allowZero {
|
||||
return 0, errors.New("0 is not a valid port number")
|
||||
}
|
||||
return int(portInt), nil
|
||||
}
|
||||
|
||||
// BigForIP creates a big.Int based on the provided net.IP
|
||||
func BigForIP(ip net.IP) *big.Int {
|
||||
b := ip.To4()
|
||||
if b == nil {
|
||||
b = ip.To16()
|
||||
}
|
||||
return big.NewInt(0).SetBytes(b)
|
||||
}
|
||||
|
||||
// AddIPOffset adds the provided integer offset to a base big.Int representing a
|
||||
// net.IP
|
||||
func AddIPOffset(base *big.Int, offset int) net.IP {
|
||||
return net.IP(big.NewInt(0).Add(base, big.NewInt(int64(offset))).Bytes())
|
||||
}
|
||||
|
||||
// RangeSize returns the size of a range in valid addresses.
|
||||
func RangeSize(subnet *net.IPNet) int64 {
|
||||
ones, bits := subnet.Mask.Size()
|
||||
if bits == 32 && (bits-ones) >= 31 || bits == 128 && (bits-ones) >= 127 {
|
||||
return 0
|
||||
}
|
||||
return int64(1) << uint(bits-ones)
|
||||
}
|
||||
|
||||
// GetIndexedIP returns a net.IP that is subnet.IP + index in the contiguous IP space.
|
||||
func GetIndexedIP(subnet *net.IPNet, index int) (net.IP, error) {
|
||||
ip := AddIPOffset(BigForIP(subnet.IP), index)
|
||||
if !subnet.Contains(ip) {
|
||||
return nil, fmt.Errorf("can't generate IP with index %d from subnet. subnet too small. subnet: %q", index, subnet)
|
||||
}
|
||||
return ip, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user