Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b42652cd
Commit
b42652cd
authored
Mar 16, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Retool mount detection for tests
parent
1725c23e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
63 deletions
+75
-63
empty_dir.go
pkg/kubelet/volume/empty_dir/empty_dir.go
+45
-40
empty_dir_linux.go
pkg/kubelet/volume/empty_dir/empty_dir_linux.go
+12
-6
empty_dir_test.go
pkg/kubelet/volume/empty_dir/empty_dir_test.go
+14
-13
empty_dir_unsupported.go
pkg/kubelet/volume/empty_dir/empty_dir_unsupported.go
+4
-4
No files found.
pkg/kubelet/volume/empty_dir/empty_dir.go
View file @
b42652cd
...
@@ -82,10 +82,10 @@ func (plugin *emptyDirPlugin) CanSupport(spec *api.Volume) bool {
...
@@ -82,10 +82,10 @@ func (plugin *emptyDirPlugin) CanSupport(spec *api.Volume) bool {
func
(
plugin
*
emptyDirPlugin
)
NewBuilder
(
spec
*
api
.
Volume
,
podRef
*
api
.
ObjectReference
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
emptyDirPlugin
)
NewBuilder
(
spec
*
api
.
Volume
,
podRef
*
api
.
ObjectReference
)
(
volume
.
Builder
,
error
)
{
// Inject real implementations here, test through the internal function.
// Inject real implementations here, test through the internal function.
return
plugin
.
newBuilderInternal
(
spec
,
podRef
,
plugin
.
mounter
,
&
realM
ediume
r
{})
return
plugin
.
newBuilderInternal
(
spec
,
podRef
,
plugin
.
mounter
,
&
realM
ountDetecto
r
{})
}
}
func
(
plugin
*
emptyDirPlugin
)
newBuilderInternal
(
spec
*
api
.
Volume
,
podRef
*
api
.
ObjectReference
,
mounter
mount
.
Interface
,
m
ediumer
mediume
r
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
emptyDirPlugin
)
newBuilderInternal
(
spec
*
api
.
Volume
,
podRef
*
api
.
ObjectReference
,
mounter
mount
.
Interface
,
m
ountDetector
mountDetecto
r
)
(
volume
.
Builder
,
error
)
{
if
plugin
.
legacyMode
{
if
plugin
.
legacyMode
{
// Legacy mode instances can be cleaned up but not created anew.
// Legacy mode instances can be cleaned up but not created anew.
return
nil
,
fmt
.
Errorf
(
"legacy mode: can not create new instances"
)
return
nil
,
fmt
.
Errorf
(
"legacy mode: can not create new instances"
)
...
@@ -95,41 +95,46 @@ func (plugin *emptyDirPlugin) newBuilderInternal(spec *api.Volume, podRef *api.O
...
@@ -95,41 +95,46 @@ func (plugin *emptyDirPlugin) newBuilderInternal(spec *api.Volume, podRef *api.O
medium
=
spec
.
EmptyDir
.
Medium
medium
=
spec
.
EmptyDir
.
Medium
}
}
return
&
emptyDir
{
return
&
emptyDir
{
podUID
:
podRef
.
UID
,
podUID
:
podRef
.
UID
,
volName
:
spec
.
Name
,
volName
:
spec
.
Name
,
medium
:
medium
,
medium
:
medium
,
mounter
:
mounter
,
mounter
:
mounter
,
m
ediumer
:
mediume
r
,
m
ountDetector
:
mountDetecto
r
,
plugin
:
plugin
,
plugin
:
plugin
,
legacyMode
:
false
,
legacyMode
:
false
,
},
nil
},
nil
}
}
func
(
plugin
*
emptyDirPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
)
(
volume
.
Cleaner
,
error
)
{
func
(
plugin
*
emptyDirPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
)
(
volume
.
Cleaner
,
error
)
{
// Inject real implementations here, test through the internal function.
// Inject real implementations here, test through the internal function.
return
plugin
.
newCleanerInternal
(
volName
,
podUID
,
plugin
.
mounter
,
&
realM
ediume
r
{})
return
plugin
.
newCleanerInternal
(
volName
,
podUID
,
plugin
.
mounter
,
&
realM
ountDetecto
r
{})
}
}
func
(
plugin
*
emptyDirPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
,
m
ediumer
mediume
r
)
(
volume
.
Cleaner
,
error
)
{
func
(
plugin
*
emptyDirPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
,
m
ountDetector
mountDetecto
r
)
(
volume
.
Cleaner
,
error
)
{
legacy
:=
false
legacy
:=
false
if
plugin
.
legacyMode
{
if
plugin
.
legacyMode
{
legacy
=
true
legacy
=
true
}
}
ed
:=
&
emptyDir
{
ed
:=
&
emptyDir
{
podUID
:
podUID
,
podUID
:
podUID
,
volName
:
volName
,
volName
:
volName
,
medium
:
api
.
StorageTypeDefault
,
// might be changed later
medium
:
api
.
StorageTypeDefault
,
// might be changed later
mounter
:
mounter
,
mounter
:
mounter
,
m
ediumer
:
mediume
r
,
m
ountDetector
:
mountDetecto
r
,
plugin
:
plugin
,
plugin
:
plugin
,
legacyMode
:
legacy
,
legacyMode
:
legacy
,
}
}
return
ed
,
nil
return
ed
,
nil
}
}
// mediumer abstracts how to find what storageMedium a path is backed by.
// mountDetector abstracts how to find what kind of mount a path is backed by.
type
mediumer
interface
{
type
mountDetector
interface
{
GetMedium
(
path
string
)
(
storageMedium
,
error
)
// 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
// on a memory FS (tmpfs on Linux) but is not the root mountpoint of
// that tmpfs.
GetMountMedium
(
path
string
)
(
storageMedium
,
bool
,
error
)
}
}
type
storageMedium
int
type
storageMedium
int
...
@@ -142,13 +147,13 @@ const (
...
@@ -142,13 +147,13 @@ const (
// EmptyDir volumes are temporary directories exposed to the pod.
// EmptyDir volumes are temporary directories exposed to the pod.
// These do not persist beyond the lifetime of a pod.
// These do not persist beyond the lifetime of a pod.
type
emptyDir
struct
{
type
emptyDir
struct
{
podUID
types
.
UID
podUID
types
.
UID
volName
string
volName
string
medium
api
.
StorageType
medium
api
.
StorageType
mounter
mount
.
Interface
mounter
mount
.
Interface
m
ediumer
mediume
r
m
ountDetector
mountDetecto
r
plugin
*
emptyDirPlugin
plugin
*
emptyDirPlugin
legacyMode
bool
legacyMode
bool
}
}
// SetUp creates new directory.
// SetUp creates new directory.
...
@@ -183,9 +188,11 @@ func (ed *emptyDir) setupTmpfs(dir string) error {
...
@@ -183,9 +188,11 @@ func (ed *emptyDir) setupTmpfs(dir string) error {
return
err
return
err
}
}
// Make SetUp idempotent.
// Make SetUp idempotent.
if
medium
,
err
:=
ed
.
mediumer
.
GetMedium
(
dir
);
err
!=
nil
{
medium
,
isMnt
,
err
:=
ed
.
mountDetector
.
GetMountMedium
(
dir
)
if
err
!=
nil
{
return
err
return
err
}
else
if
medium
==
mediumMemory
{
}
if
isMnt
&&
medium
==
mediumMemory
{
return
nil
// current state is what we expect
return
nil
// current state is what we expect
}
}
return
ed
.
mounter
.
Mount
(
"tmpfs"
,
dir
,
"tmpfs"
,
0
,
""
)
return
ed
.
mounter
.
Mount
(
"tmpfs"
,
dir
,
"tmpfs"
,
0
,
""
)
...
@@ -207,18 +214,16 @@ func (ed *emptyDir) TearDown() error {
...
@@ -207,18 +214,16 @@ func (ed *emptyDir) TearDown() error {
// TearDownAt simply discards everything in the directory.
// TearDownAt simply discards everything in the directory.
func
(
ed
*
emptyDir
)
TearDownAt
(
dir
string
)
error
{
func
(
ed
*
emptyDir
)
TearDownAt
(
dir
string
)
error
{
// Figure out the medium.
// Figure out the medium.
if
medium
,
err
:=
ed
.
mediumer
.
GetMedium
(
dir
);
err
!=
nil
{
medium
,
isMnt
,
err
:=
ed
.
mountDetector
.
GetMountMedium
(
dir
)
if
err
!=
nil
{
return
err
return
err
}
else
{
switch
medium
{
case
mediumMemory
:
ed
.
medium
=
api
.
StorageTypeMemory
return
ed
.
teardownTmpfs
(
dir
)
default
:
// assume StorageTypeDefault
return
ed
.
teardownDefault
(
dir
)
}
}
}
if
isMnt
&&
medium
==
mediumMemory
{
ed
.
medium
=
api
.
StorageTypeMemory
return
ed
.
teardownTmpfs
(
dir
)
}
// assume StorageTypeDefault
return
ed
.
teardownDefault
(
dir
)
}
}
func
(
ed
*
emptyDir
)
teardownDefault
(
dir
string
)
error
{
func
(
ed
*
emptyDir
)
teardownDefault
(
dir
string
)
error
{
...
...
pkg/kubelet/volume/empty_dir/empty_dir_linux.go
View file @
b42652cd
...
@@ -19,21 +19,27 @@ package empty_dir
...
@@ -19,21 +19,27 @@ package empty_dir
import
(
import
(
"fmt"
"fmt"
"syscall"
"syscall"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
)
)
// Defined by Linux - the type number for tmpfs mounts.
// Defined by Linux - the type number for tmpfs mounts.
const
linuxTmpfsMagic
=
0x01021994
const
linuxTmpfsMagic
=
0x01021994
// realM
ediumer implements mediume
r in terms of syscalls.
// realM
ountDetector implements mountDetecto
r in terms of syscalls.
type
realM
ediume
r
struct
{}
type
realM
ountDetecto
r
struct
{}
func
(
m
*
realMediumer
)
GetMedium
(
path
string
)
(
storageMedium
,
error
)
{
func
(
m
*
realMountDetector
)
GetMountMedium
(
path
string
)
(
storageMedium
,
bool
,
error
)
{
isMnt
,
err
:=
mount
.
IsMountPoint
(
path
)
if
err
!=
nil
{
return
0
,
false
,
fmt
.
Errorf
(
"IsMountPoint(%q): %v"
,
path
,
err
)
}
buf
:=
syscall
.
Statfs_t
{}
buf
:=
syscall
.
Statfs_t
{}
if
err
:=
syscall
.
Statfs
(
path
,
&
buf
);
err
!=
nil
{
if
err
:=
syscall
.
Statfs
(
path
,
&
buf
);
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"statfs(%q): %v"
,
path
,
err
)
return
0
,
f
alse
,
f
mt
.
Errorf
(
"statfs(%q): %v"
,
path
,
err
)
}
}
if
buf
.
Type
==
linuxTmpfsMagic
{
if
buf
.
Type
==
linuxTmpfsMagic
{
return
mediumMemory
,
nil
return
mediumMemory
,
isMnt
,
nil
}
}
return
mediumUnknown
,
nil
return
mediumUnknown
,
isMnt
,
nil
}
}
pkg/kubelet/volume/empty_dir/empty_dir_test.go
View file @
b42652cd
...
@@ -56,12 +56,13 @@ func TestCanSupport(t *testing.T) {
...
@@ -56,12 +56,13 @@ func TestCanSupport(t *testing.T) {
}
}
}
}
type
fakeMediumer
struct
{
type
fakeMountDetector
struct
{
typeToReturn
storageMedium
medium
storageMedium
isMount
bool
}
}
func
(
fake
*
fakeM
ediumer
)
GetMedium
(
path
string
)
(
storageMedium
,
error
)
{
func
(
fake
*
fakeM
ountDetector
)
GetMountMedium
(
path
string
)
(
storageMedium
,
bool
,
error
)
{
return
fake
.
typeToReturn
,
nil
return
fake
.
medium
,
fake
.
isMount
,
nil
}
}
func
TestPlugin
(
t
*
testing
.
T
)
{
func
TestPlugin
(
t
*
testing
.
T
)
{
...
@@ -72,8 +73,8 @@ func TestPlugin(t *testing.T) {
...
@@ -72,8 +73,8 @@ func TestPlugin(t *testing.T) {
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{
Medium
:
api
.
StorageTypeDefault
}},
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{
Medium
:
api
.
StorageTypeDefault
}},
}
}
mounter
:=
mount
.
FakeMounter
{}
mounter
:=
mount
.
FakeMounter
{}
m
ediumer
:=
fakeMediume
r
{}
m
ountDetector
:=
fakeMountDetecto
r
{}
builder
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
spec
,
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
&
mounter
,
&
m
ediume
r
)
builder
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
spec
,
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
&
mounter
,
&
m
ountDetecto
r
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
}
...
@@ -101,7 +102,7 @@ func TestPlugin(t *testing.T) {
...
@@ -101,7 +102,7 @@ func TestPlugin(t *testing.T) {
}
}
mounter
.
ResetLog
()
mounter
.
ResetLog
()
cleaner
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newCleanerInternal
(
"vol1"
,
types
.
UID
(
"poduid"
),
&
mounter
,
&
fakeM
ediume
r
{})
cleaner
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newCleanerInternal
(
"vol1"
,
types
.
UID
(
"poduid"
),
&
mounter
,
&
fakeM
ountDetecto
r
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
}
}
...
@@ -131,8 +132,8 @@ func TestPluginTmpfs(t *testing.T) {
...
@@ -131,8 +132,8 @@ func TestPluginTmpfs(t *testing.T) {
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{
Medium
:
api
.
StorageTypeMemory
}},
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{
Medium
:
api
.
StorageTypeMemory
}},
}
}
mounter
:=
mount
.
FakeMounter
{}
mounter
:=
mount
.
FakeMounter
{}
m
ediumer
:=
fakeMediume
r
{}
m
ountDetector
:=
fakeMountDetecto
r
{}
builder
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
spec
,
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
&
mounter
,
&
m
ediume
r
)
builder
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
spec
,
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
&
mounter
,
&
m
ountDetecto
r
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
}
}
...
@@ -164,7 +165,7 @@ func TestPluginTmpfs(t *testing.T) {
...
@@ -164,7 +165,7 @@ func TestPluginTmpfs(t *testing.T) {
}
}
mounter
.
ResetLog
()
mounter
.
ResetLog
()
cleaner
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newCleanerInternal
(
"vol1"
,
types
.
UID
(
"poduid"
),
&
mounter
,
&
fakeM
ediumer
{
mediumMemory
})
cleaner
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newCleanerInternal
(
"vol1"
,
types
.
UID
(
"poduid"
),
&
mounter
,
&
fakeM
ountDetector
{
mediumMemory
,
true
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
}
}
...
@@ -181,7 +182,7 @@ func TestPluginTmpfs(t *testing.T) {
...
@@ -181,7 +182,7 @@ func TestPluginTmpfs(t *testing.T) {
t
.
Errorf
(
"SetUp() failed: %v"
,
err
)
t
.
Errorf
(
"SetUp() failed: %v"
,
err
)
}
}
if
len
(
mounter
.
Log
)
!=
1
{
if
len
(
mounter
.
Log
)
!=
1
{
t
.
Errorf
(
"Expected 1 mounter call, got %
#v"
,
mounter
.
Log
)
t
.
Errorf
(
"Expected 1 mounter call, got %
d (%v)"
,
len
(
mounter
.
Log
)
,
mounter
.
Log
)
}
else
{
}
else
{
if
mounter
.
Log
[
0
]
.
Action
!=
mount
.
FakeActionUnmount
{
if
mounter
.
Log
[
0
]
.
Action
!=
mount
.
FakeActionUnmount
{
t
.
Errorf
(
"Unexpected mounter action: %#v"
,
mounter
.
Log
[
0
])
t
.
Errorf
(
"Unexpected mounter action: %#v"
,
mounter
.
Log
[
0
])
...
@@ -221,11 +222,11 @@ func TestPluginLegacy(t *testing.T) {
...
@@ -221,11 +222,11 @@ func TestPluginLegacy(t *testing.T) {
}
}
spec
:=
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}}}
spec
:=
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}}}
if
_
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
&
spec
,
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
&
mount
.
FakeMounter
{},
&
fakeM
ediume
r
{});
err
==
nil
{
if
_
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
&
spec
,
&
api
.
ObjectReference
{
UID
:
types
.
UID
(
"poduid"
)},
&
mount
.
FakeMounter
{},
&
fakeM
ountDetecto
r
{});
err
==
nil
{
t
.
Errorf
(
"Expected failiure"
)
t
.
Errorf
(
"Expected failiure"
)
}
}
cleaner
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newCleanerInternal
(
"vol1"
,
types
.
UID
(
"poduid"
),
&
mount
.
FakeMounter
{},
&
fakeM
ediume
r
{})
cleaner
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newCleanerInternal
(
"vol1"
,
types
.
UID
(
"poduid"
),
&
mount
.
FakeMounter
{},
&
fakeM
ountDetecto
r
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
}
}
...
...
pkg/kubelet/volume/empty_dir/empty_dir_unsupported.go
View file @
b42652cd
...
@@ -18,9 +18,9 @@ limitations under the License.
...
@@ -18,9 +18,9 @@ limitations under the License.
package
empty_dir
package
empty_dir
// realM
ediume
r pretends to implement mediumer.
// realM
ountDetecto
r pretends to implement mediumer.
type
realM
ediume
r
struct
{}
type
realM
ountDetecto
r
struct
{}
func
(
m
*
realM
ediumer
)
GetMedium
(
path
string
)
(
storageMedium
,
error
)
{
func
(
m
*
realM
ountDetector
)
GetMountMedium
(
path
string
)
(
storageMedium
,
bool
,
error
)
{
return
mediumUnknown
,
nil
return
mediumUnknown
,
false
,
nil
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment