diff --git a/pkg/volume/empty_dir/empty_dir.go b/pkg/volume/empty_dir/empty_dir.go index ef7807601ee..e0687e4e89d 100644 --- a/pkg/volume/empty_dir/empty_dir.go +++ b/pkg/volume/empty_dir/empty_dir.go @@ -155,20 +155,12 @@ func (plugin *emptyDirPlugin) ConstructVolumeSpec(volName, mountPath string) (*v type mountDetector interface { // GetMountMedium determines what type of medium a given path is backed // by and whether that path is a mount point. For example, if this - // returns (mediumMemory, false, nil), the caller knows that the path is + // returns (v1.StorageMediumMemory, false, nil), the caller knows that the path is // on a memory FS (tmpfs on Linux) but is not the root mountpoint of // that tmpfs. - GetMountMedium(path string) (storageMedium, bool, error) + GetMountMedium(path string) (v1.StorageMedium, bool, error) } -type storageMedium int - -const ( - mediumUnknown storageMedium = 0 // assume anything we don't explicitly handle is this - mediumMemory storageMedium = 1 // memory (e.g. tmpfs on linux) - mediumHugepages storageMedium = 2 // hugepages -) - // EmptyDir volumes are temporary directories exposed to the pod. // These do not persist beyond the lifetime of a pod. type emptyDir struct { @@ -257,7 +249,7 @@ func (ed *emptyDir) setupTmpfs(dir string) error { } // If the directory is a mountpoint with medium memory, there is no // work to do since we are already in the desired state. - if isMnt && medium == mediumMemory { + if isMnt && medium == v1.StorageMediumMemory { return nil } @@ -280,7 +272,7 @@ func (ed *emptyDir) setupHugepages(dir string) error { } // If the directory is a mountpoint with medium hugepages, there is no // work to do since we are already in the desired state. - if isMnt && medium == mediumHugepages { + if isMnt && medium == v1.StorageMediumHugePages { return nil } @@ -388,10 +380,10 @@ func (ed *emptyDir) TearDownAt(dir string) error { return err } if isMnt { - if medium == mediumMemory { + if medium == v1.StorageMediumMemory { ed.medium = v1.StorageMediumMemory return ed.teardownTmpfsOrHugetlbfs(dir) - } else if medium == mediumHugepages { + } else if medium == v1.StorageMediumHugePages { ed.medium = v1.StorageMediumHugePages return ed.teardownTmpfsOrHugetlbfs(dir) } diff --git a/pkg/volume/empty_dir/empty_dir_linux.go b/pkg/volume/empty_dir/empty_dir_linux.go index e7d04fbc18f..ba289fee9fb 100644 --- a/pkg/volume/empty_dir/empty_dir_linux.go +++ b/pkg/volume/empty_dir/empty_dir_linux.go @@ -23,6 +23,8 @@ import ( "github.com/golang/glog" "golang.org/x/sys/unix" + + "k8s.io/api/core/v1" "k8s.io/kubernetes/pkg/util/mount" ) @@ -37,22 +39,22 @@ type realMountDetector struct { mounter mount.Interface } -func (m *realMountDetector) GetMountMedium(path string) (storageMedium, bool, error) { +func (m *realMountDetector) GetMountMedium(path string) (v1.StorageMedium, bool, error) { glog.V(5).Infof("Determining mount medium of %v", path) notMnt, err := m.mounter.IsLikelyNotMountPoint(path) if err != nil { - return 0, false, fmt.Errorf("IsLikelyNotMountPoint(%q): %v", path, err) + return v1.StorageMediumDefault, false, fmt.Errorf("IsLikelyNotMountPoint(%q): %v", path, err) } buf := unix.Statfs_t{} if err := unix.Statfs(path, &buf); err != nil { - return 0, false, fmt.Errorf("statfs(%q): %v", path, err) + return v1.StorageMediumDefault, false, fmt.Errorf("statfs(%q): %v", path, err) } glog.V(5).Infof("Statfs_t of %v: %+v", path, buf) if buf.Type == linuxTmpfsMagic { - return mediumMemory, !notMnt, nil + return v1.StorageMediumMemory, !notMnt, nil } else if int64(buf.Type) == linuxHugetlbfsMagic { - return mediumHugepages, !notMnt, nil + return v1.StorageMediumHugePages, !notMnt, nil } - return mediumUnknown, !notMnt, nil + return v1.StorageMediumDefault, !notMnt, nil } diff --git a/pkg/volume/empty_dir/empty_dir_test.go b/pkg/volume/empty_dir/empty_dir_test.go index cd4e9b618f0..767c0a945c8 100644 --- a/pkg/volume/empty_dir/empty_dir_test.go +++ b/pkg/volume/empty_dir/empty_dir_test.go @@ -66,11 +66,11 @@ func TestCanSupport(t *testing.T) { } type fakeMountDetector struct { - medium storageMedium + medium v1.StorageMedium isMount bool } -func (fake *fakeMountDetector) GetMountMedium(path string) (storageMedium, bool, error) { +func (fake *fakeMountDetector) GetMountMedium(path string) (v1.StorageMedium, bool, error) { return fake.medium, fake.isMount, nil } @@ -196,9 +196,9 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) { physicalMounter.ResetLog() // Make an unmounter for the volume - teardownMedium := mediumUnknown + teardownMedium := v1.StorageMediumDefault if config.medium == v1.StorageMediumMemory { - teardownMedium = mediumMemory + teardownMedium = v1.StorageMediumMemory } unmounterMountDetector := &fakeMountDetector{medium: teardownMedium, isMount: config.shouldBeMountedBeforeTeardown} unmounter, err := plug.(*emptyDirPlugin).newUnmounterInternal(volumeName, types.UID("poduid"), &physicalMounter, unmounterMountDetector) diff --git a/pkg/volume/empty_dir/empty_dir_unsupported.go b/pkg/volume/empty_dir/empty_dir_unsupported.go index c389ace7c30..defbfc5e196 100644 --- a/pkg/volume/empty_dir/empty_dir_unsupported.go +++ b/pkg/volume/empty_dir/empty_dir_unsupported.go @@ -19,6 +19,7 @@ limitations under the License. package empty_dir import ( + "k8s.io/api/core/v1" "k8s.io/kubernetes/pkg/util/mount" ) @@ -27,6 +28,6 @@ type realMountDetector struct { mounter mount.Interface } -func (m *realMountDetector) GetMountMedium(path string) (storageMedium, bool, error) { - return mediumUnknown, false, nil +func (m *realMountDetector) GetMountMedium(path string) (v1.StorageMedium, bool, error) { + return v1.StorageMediumDefault, false, nil } diff --git a/staging/src/k8s.io/api/core/v1/types.go b/staging/src/k8s.io/api/core/v1/types.go index 0951e6f64ae..5704983e979 100644 --- a/staging/src/k8s.io/api/core/v1/types.go +++ b/staging/src/k8s.io/api/core/v1/types.go @@ -1021,8 +1021,8 @@ type FlockerVolumeSource struct { type StorageMedium string const ( - StorageMediumDefault StorageMedium = "" // use whatever the default is for the node - StorageMediumMemory StorageMedium = "Memory" // use memory (tmpfs) + StorageMediumDefault StorageMedium = "" // use whatever the default is for the node, assume anything we don't explicitly handle is this + StorageMediumMemory StorageMedium = "Memory" // use memory (e.g. tmpfs on linux) StorageMediumHugePages StorageMedium = "HugePages" // use hugepages )