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
704573d3
Commit
704573d3
authored
Sep 17, 2018
by
David Zhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GetMountRefs shouldn't error when file doesn'g exist in Windows and nsenter. Add unit test
parent
9d207b3e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
0 deletions
+18
-0
mount_linux.go
pkg/util/mount/mount_linux.go
+2
-0
mount_linux_test.go
pkg/util/mount/mount_linux_test.go
+4
-0
mount_windows.go
pkg/util/mount/mount_windows.go
+5
-0
nsenter_mount.go
pkg/util/mount/nsenter_mount.go
+7
-0
No files found.
pkg/util/mount/mount_linux.go
View file @
704573d3
...
@@ -1007,6 +1007,8 @@ func (mounter *Mounter) SafeMakeDir(subdir string, base string, perm os.FileMode
...
@@ -1007,6 +1007,8 @@ func (mounter *Mounter) SafeMakeDir(subdir string, base string, perm os.FileMode
func
(
mounter
*
Mounter
)
GetMountRefs
(
pathname
string
)
([]
string
,
error
)
{
func
(
mounter
*
Mounter
)
GetMountRefs
(
pathname
string
)
([]
string
,
error
)
{
if
_
,
err
:=
os
.
Stat
(
pathname
);
os
.
IsNotExist
(
err
)
{
if
_
,
err
:=
os
.
Stat
(
pathname
);
os
.
IsNotExist
(
err
)
{
return
[]
string
{},
nil
return
[]
string
{},
nil
}
else
if
err
!=
nil
{
return
nil
,
err
}
}
realpath
,
err
:=
filepath
.
EvalSymlinks
(
pathname
)
realpath
,
err
:=
filepath
.
EvalSymlinks
(
pathname
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/util/mount/mount_linux_test.go
View file @
704573d3
...
@@ -110,6 +110,10 @@ func TestGetMountRefs(t *testing.T) {
...
@@ -110,6 +110,10 @@ func TestGetMountRefs(t *testing.T) {
"/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd2"
,
"/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd2"
,
},
},
},
},
{
"/var/fake/directory/that/doesnt/exist"
,
[]
string
{},
},
}
}
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
...
...
pkg/util/mount/mount_windows.go
View file @
704573d3
...
@@ -459,6 +459,11 @@ func getAllParentLinks(path string) ([]string, error) {
...
@@ -459,6 +459,11 @@ func getAllParentLinks(path string) ([]string, error) {
}
}
func
(
mounter
*
Mounter
)
GetMountRefs
(
pathname
string
)
([]
string
,
error
)
{
func
(
mounter
*
Mounter
)
GetMountRefs
(
pathname
string
)
([]
string
,
error
)
{
if
_
,
err
:=
os
.
Stat
(
normalizeWindowsPath
(
pathname
));
os
.
IsNotExist
(
err
)
{
return
[]
string
{},
nil
}
else
if
err
!=
nil
{
return
nil
,
err
}
refs
,
err
:=
getAllParentLinks
(
normalizeWindowsPath
(
pathname
))
refs
,
err
:=
getAllParentLinks
(
normalizeWindowsPath
(
pathname
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
pkg/util/mount/nsenter_mount.go
View file @
704573d3
...
@@ -337,6 +337,13 @@ func (mounter *NsenterMounter) SafeMakeDir(subdir string, base string, perm os.F
...
@@ -337,6 +337,13 @@ func (mounter *NsenterMounter) SafeMakeDir(subdir string, base string, perm os.F
}
}
func
(
mounter
*
NsenterMounter
)
GetMountRefs
(
pathname
string
)
([]
string
,
error
)
{
func
(
mounter
*
NsenterMounter
)
GetMountRefs
(
pathname
string
)
([]
string
,
error
)
{
exists
,
err
:=
mounter
.
ExistsPath
(
pathname
)
if
err
!=
nil
{
return
nil
,
err
}
if
!
exists
{
return
[]
string
{},
nil
}
hostpath
,
err
:=
mounter
.
ne
.
EvalSymlinks
(
pathname
,
true
/* mustExist */
)
hostpath
,
err
:=
mounter
.
ne
.
EvalSymlinks
(
pathname
,
true
/* mustExist */
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
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