mirror of https://github.com/k3s-io/k3s
Do not track resource usage for host path volumes. They can contain loops.
Signed-off-by: Vishnu kannan <vishnuk@google.com>pull/6/head
parent
f89432e44b
commit
9e5ddcb822
|
@ -97,13 +97,13 @@ func (plugin *hostPathPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volu
|
|||
if spec.Volume != nil && spec.Volume.HostPath != nil {
|
||||
path := spec.Volume.HostPath.Path
|
||||
return &hostPathBuilder{
|
||||
hostPath: &hostPath{path: path, MetricsProvider: volume.NewMetricsDu(path)},
|
||||
hostPath: &hostPath{path: path},
|
||||
readOnly: false,
|
||||
}, nil
|
||||
} else {
|
||||
path := spec.PersistentVolume.Spec.HostPath.Path
|
||||
return &hostPathBuilder{
|
||||
hostPath: &hostPath{path: path, MetricsProvider: volume.NewMetricsDu(path)},
|
||||
hostPath: &hostPath{path: path},
|
||||
readOnly: spec.ReadOnly,
|
||||
}, nil
|
||||
}
|
||||
|
@ -111,8 +111,7 @@ func (plugin *hostPathPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volu
|
|||
|
||||
func (plugin *hostPathPlugin) NewCleaner(volName string, podUID types.UID) (volume.Cleaner, error) {
|
||||
return &hostPathCleaner{&hostPath{
|
||||
path: "",
|
||||
MetricsProvider: volume.NewMetricsDu(""),
|
||||
path: "",
|
||||
}}, nil
|
||||
}
|
||||
|
||||
|
@ -137,12 +136,11 @@ func newRecycler(spec *volume.Spec, host volume.VolumeHost, config volume.Volume
|
|||
}
|
||||
path := spec.PersistentVolume.Spec.HostPath.Path
|
||||
return &hostPathRecycler{
|
||||
name: spec.Name(),
|
||||
path: path,
|
||||
host: host,
|
||||
config: config,
|
||||
timeout: volume.CalculateTimeoutForVolume(config.RecyclerMinimumTimeout, config.RecyclerTimeoutIncrement, spec.PersistentVolume),
|
||||
MetricsProvider: volume.NewMetricsDu(path),
|
||||
name: spec.Name(),
|
||||
path: path,
|
||||
host: host,
|
||||
config: config,
|
||||
timeout: volume.CalculateTimeoutForVolume(config.RecyclerMinimumTimeout, config.RecyclerTimeoutIncrement, spec.PersistentVolume),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -151,7 +149,7 @@ func newDeleter(spec *volume.Spec, host volume.VolumeHost) (volume.Deleter, erro
|
|||
return nil, fmt.Errorf("spec.PersistentVolumeSource.HostPath is nil")
|
||||
}
|
||||
path := spec.PersistentVolume.Spec.HostPath.Path
|
||||
return &hostPathDeleter{spec.Name(), path, host, volume.NewMetricsDu(path)}, nil
|
||||
return &hostPathDeleter{name: spec.Name(), path: path, host: host}, nil
|
||||
}
|
||||
|
||||
func newProvisioner(options volume.VolumeOptions, host volume.VolumeHost) (volume.Provisioner, error) {
|
||||
|
@ -162,7 +160,7 @@ func newProvisioner(options volume.VolumeOptions, host volume.VolumeHost) (volum
|
|||
// The direct at the specified path will be directly exposed to the container.
|
||||
type hostPath struct {
|
||||
path string
|
||||
volume.MetricsProvider
|
||||
volume.MetricsNil
|
||||
}
|
||||
|
||||
func (hp *hostPath) GetPath() string {
|
||||
|
@ -222,7 +220,7 @@ type hostPathRecycler struct {
|
|||
host volume.VolumeHost
|
||||
config volume.VolumeConfig
|
||||
timeout int64
|
||||
volume.MetricsProvider
|
||||
volume.MetricsNil
|
||||
}
|
||||
|
||||
func (r *hostPathRecycler) GetPath() string {
|
||||
|
@ -291,7 +289,7 @@ type hostPathDeleter struct {
|
|||
name string
|
||||
path string
|
||||
host volume.VolumeHost
|
||||
volume.MetricsProvider
|
||||
volume.MetricsNil
|
||||
}
|
||||
|
||||
func (r *hostPathDeleter) GetPath() string {
|
||||
|
|
|
@ -20,7 +20,6 @@ package host_path
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
@ -272,49 +271,3 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
|||
t.Errorf("Expected true for builder.IsReadOnly")
|
||||
}
|
||||
}
|
||||
|
||||
// TestMetrics tests that MetricProvider methods return sane values.
|
||||
func TestMetrics(t *testing.T) {
|
||||
// Create an empty temp directory for the volume
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "host_path_test")
|
||||
if err != nil {
|
||||
t.Fatalf("Can't make a tmp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volumetest.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/host-path")
|
||||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
}
|
||||
spec := &api.Volume{
|
||||
Name: "vol1",
|
||||
VolumeSource: api.VolumeSource{HostPath: &api.HostPathVolumeSource{Path: tmpDir}},
|
||||
}
|
||||
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
|
||||
builder, err := plug.NewBuilder(volume.NewSpecFromVolume(spec), pod, volume.VolumeOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new Builder: %v", err)
|
||||
}
|
||||
|
||||
expectedEmptyDirUsage, err := volumetest.FindEmptyDirectoryUsageOnTmpfs()
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error finding expected empty directory usage on tmpfs: %v", err)
|
||||
}
|
||||
|
||||
metrics, err := builder.GetMetrics()
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error when calling GetMetrics %v", err)
|
||||
}
|
||||
if e, a := expectedEmptyDirUsage.Value(), metrics.Used.Value(); e != a {
|
||||
t.Errorf("Unexpected value for empty directory; expected %v, got %v", e, a)
|
||||
}
|
||||
if metrics.Capacity.Value() <= 0 {
|
||||
t.Errorf("Expected Capacity to be greater than 0")
|
||||
}
|
||||
if metrics.Available.Value() <= 0 {
|
||||
t.Errorf("Expected Available to be greater than 0")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue