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
b376b31e
Commit
b376b31e
authored
Jun 26, 2018
by
Matthew Wong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve potential devicePath symlink when MapVolume in containerized kubelet
parent
4905c339
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
46 additions
and
0 deletions
+46
-0
exec_mount.go
pkg/util/mount/exec_mount.go
+4
-0
exec_mount_unsupported.go
pkg/util/mount/exec_mount_unsupported.go
+4
-0
fake.go
pkg/util/mount/fake.go
+4
-0
mount.go
pkg/util/mount/mount.go
+3
-0
mount_linux.go
pkg/util/mount/mount_linux.go
+4
-0
mount_unsupported.go
pkg/util/mount/mount_unsupported.go
+4
-0
mount_windows.go
pkg/util/mount/mount_windows.go
+5
-0
nsenter_mount.go
pkg/util/mount/nsenter_mount.go
+4
-0
nsenter_mount_unsupported.go
pkg/util/mount/nsenter_mount_unsupported.go
+4
-0
operation_generator.go
pkg/volume/util/operationexecutor/operation_generator.go
+10
-0
No files found.
pkg/util/mount/exec_mount.go
View file @
b376b31e
...
...
@@ -140,6 +140,10 @@ func (m *execMounter) ExistsPath(pathname string) (bool, error) {
return
m
.
wrappedMounter
.
ExistsPath
(
pathname
)
}
func
(
m
*
execMounter
)
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
{
return
m
.
wrappedMounter
.
EvalHostSymlinks
(
pathname
)
}
func
(
m
*
execMounter
)
PrepareSafeSubpath
(
subPath
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
return
m
.
wrappedMounter
.
PrepareSafeSubpath
(
subPath
)
}
...
...
pkg/util/mount/exec_mount_unsupported.go
View file @
b376b31e
...
...
@@ -87,6 +87,10 @@ func (mounter *execMounter) ExistsPath(pathname string) (bool, error) {
return
true
,
errors
.
New
(
"not implemented"
)
}
func
(
m
*
execMounter
)
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
{
return
""
,
errors
.
New
(
"not implemented"
)
}
func
(
mounter
*
execMounter
)
PrepareSafeSubpath
(
subPath
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
return
subPath
.
Path
,
nil
,
nil
}
...
...
pkg/util/mount/fake.go
View file @
b376b31e
...
...
@@ -212,6 +212,10 @@ func (f *FakeMounter) ExistsPath(pathname string) (bool, error) {
return
false
,
nil
}
func
(
f
*
FakeMounter
)
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
{
return
pathname
,
nil
}
func
(
f
*
FakeMounter
)
PrepareSafeSubpath
(
subPath
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
return
subPath
.
Path
,
nil
,
nil
}
...
...
pkg/util/mount/mount.go
View file @
b376b31e
...
...
@@ -96,6 +96,9 @@ type Interface interface {
// Will operate in the host mount namespace if kubelet is running in a container.
// Error is returned on any other error than "file not found".
ExistsPath
(
pathname
string
)
(
bool
,
error
)
// EvalHostSymlinks returns the path name after evaluating symlinks.
// Will operate in the host mount namespace if kubelet is running in a container.
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
// CleanSubPaths removes any bind-mounts created by PrepareSafeSubpath in given
// pod volume directory.
CleanSubPaths
(
podDir
string
,
volumeName
string
)
error
...
...
pkg/util/mount/mount_linux.go
View file @
b376b31e
...
...
@@ -419,6 +419,10 @@ func (mounter *Mounter) ExistsPath(pathname string) (bool, error) {
return
utilfile
.
FileExists
(
pathname
)
}
func
(
mounter
*
Mounter
)
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
{
return
filepath
.
EvalSymlinks
(
pathname
)
}
// formatAndMount uses unix utils to format and mount the given disk
func
(
mounter
*
SafeFormatAndMount
)
formatAndMount
(
source
string
,
target
string
,
fstype
string
,
options
[]
string
)
error
{
readOnly
:=
false
...
...
pkg/util/mount/mount_unsupported.go
View file @
b376b31e
...
...
@@ -106,6 +106,10 @@ func (mounter *Mounter) ExistsPath(pathname string) (bool, error) {
return
true
,
errors
.
New
(
"not implemented"
)
}
func
(
mounter
*
Mounter
)
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
{
return
""
,
unsupportedErr
}
func
(
mounter
*
Mounter
)
PrepareSafeSubpath
(
subPath
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
return
subPath
.
Path
,
nil
,
unsupportedErr
}
...
...
pkg/util/mount/mount_windows.go
View file @
b376b31e
...
...
@@ -232,6 +232,11 @@ func (mounter *Mounter) ExistsPath(pathname string) (bool, error) {
return
utilfile
.
FileExists
(
pathname
)
}
// EvalHostSymlinks returns the path name after evaluating symlinks
func
(
mounter
*
Mounter
)
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
{
return
filepath
.
EvalSymlinks
(
pathname
)
}
// check whether hostPath is within volume path
// this func will lock all intermediate subpath directories, need to close handle outside of this func after container started
func
lockAndCheckSubPath
(
volumePath
,
hostPath
string
)
([]
uintptr
,
error
)
{
...
...
pkg/util/mount/nsenter_mount.go
View file @
b376b31e
...
...
@@ -287,6 +287,10 @@ func (mounter *NsenterMounter) ExistsPath(pathname string) (bool, error) {
return
utilfile
.
FileExists
(
kubeletpath
)
}
func
(
mounter
*
NsenterMounter
)
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
{
return
mounter
.
ne
.
EvalSymlinks
(
pathname
,
true
)
}
func
(
mounter
*
NsenterMounter
)
CleanSubPaths
(
podDir
string
,
volumeName
string
)
error
{
return
doCleanSubPaths
(
mounter
,
podDir
,
volumeName
)
}
...
...
pkg/util/mount/nsenter_mount_unsupported.go
View file @
b376b31e
...
...
@@ -89,6 +89,10 @@ func (*NsenterMounter) ExistsPath(pathname string) (bool, error) {
return
true
,
errors
.
New
(
"not implemented"
)
}
func
(
*
NsenterMounter
)
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
{
return
""
,
errors
.
New
(
"not implemented"
)
}
func
(
*
NsenterMounter
)
SafeMakeDir
(
pathname
string
,
base
string
,
perm
os
.
FileMode
)
error
{
return
nil
}
...
...
pkg/volume/util/operationexecutor/operation_generator.go
View file @
b376b31e
...
...
@@ -866,6 +866,16 @@ func (og *operationGenerator) GenerateMapVolumeFunc(
return
volumeToMount
.
GenerateError
(
"MapVolume failed"
,
fmt
.
Errorf
(
"Device path of the volume is empty"
))
}
// When kubelet is containerized, devicePath may be a symlink at a place unavailable to
// kubelet, so evaluate it on the host and expect that it links to a device in /dev,
// which will be available to containerized kubelet. If still it does not exist,
// AttachFileDevice will fail. If kubelet is not containerized, eval it anyway.
mounter
:=
og
.
GetVolumePluginMgr
()
.
Host
.
GetMounter
(
blockVolumePlugin
.
GetPluginName
())
devicePath
,
err
=
mounter
.
EvalHostSymlinks
(
devicePath
)
if
err
!=
nil
{
return
volumeToMount
.
GenerateError
(
"MapVolume.EvalHostSymlinks failed"
,
err
)
}
// Map device to global and pod device map path
volumeMapPath
,
volName
:=
blockVolumeMapper
.
GetPodDeviceMapPath
()
mapErr
=
blockVolumeMapper
.
MapDevice
(
devicePath
,
globalMapPath
,
volumeMapPath
,
volName
,
volumeToMount
.
Pod
.
UID
)
...
...
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