mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: update kubernetes and libraries to v1.22.0 version
Kubernetes v1.22 version has been released and this update ceph csi dependencies to use the same version. Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
e077c1fdf5
commit
aa698bc3e1
87
vendor/k8s.io/kubernetes/pkg/volume/metrics_block.go
generated
vendored
Normal file
87
vendor/k8s.io/kubernetes/pkg/volume/metrics_block.go
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
Copyright 2021 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 volume
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
var _ MetricsProvider = &metricsBlock{}
|
||||
|
||||
// metricsBlock represents a MetricsProvider that detects the size of the
|
||||
// BlockMode Volume.
|
||||
type metricsBlock struct {
|
||||
// the device node where the volume is attached to.
|
||||
device string
|
||||
}
|
||||
|
||||
// NewMetricsStatfs creates a new metricsBlock with the device node of the
|
||||
// Volume.
|
||||
func NewMetricsBlock(device string) MetricsProvider {
|
||||
return &metricsBlock{device}
|
||||
}
|
||||
|
||||
// See MetricsProvider.GetMetrics
|
||||
// GetMetrics detects the size of the BlockMode volume for the device node
|
||||
// where the Volume is attached.
|
||||
//
|
||||
// Note that only the capacity of the device can be detected with standard
|
||||
// tools. Storage systems may have more information that they can provide by
|
||||
// going through specialized APIs.
|
||||
func (mb *metricsBlock) GetMetrics() (*Metrics, error) {
|
||||
// TODO: Windows does not yet support VolumeMode=Block
|
||||
if runtime.GOOS == "windows" {
|
||||
return nil, NewNotImplementedError("Windows does not support Block volumes")
|
||||
}
|
||||
|
||||
metrics := &Metrics{Time: metav1.Now()}
|
||||
if mb.device == "" {
|
||||
return metrics, NewNoPathDefinedError()
|
||||
}
|
||||
|
||||
err := mb.getBlockInfo(metrics)
|
||||
if err != nil {
|
||||
return metrics, err
|
||||
}
|
||||
|
||||
return metrics, nil
|
||||
}
|
||||
|
||||
// getBlockInfo fetches metrics.Capacity by opening the device and seeking to
|
||||
// the end.
|
||||
func (mb *metricsBlock) getBlockInfo(metrics *Metrics) error {
|
||||
dev, err := os.Open(mb.device)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to open device %q: %w", mb.device, err)
|
||||
}
|
||||
defer dev.Close()
|
||||
|
||||
end, err := dev.Seek(0, io.SeekEnd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to detect size of %q: %w", mb.device, err)
|
||||
}
|
||||
|
||||
metrics.Capacity = resource.NewQuantity(end, resource.BinarySI)
|
||||
|
||||
return nil
|
||||
}
|
26
vendor/k8s.io/kubernetes/pkg/volume/metrics_du.go
generated
vendored
26
vendor/k8s.io/kubernetes/pkg/volume/metrics_du.go
generated
vendored
@ -46,12 +46,7 @@ func (md *metricsDu) GetMetrics() (*Metrics, error) {
|
||||
return metrics, NewNoPathDefinedError()
|
||||
}
|
||||
|
||||
err := md.runDiskUsage(metrics)
|
||||
if err != nil {
|
||||
return metrics, err
|
||||
}
|
||||
|
||||
err = md.runFind(metrics)
|
||||
err := md.getDiskUsage(metrics)
|
||||
if err != nil {
|
||||
return metrics, err
|
||||
}
|
||||
@ -64,23 +59,14 @@ func (md *metricsDu) GetMetrics() (*Metrics, error) {
|
||||
return metrics, nil
|
||||
}
|
||||
|
||||
// runDiskUsage gets disk usage of md.path and writes the results to metrics.Used
|
||||
func (md *metricsDu) runDiskUsage(metrics *Metrics) error {
|
||||
used, err := fs.DiskUsage(md.path)
|
||||
// getDiskUsage writes metrics.Used and metric.InodesUsed from fs.DiskUsage
|
||||
func (md *metricsDu) getDiskUsage(metrics *Metrics) error {
|
||||
usage, err := fs.DiskUsage(md.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metrics.Used = used
|
||||
return nil
|
||||
}
|
||||
|
||||
// runFind executes the "find" command and writes the results to metrics.InodesUsed
|
||||
func (md *metricsDu) runFind(metrics *Metrics) error {
|
||||
inodesUsed, err := fs.Find(md.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metrics.InodesUsed = resource.NewQuantity(inodesUsed, resource.BinarySI)
|
||||
metrics.Used = resource.NewQuantity(usage.Bytes, resource.BinarySI)
|
||||
metrics.InodesUsed = resource.NewQuantity(usage.Inodes, resource.BinarySI)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
8
vendor/k8s.io/kubernetes/pkg/volume/metrics_errors.go
generated
vendored
8
vendor/k8s.io/kubernetes/pkg/volume/metrics_errors.go
generated
vendored
@ -35,6 +35,14 @@ func NewNotSupportedError() *MetricsError {
|
||||
}
|
||||
}
|
||||
|
||||
// NewNotImplementedError creates a new MetricsError with code NotSupported.
|
||||
func NewNotImplementedError(reason string) *MetricsError {
|
||||
return &MetricsError{
|
||||
Code: ErrCodeNotSupported,
|
||||
Msg: fmt.Sprintf("metrics support is not implemented: %s", reason),
|
||||
}
|
||||
}
|
||||
|
||||
// NewNotSupportedErrorWithDriverName creates a new MetricsError with code NotSupported.
|
||||
// driver name is added to the error message.
|
||||
func NewNotSupportedErrorWithDriverName(name string) *MetricsError {
|
||||
|
5
vendor/k8s.io/kubernetes/pkg/volume/metrics_nil.go
generated
vendored
5
vendor/k8s.io/kubernetes/pkg/volume/metrics_nil.go
generated
vendored
@ -23,6 +23,11 @@ var _ MetricsProvider = &MetricsNil{}
|
||||
// metrics.
|
||||
type MetricsNil struct{}
|
||||
|
||||
// SupportsMetrics returns false for the MetricsNil type.
|
||||
func (*MetricsNil) SupportsMetrics() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// GetMetrics returns an empty Metrics and an error.
|
||||
// See MetricsProvider.GetMetrics
|
||||
func (*MetricsNil) GetMetrics() (*Metrics, error) {
|
||||
|
36
vendor/k8s.io/kubernetes/pkg/volume/plugins.go
generated
vendored
36
vendor/k8s.io/kubernetes/pkg/volume/plugins.go
generated
vendored
@ -71,8 +71,10 @@ const (
|
||||
|
||||
var (
|
||||
deprecatedVolumeProviders = map[string]string{
|
||||
"kubernetes.io/cinder": "The Cinder volume provider is deprecated and will be removed in a future release",
|
||||
"kubernetes.io/scaleio": "The ScaleIO volume provider is deprecated and will be removed in a future release",
|
||||
"kubernetes.io/cinder": "The Cinder volume provider is deprecated and will be removed in a future release",
|
||||
"kubernetes.io/storageos": "The StorageOS volume provider is deprecated and will be removed in a future release",
|
||||
"kubernetes.io/quobyte": "The Quobyte volume provider is deprecated and will be removed in a future release",
|
||||
"kubernetes.io/flocker": "The Flocker volume provider is deprecated and will be removed in a future release",
|
||||
}
|
||||
)
|
||||
|
||||
@ -606,7 +608,7 @@ func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, prober DynamicPlu
|
||||
}
|
||||
if err := pm.prober.Init(); err != nil {
|
||||
// Prober init failure should not affect the initialization of other plugins.
|
||||
klog.Errorf("Error initializing dynamic plugin prober: %s", err)
|
||||
klog.ErrorS(err, "Error initializing dynamic plugin prober")
|
||||
pm.prober = &dummyPluginProber{}
|
||||
}
|
||||
|
||||
@ -631,12 +633,12 @@ func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, prober DynamicPlu
|
||||
}
|
||||
err := plugin.Init(host)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to load volume plugin %s, error: %s", name, err.Error())
|
||||
klog.ErrorS(err, "Failed to load volume plugin", "pluginName", name)
|
||||
allErrs = append(allErrs, err)
|
||||
continue
|
||||
}
|
||||
pm.plugins[name] = plugin
|
||||
klog.V(1).Infof("Loaded volume plugin %q", name)
|
||||
klog.V(1).InfoS("Loaded volume plugin", "pluginName", name)
|
||||
}
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
}
|
||||
@ -649,10 +651,10 @@ func (pm *VolumePluginMgr) initProbedPlugin(probedPlugin VolumePlugin) error {
|
||||
|
||||
err := probedPlugin.Init(pm.Host)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to load volume plugin %s, error: %s", name, err.Error())
|
||||
return fmt.Errorf("failed to load volume plugin %s, error: %s", name, err.Error())
|
||||
}
|
||||
|
||||
klog.V(1).Infof("Loaded volume plugin %q", name)
|
||||
klog.V(1).InfoS("Loaded volume plugin", "pluginName", name)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -664,7 +666,7 @@ func (pm *VolumePluginMgr) FindPluginBySpec(spec *Spec) (VolumePlugin, error) {
|
||||
defer pm.mutex.RUnlock()
|
||||
|
||||
if spec == nil {
|
||||
return nil, fmt.Errorf("Could not find plugin because volume spec is nil")
|
||||
return nil, fmt.Errorf("could not find plugin because volume spec is nil")
|
||||
}
|
||||
|
||||
matches := []VolumePlugin{}
|
||||
@ -745,15 +747,15 @@ func (pm *VolumePluginMgr) logDeprecation(plugin string) {
|
||||
func (pm *VolumePluginMgr) refreshProbedPlugins() {
|
||||
events, err := pm.prober.Probe()
|
||||
if err != nil {
|
||||
klog.Errorf("Error dynamically probing plugins: %s", err)
|
||||
klog.ErrorS(err, "Error dynamically probing plugins")
|
||||
return // Use cached plugins upon failure.
|
||||
}
|
||||
|
||||
for _, event := range events {
|
||||
if event.Op == ProbeAddOrUpdate {
|
||||
if err := pm.initProbedPlugin(event.Plugin); err != nil {
|
||||
klog.Errorf("Error initializing dynamically probed plugin %s; error: %s",
|
||||
event.Plugin.GetPluginName(), err)
|
||||
klog.ErrorS(err, "Error initializing dynamically probed plugin",
|
||||
"pluginName", event.Plugin.GetPluginName())
|
||||
continue
|
||||
}
|
||||
pm.probedPlugins[event.Plugin.GetPluginName()] = event.Plugin
|
||||
@ -761,8 +763,8 @@ func (pm *VolumePluginMgr) refreshProbedPlugins() {
|
||||
// Plugin is not available on ProbeRemove event, only PluginName
|
||||
delete(pm.probedPlugins, event.PluginName)
|
||||
} else {
|
||||
klog.Errorf("Unknown Operation on PluginName: %s.",
|
||||
event.Plugin.GetPluginName())
|
||||
klog.ErrorS(nil, "Unknown Operation on PluginName.",
|
||||
"pluginName", event.Plugin.GetPluginName())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -787,7 +789,7 @@ func (pm *VolumePluginMgr) ListVolumePluginWithLimits() []VolumePluginWithAttach
|
||||
func (pm *VolumePluginMgr) FindPersistentPluginBySpec(spec *Spec) (PersistentVolumePlugin, error) {
|
||||
volumePlugin, err := pm.FindPluginBySpec(spec)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not find volume plugin for spec: %#v", spec)
|
||||
return nil, fmt.Errorf("could not find volume plugin for spec: %#v", spec)
|
||||
}
|
||||
if persistentVolumePlugin, ok := volumePlugin.(PersistentVolumePlugin); ok {
|
||||
return persistentVolumePlugin, nil
|
||||
@ -800,7 +802,7 @@ func (pm *VolumePluginMgr) FindPersistentPluginBySpec(spec *Spec) (PersistentVol
|
||||
func (pm *VolumePluginMgr) FindVolumePluginWithLimitsBySpec(spec *Spec) (VolumePluginWithAttachLimits, error) {
|
||||
volumePlugin, err := pm.FindPluginBySpec(spec)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not find volume plugin for spec : %#v", spec)
|
||||
return nil, fmt.Errorf("could not find volume plugin for spec : %#v", spec)
|
||||
}
|
||||
|
||||
if limitedPlugin, ok := volumePlugin.(VolumePluginWithAttachLimits); ok {
|
||||
@ -956,10 +958,10 @@ func (pm *VolumePluginMgr) FindExpandablePluginBySpec(spec *Spec) (ExpandableVol
|
||||
if spec.IsKubeletExpandable() {
|
||||
// for kubelet expandable volumes, return a noop plugin that
|
||||
// returns success for expand on the controller
|
||||
klog.V(4).Infof("FindExpandablePluginBySpec(%s) -> returning noopExpandableVolumePluginInstance", spec.Name())
|
||||
klog.V(4).InfoS("FindExpandablePluginBySpec -> returning noopExpandableVolumePluginInstance", "specName", spec.Name())
|
||||
return &noopExpandableVolumePluginInstance{spec}, nil
|
||||
}
|
||||
klog.V(4).Infof("FindExpandablePluginBySpec(%s) -> err:%v", spec.Name(), err)
|
||||
klog.V(4).InfoS("FindExpandablePluginBySpec -> err", "specName", spec.Name(), "err", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
134
vendor/k8s.io/kubernetes/pkg/volume/util/fs/fs.go
generated
vendored
134
vendor/k8s.io/kubernetes/pkg/volume/util/fs/fs.go
generated
vendored
@ -19,17 +19,21 @@ limitations under the License.
|
||||
package fs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/volume/util/fsquota"
|
||||
)
|
||||
|
||||
type UsageInfo struct {
|
||||
Bytes int64
|
||||
Inodes int64
|
||||
}
|
||||
|
||||
// Info linux returns (available bytes, byte capacity, byte usage, total inodes, inodes free, inode usage, error)
|
||||
// for the filesystem that path resides upon.
|
||||
func Info(path string) (int64, int64, int64, int64, int64, int64, error) {
|
||||
@ -55,63 +59,83 @@ func Info(path string) (int64, int64, int64, int64, int64, int64, error) {
|
||||
return available, capacity, usage, inodes, inodesFree, inodesUsed, nil
|
||||
}
|
||||
|
||||
// DiskUsage gets disk usage of specified path.
|
||||
func DiskUsage(path string) (*resource.Quantity, error) {
|
||||
// First check whether the quota system knows about this directory
|
||||
// A nil quantity with no error means that the path does not support quotas
|
||||
// and we should use other mechanisms.
|
||||
data, err := fsquota.GetConsumption(path)
|
||||
if data != nil {
|
||||
return data, nil
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf("unable to retrieve disk consumption via quota for %s: %v", path, err)
|
||||
}
|
||||
// Uses the same niceness level as cadvisor.fs does when running du
|
||||
// Uses -B 1 to always scale to a blocksize of 1 byte
|
||||
out, err := exec.Command("nice", "-n", "19", "du", "-x", "-s", "-B", "1", path).CombinedOutput()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed command 'du' ($ nice -n 19 du -x -s -B 1) on path %s with error %v", path, err)
|
||||
}
|
||||
used, err := resource.ParseQuantity(strings.Fields(string(out))[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse 'du' output %s due to error %v", out, err)
|
||||
}
|
||||
used.Format = resource.BinarySI
|
||||
return &used, nil
|
||||
}
|
||||
// DiskUsage calculates the number of inodes and disk usage for a given directory
|
||||
func DiskUsage(path string) (UsageInfo, error) {
|
||||
var usage UsageInfo
|
||||
|
||||
// Find uses the equivalent of the command `find <path> -dev -printf '.' | wc -c` to count files and directories.
|
||||
// While this is not an exact measure of inodes used, it is a very good approximation.
|
||||
func Find(path string) (int64, error) {
|
||||
if path == "" {
|
||||
return 0, fmt.Errorf("invalid directory")
|
||||
return usage, fmt.Errorf("invalid directory")
|
||||
}
|
||||
|
||||
// First check whether the quota system knows about this directory
|
||||
// A nil quantity with no error means that the path does not support quotas
|
||||
// and we should use other mechanisms.
|
||||
inodes, err := fsquota.GetInodes(path)
|
||||
// A nil quantity or error means that the path does not support quotas
|
||||
// or xfs_quota tool is missing and we should use other mechanisms.
|
||||
consumption, _ := fsquota.GetConsumption(path)
|
||||
if consumption != nil {
|
||||
usage.Bytes = consumption.Value()
|
||||
}
|
||||
|
||||
inodes, _ := fsquota.GetInodes(path)
|
||||
if inodes != nil {
|
||||
return inodes.Value(), nil
|
||||
} else if err != nil {
|
||||
return 0, fmt.Errorf("unable to retrieve inode consumption via quota for %s: %v", path, err)
|
||||
usage.Inodes = inodes.Value()
|
||||
}
|
||||
var counter byteCounter
|
||||
var stderr bytes.Buffer
|
||||
findCmd := exec.Command("find", path, "-xdev", "-printf", ".")
|
||||
findCmd.Stdout, findCmd.Stderr = &counter, &stderr
|
||||
if err := findCmd.Start(); err != nil {
|
||||
return 0, fmt.Errorf("failed to exec cmd %v - %v; stderr: %v", findCmd.Args, err, stderr.String())
|
||||
}
|
||||
if err := findCmd.Wait(); err != nil {
|
||||
return 0, fmt.Errorf("cmd %v failed. stderr: %s; err: %v", findCmd.Args, stderr.String(), err)
|
||||
}
|
||||
return counter.bytesWritten, nil
|
||||
}
|
||||
|
||||
// Simple io.Writer implementation that counts how many bytes were written.
|
||||
type byteCounter struct{ bytesWritten int64 }
|
||||
if inodes != nil && consumption != nil {
|
||||
return usage, nil
|
||||
}
|
||||
|
||||
func (b *byteCounter) Write(p []byte) (int, error) {
|
||||
b.bytesWritten += int64(len(p))
|
||||
return len(p), nil
|
||||
topLevelStat := &unix.Stat_t{}
|
||||
err := unix.Stat(path, topLevelStat)
|
||||
if err != nil {
|
||||
return usage, err
|
||||
}
|
||||
|
||||
// dedupedInode stores inodes that could be duplicates (nlink > 1)
|
||||
dedupedInodes := make(map[uint64]struct{})
|
||||
|
||||
err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
|
||||
// ignore files that have been deleted after directory was read
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to count inodes for %s: %s", path, err)
|
||||
}
|
||||
|
||||
// according to the docs, Sys can be nil
|
||||
if info.Sys() == nil {
|
||||
return fmt.Errorf("fileinfo Sys is nil")
|
||||
}
|
||||
|
||||
s, ok := info.Sys().(*syscall.Stat_t)
|
||||
if !ok {
|
||||
return fmt.Errorf("unsupported fileinfo; could not convert to stat_t")
|
||||
}
|
||||
|
||||
if s.Dev != topLevelStat.Dev {
|
||||
// don't descend into directories on other devices
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
// Dedupe hardlinks
|
||||
if s.Nlink > 1 {
|
||||
if _, ok := dedupedInodes[s.Ino]; !ok {
|
||||
dedupedInodes[s.Ino] = struct{}{}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if consumption == nil {
|
||||
usage.Bytes += int64(s.Blocks) * int64(512) // blocksize in bytes
|
||||
}
|
||||
|
||||
if inodes == nil {
|
||||
usage.Inodes++
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return usage, err
|
||||
}
|
||||
|
17
vendor/k8s.io/kubernetes/pkg/volume/util/fs/fs_unsupported.go
generated
vendored
17
vendor/k8s.io/kubernetes/pkg/volume/util/fs/fs_unsupported.go
generated
vendored
@ -20,21 +20,20 @@ package fs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
)
|
||||
|
||||
type UsageInfo struct {
|
||||
Bytes int64
|
||||
Inodes int64
|
||||
}
|
||||
|
||||
// Info unsupported returns 0 values for available and capacity and an error.
|
||||
func Info(path string) (int64, int64, int64, int64, int64, int64, error) {
|
||||
return 0, 0, 0, 0, 0, 0, fmt.Errorf("fsinfo not supported for this build")
|
||||
}
|
||||
|
||||
// DiskUsage gets disk usage of specified path.
|
||||
func DiskUsage(path string) (*resource.Quantity, error) {
|
||||
return nil, fmt.Errorf("du not supported for this build")
|
||||
}
|
||||
|
||||
// Find will always return zero since is on unsupported platform.
|
||||
func Find(path string) (int64, error) {
|
||||
return 0, fmt.Errorf("find not supported for this build")
|
||||
func DiskUsage(path string) (UsageInfo, error) {
|
||||
var usage UsageInfo
|
||||
return usage, fmt.Errorf("directory disk usage not supported for this build.")
|
||||
}
|
||||
|
30
vendor/k8s.io/kubernetes/pkg/volume/util/fs/fs_windows.go
generated
vendored
30
vendor/k8s.io/kubernetes/pkg/volume/util/fs/fs_windows.go
generated
vendored
@ -26,8 +26,6 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -35,6 +33,11 @@ var (
|
||||
procGetDiskFreeSpaceEx = modkernel32.NewProc("GetDiskFreeSpaceExW")
|
||||
)
|
||||
|
||||
type UsageInfo struct {
|
||||
Bytes int64
|
||||
Inodes int64
|
||||
}
|
||||
|
||||
// Info returns (available bytes, byte capacity, byte usage, total inodes, inodes free, inode usage, error)
|
||||
// for the filesystem that path resides upon.
|
||||
func Info(path string) (int64, int64, int64, int64, int64, int64, error) {
|
||||
@ -64,28 +67,15 @@ func Info(path string) (int64, int64, int64, int64, int64, int64, error) {
|
||||
}
|
||||
|
||||
// DiskUsage gets disk usage of specified path.
|
||||
func DiskUsage(path string) (*resource.Quantity, error) {
|
||||
func DiskUsage(path string) (UsageInfo, error) {
|
||||
var usage UsageInfo
|
||||
info, err := os.Lstat(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return usage, err
|
||||
}
|
||||
|
||||
usage, err := diskUsage(path, info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
used, err := resource.ParseQuantity(fmt.Sprintf("%d", usage))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse fs usage %d due to %v", usage, err)
|
||||
}
|
||||
used.Format = resource.BinarySI
|
||||
return &used, nil
|
||||
}
|
||||
|
||||
// Find will always return zero since inodes is not supported on Windows.
|
||||
func Find(path string) (int64, error) {
|
||||
return 0, nil
|
||||
usage.Bytes, err = diskUsage(path, info)
|
||||
return usage, err
|
||||
}
|
||||
|
||||
func diskUsage(currPath string, info os.FileInfo) (int64, error) {
|
||||
|
5
vendor/k8s.io/kubernetes/pkg/volume/util/types/types.go
generated
vendored
5
vendor/k8s.io/kubernetes/pkg/volume/util/types/types.go
generated
vendored
@ -148,10 +148,7 @@ func IsOperationFinishedError(err error) bool {
|
||||
// on PVC and actual filesystem on disk did not match
|
||||
func IsFilesystemMismatchError(err error) bool {
|
||||
mountError := mount.MountError{}
|
||||
if errors.As(err, &mountError) && mountError.Type == mount.FilesystemMismatch {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return errors.As(err, &mountError) && mountError.Type == mount.FilesystemMismatch
|
||||
}
|
||||
|
||||
// IsUncertainProgressError checks if given error is of type that indicates
|
||||
|
15
vendor/k8s.io/kubernetes/pkg/volume/volume.go
generated
vendored
15
vendor/k8s.io/kubernetes/pkg/volume/volume.go
generated
vendored
@ -48,6 +48,14 @@ type BlockVolume interface {
|
||||
// and name of a symbolic link associated to a block device.
|
||||
// ex. pods/{podUid}/{DefaultKubeletVolumeDevicesDirName}/{escapeQualifiedPluginName}/, {volumeName}
|
||||
GetPodDeviceMapPath() (string, string)
|
||||
|
||||
// SupportsMetrics should return true if the MetricsProvider is
|
||||
// initialized
|
||||
SupportsMetrics() bool
|
||||
|
||||
// MetricsProvider embeds methods for exposing metrics (e.g.
|
||||
// used, available space).
|
||||
MetricsProvider
|
||||
}
|
||||
|
||||
// MetricsProvider exposes metrics (e.g. used,available space) related to a
|
||||
@ -263,6 +271,11 @@ type Attacher interface {
|
||||
WaitForAttach(spec *Spec, devicePath string, pod *v1.Pod, timeout time.Duration) (string, error)
|
||||
}
|
||||
|
||||
// DeviceMounterArgs provides auxiliary, optional arguments to DeviceMounter.
|
||||
type DeviceMounterArgs struct {
|
||||
FsGroup *int64
|
||||
}
|
||||
|
||||
// DeviceMounter can mount a block volume to a global path.
|
||||
type DeviceMounter interface {
|
||||
// GetDeviceMountPath returns a path where the device should
|
||||
@ -277,7 +290,7 @@ type DeviceMounter interface {
|
||||
// - TransientOperationFailure
|
||||
// - UncertainProgressError
|
||||
// - Error of any other type should be considered a final error
|
||||
MountDevice(spec *Spec, devicePath string, deviceMountPath string) error
|
||||
MountDevice(spec *Spec, devicePath string, deviceMountPath string, deviceMounterArgs DeviceMounterArgs) error
|
||||
}
|
||||
|
||||
type BulkVolumeVerifier interface {
|
||||
|
16
vendor/k8s.io/kubernetes/pkg/volume/volume_linux.go
generated
vendored
16
vendor/k8s.io/kubernetes/pkg/volume/volume_linux.go
generated
vendored
@ -66,7 +66,7 @@ func SetVolumeOwnership(mounter Mounter, fsGroup *int64, fsGroupChangePolicy *v1
|
||||
}
|
||||
|
||||
if skipPermissionChange(mounter, fsGroup, fsGroupChangePolicy) {
|
||||
klog.V(3).Infof("skipping permission and ownership change for volume %s", mounter.GetPath())
|
||||
klog.V(3).InfoS("Skipping permission and ownership change for volume", "path", mounter.GetPath())
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ func legacyOwnershipChange(mounter Mounter, fsGroup *int64) error {
|
||||
func changeFilePermission(filename string, fsGroup *int64, readonly bool, info os.FileInfo) error {
|
||||
err := os.Lchown(filename, -1, int(*fsGroup))
|
||||
if err != nil {
|
||||
klog.Errorf("Lchown failed on %v: %v", filename, err)
|
||||
klog.ErrorS(err, "Lchown failed", "path", filename)
|
||||
}
|
||||
|
||||
// chmod passes through to the underlying file for symlinks.
|
||||
@ -122,7 +122,7 @@ func changeFilePermission(filename string, fsGroup *int64, readonly bool, info o
|
||||
|
||||
err = os.Chmod(filename, info.Mode()|mask)
|
||||
if err != nil {
|
||||
klog.Errorf("Chmod failed on %v: %v", filename, err)
|
||||
klog.ErrorS(err, "Chown failed", "path", filename)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -132,7 +132,7 @@ func skipPermissionChange(mounter Mounter, fsGroup *int64, fsGroupChangePolicy *
|
||||
dir := mounter.GetPath()
|
||||
|
||||
if fsGroupChangePolicy == nil || *fsGroupChangePolicy != v1.FSGroupChangeOnRootMismatch {
|
||||
klog.V(4).Infof("perform recursive ownership change for %s", dir)
|
||||
klog.V(4).InfoS("Perform recursive ownership change for directory", "path", dir)
|
||||
return false
|
||||
}
|
||||
return !requiresPermissionChange(mounter.GetPath(), fsGroup, mounter.GetAttributes().ReadOnly)
|
||||
@ -141,17 +141,17 @@ func skipPermissionChange(mounter Mounter, fsGroup *int64, fsGroupChangePolicy *
|
||||
func requiresPermissionChange(rootDir string, fsGroup *int64, readonly bool) bool {
|
||||
fsInfo, err := os.Stat(rootDir)
|
||||
if err != nil {
|
||||
klog.Errorf("performing recursive ownership change on %s because reading permissions of root volume failed: %v", rootDir, err)
|
||||
klog.ErrorS(err, "Performing recursive ownership change on rootDir because reading permissions of root volume failed", "path", rootDir)
|
||||
return true
|
||||
}
|
||||
stat, ok := fsInfo.Sys().(*syscall.Stat_t)
|
||||
if !ok || stat == nil {
|
||||
klog.Errorf("performing recursive ownership change on %s because reading permissions of root volume failed", rootDir)
|
||||
klog.ErrorS(nil, "Performing recursive ownership change on rootDir because reading permissions of root volume failed", "path", rootDir)
|
||||
return true
|
||||
}
|
||||
|
||||
if int(stat.Gid) != int(*fsGroup) {
|
||||
klog.V(4).Infof("expected group ownership of volume %s did not match with: %d", rootDir, stat.Gid)
|
||||
klog.V(4).InfoS("Expected group ownership of volume did not match with Gid", "path", rootDir, "GID", stat.Gid)
|
||||
return true
|
||||
}
|
||||
unixPerms := rwMask
|
||||
@ -175,7 +175,7 @@ func requiresPermissionChange(rootDir string, fsGroup *int64, readonly bool) boo
|
||||
// unixPerms: 770, filePerms: 750 : 770&750 = 750 (perms on directory is NOT a superset)
|
||||
// We also need to check if setgid bits are set in permissions of the directory.
|
||||
if (unixPerms&filePerm != unixPerms) || (fsInfo.Mode()&os.ModeSetgid == 0) {
|
||||
klog.V(4).Infof("performing recursive ownership change on %s because of mismatching mode", rootDir)
|
||||
klog.V(4).InfoS("Performing recursive ownership change on rootDir because of mismatching mode", "path", rootDir)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
Reference in New Issue
Block a user