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
22ea7488
Commit
22ea7488
authored
Jan 05, 2018
by
xiangpengzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use consts defined in api instead of defining another ones.
parent
e99ec245
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
28 deletions
+23
-28
empty_dir.go
pkg/volume/empty_dir/empty_dir.go
+6
-14
empty_dir_linux.go
pkg/volume/empty_dir/empty_dir_linux.go
+8
-6
empty_dir_test.go
pkg/volume/empty_dir/empty_dir_test.go
+4
-4
empty_dir_unsupported.go
pkg/volume/empty_dir/empty_dir_unsupported.go
+3
-2
types.go
staging/src/k8s.io/api/core/v1/types.go
+2
-2
No files found.
pkg/volume/empty_dir/empty_dir.go
View file @
22ea7488
...
@@ -155,20 +155,12 @@ func (plugin *emptyDirPlugin) ConstructVolumeSpec(volName, mountPath string) (*v
...
@@ -155,20 +155,12 @@ func (plugin *emptyDirPlugin) ConstructVolumeSpec(volName, mountPath string) (*v
type
mountDetector
interface
{
type
mountDetector
interface
{
// GetMountMedium determines what type of medium a given path is backed
// GetMountMedium determines what type of medium a given path is backed
// by and whether that path is a mount point. For example, if this
// by and whether that path is a mount point. For example, if this
// returns (
m
ediumMemory, false, nil), the caller knows that the path is
// returns (
v1.StorageM
ediumMemory, false, nil), the caller knows that the path is
// on a memory FS (tmpfs on Linux) but is not the root mountpoint of
// on a memory FS (tmpfs on Linux) but is not the root mountpoint of
// that tmpfs.
// that tmpfs.
GetMountMedium
(
path
string
)
(
s
torageMedium
,
bool
,
error
)
GetMountMedium
(
path
string
)
(
v1
.
S
torageMedium
,
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.
// 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
{
...
@@ -257,7 +249,7 @@ func (ed *emptyDir) setupTmpfs(dir string) error {
...
@@ -257,7 +249,7 @@ func (ed *emptyDir) setupTmpfs(dir string) error {
}
}
// If the directory is a mountpoint with medium memory, there is no
// If the directory is a mountpoint with medium memory, there is no
// work to do since we are already in the desired state.
// work to do since we are already in the desired state.
if
isMnt
&&
medium
==
m
ediumMemory
{
if
isMnt
&&
medium
==
v1
.
StorageM
ediumMemory
{
return
nil
return
nil
}
}
...
@@ -280,7 +272,7 @@ func (ed *emptyDir) setupHugepages(dir string) error {
...
@@ -280,7 +272,7 @@ func (ed *emptyDir) setupHugepages(dir string) error {
}
}
// If the directory is a mountpoint with medium hugepages, there is no
// If the directory is a mountpoint with medium hugepages, there is no
// work to do since we are already in the desired state.
// work to do since we are already in the desired state.
if
isMnt
&&
medium
==
mediumHugep
ages
{
if
isMnt
&&
medium
==
v1
.
StorageMediumHugeP
ages
{
return
nil
return
nil
}
}
...
@@ -388,10 +380,10 @@ func (ed *emptyDir) TearDownAt(dir string) error {
...
@@ -388,10 +380,10 @@ func (ed *emptyDir) TearDownAt(dir string) error {
return
err
return
err
}
}
if
isMnt
{
if
isMnt
{
if
medium
==
m
ediumMemory
{
if
medium
==
v1
.
StorageM
ediumMemory
{
ed
.
medium
=
v1
.
StorageMediumMemory
ed
.
medium
=
v1
.
StorageMediumMemory
return
ed
.
teardownTmpfsOrHugetlbfs
(
dir
)
return
ed
.
teardownTmpfsOrHugetlbfs
(
dir
)
}
else
if
medium
==
mediumHugep
ages
{
}
else
if
medium
==
v1
.
StorageMediumHugeP
ages
{
ed
.
medium
=
v1
.
StorageMediumHugePages
ed
.
medium
=
v1
.
StorageMediumHugePages
return
ed
.
teardownTmpfsOrHugetlbfs
(
dir
)
return
ed
.
teardownTmpfsOrHugetlbfs
(
dir
)
}
}
...
...
pkg/volume/empty_dir/empty_dir_linux.go
View file @
22ea7488
...
@@ -23,6 +23,8 @@ import (
...
@@ -23,6 +23,8 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
"golang.org/x/sys/unix"
"golang.org/x/sys/unix"
"k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/mount"
)
)
...
@@ -37,22 +39,22 @@ type realMountDetector struct {
...
@@ -37,22 +39,22 @@ type realMountDetector struct {
mounter
mount
.
Interface
mounter
mount
.
Interface
}
}
func
(
m
*
realMountDetector
)
GetMountMedium
(
path
string
)
(
s
torageMedium
,
bool
,
error
)
{
func
(
m
*
realMountDetector
)
GetMountMedium
(
path
string
)
(
v1
.
S
torageMedium
,
bool
,
error
)
{
glog
.
V
(
5
)
.
Infof
(
"Determining mount medium of %v"
,
path
)
glog
.
V
(
5
)
.
Infof
(
"Determining mount medium of %v"
,
path
)
notMnt
,
err
:=
m
.
mounter
.
IsLikelyNotMountPoint
(
path
)
notMnt
,
err
:=
m
.
mounter
.
IsLikelyNotMountPoint
(
path
)
if
err
!=
nil
{
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
{}
buf
:=
unix
.
Statfs_t
{}
if
err
:=
unix
.
Statfs
(
path
,
&
buf
);
err
!=
nil
{
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
)
glog
.
V
(
5
)
.
Infof
(
"Statfs_t of %v: %+v"
,
path
,
buf
)
if
buf
.
Type
==
linuxTmpfsMagic
{
if
buf
.
Type
==
linuxTmpfsMagic
{
return
m
ediumMemory
,
!
notMnt
,
nil
return
v1
.
StorageM
ediumMemory
,
!
notMnt
,
nil
}
else
if
int64
(
buf
.
Type
)
==
linuxHugetlbfsMagic
{
}
else
if
int64
(
buf
.
Type
)
==
linuxHugetlbfsMagic
{
return
mediumHugep
ages
,
!
notMnt
,
nil
return
v1
.
StorageMediumHugeP
ages
,
!
notMnt
,
nil
}
}
return
mediumUnknown
,
!
notMnt
,
nil
return
v1
.
StorageMediumDefault
,
!
notMnt
,
nil
}
}
pkg/volume/empty_dir/empty_dir_test.go
View file @
22ea7488
...
@@ -66,11 +66,11 @@ func TestCanSupport(t *testing.T) {
...
@@ -66,11 +66,11 @@ func TestCanSupport(t *testing.T) {
}
}
type
fakeMountDetector
struct
{
type
fakeMountDetector
struct
{
medium
s
torageMedium
medium
v1
.
S
torageMedium
isMount
bool
isMount
bool
}
}
func
(
fake
*
fakeMountDetector
)
GetMountMedium
(
path
string
)
(
s
torageMedium
,
bool
,
error
)
{
func
(
fake
*
fakeMountDetector
)
GetMountMedium
(
path
string
)
(
v1
.
S
torageMedium
,
bool
,
error
)
{
return
fake
.
medium
,
fake
.
isMount
,
nil
return
fake
.
medium
,
fake
.
isMount
,
nil
}
}
...
@@ -196,9 +196,9 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
...
@@ -196,9 +196,9 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
physicalMounter
.
ResetLog
()
physicalMounter
.
ResetLog
()
// Make an unmounter for the volume
// Make an unmounter for the volume
teardownMedium
:=
mediumUnknown
teardownMedium
:=
v1
.
StorageMediumDefault
if
config
.
medium
==
v1
.
StorageMediumMemory
{
if
config
.
medium
==
v1
.
StorageMediumMemory
{
teardownMedium
=
m
ediumMemory
teardownMedium
=
v1
.
StorageM
ediumMemory
}
}
unmounterMountDetector
:=
&
fakeMountDetector
{
medium
:
teardownMedium
,
isMount
:
config
.
shouldBeMountedBeforeTeardown
}
unmounterMountDetector
:=
&
fakeMountDetector
{
medium
:
teardownMedium
,
isMount
:
config
.
shouldBeMountedBeforeTeardown
}
unmounter
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newUnmounterInternal
(
volumeName
,
types
.
UID
(
"poduid"
),
&
physicalMounter
,
unmounterMountDetector
)
unmounter
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newUnmounterInternal
(
volumeName
,
types
.
UID
(
"poduid"
),
&
physicalMounter
,
unmounterMountDetector
)
...
...
pkg/volume/empty_dir/empty_dir_unsupported.go
View file @
22ea7488
...
@@ -19,6 +19,7 @@ limitations under the License.
...
@@ -19,6 +19,7 @@ limitations under the License.
package
empty_dir
package
empty_dir
import
(
import
(
"k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/mount"
)
)
...
@@ -27,6 +28,6 @@ type realMountDetector struct {
...
@@ -27,6 +28,6 @@ type realMountDetector struct {
mounter
mount
.
Interface
mounter
mount
.
Interface
}
}
func
(
m
*
realMountDetector
)
GetMountMedium
(
path
string
)
(
s
torageMedium
,
bool
,
error
)
{
func
(
m
*
realMountDetector
)
GetMountMedium
(
path
string
)
(
v1
.
S
torageMedium
,
bool
,
error
)
{
return
mediumUnknown
,
false
,
nil
return
v1
.
StorageMediumDefault
,
false
,
nil
}
}
staging/src/k8s.io/api/core/v1/types.go
View file @
22ea7488
...
@@ -1021,8 +1021,8 @@ type FlockerVolumeSource struct {
...
@@ -1021,8 +1021,8 @@ type FlockerVolumeSource struct {
type
StorageMedium
string
type
StorageMedium
string
const
(
const
(
StorageMediumDefault
StorageMedium
=
""
// use whatever the default is for the node
StorageMediumDefault
StorageMedium
=
""
// use whatever the default is for the node
, assume anything we don't explicitly handle is this
StorageMediumMemory
StorageMedium
=
"Memory"
// use memory (
tmpfs
)
StorageMediumMemory
StorageMedium
=
"Memory"
// use memory (
e.g. tmpfs on linux
)
StorageMediumHugePages
StorageMedium
=
"HugePages"
// use hugepages
StorageMediumHugePages
StorageMedium
=
"HugePages"
// use hugepages
)
)
...
...
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