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
74ba0878
Commit
74ba0878
authored
May 22, 2018
by
Jan Safranek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance ExistsPath check
It should return error when the check fails (e.g. no permissions, symlink link loop etc.)
parent
7450d1b4
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
49 additions
and
46 deletions
+49
-46
container_manager_linux_test.go
pkg/kubelet/cm/container_manager_linux_test.go
+2
-2
kubelet_pods.go
pkg/kubelet/kubelet_pods.go
+1
-2
BUILD
pkg/util/mount/BUILD
+4
-0
exec_mount.go
pkg/util/mount/exec_mount.go
+1
-1
exec_mount_test.go
pkg/util/mount/exec_mount_test.go
+2
-2
exec_mount_unsupported.go
pkg/util/mount/exec_mount_unsupported.go
+2
-2
fake.go
pkg/util/mount/fake.go
+2
-2
mount.go
pkg/util/mount/mount.go
+3
-3
mount_linux.go
pkg/util/mount/mount_linux.go
+3
-6
mount_unsupported.go
pkg/util/mount/mount_unsupported.go
+2
-5
mount_windows.go
pkg/util/mount/mount_windows.go
+10
-8
nsenter_mount.go
pkg/util/mount/nsenter_mount.go
+9
-6
nsenter_mount_unsupported.go
pkg/util/mount/nsenter_mount_unsupported.go
+2
-2
removeall_test.go
pkg/util/removeall/removeall_test.go
+2
-2
host_path.go
pkg/volume/host_path/host_path.go
+2
-1
host_path_test.go
pkg/volume/host_path/host_path_test.go
+2
-2
No files found.
pkg/kubelet/cm/container_manager_linux_test.go
View file @
74ba0878
...
@@ -92,8 +92,8 @@ func (mi *fakeMountInterface) MakeFile(pathname string) error {
...
@@ -92,8 +92,8 @@ func (mi *fakeMountInterface) MakeFile(pathname string) error {
return
nil
return
nil
}
}
func
(
mi
*
fakeMountInterface
)
ExistsPath
(
pathname
string
)
bool
{
func
(
mi
*
fakeMountInterface
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
return
true
return
true
,
errors
.
New
(
"not implemented"
)
}
}
func
(
mi
*
fakeMountInterface
)
PrepareSafeSubpath
(
subPath
mount
.
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
func
(
mi
*
fakeMountInterface
)
PrepareSafeSubpath
(
subPath
mount
.
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
...
...
pkg/kubelet/kubelet_pods.go
View file @
74ba0878
...
@@ -60,7 +60,6 @@ import (
...
@@ -60,7 +60,6 @@ import (
"k8s.io/kubernetes/pkg/kubelet/status"
"k8s.io/kubernetes/pkg/kubelet/status"
kubetypes
"k8s.io/kubernetes/pkg/kubelet/types"
kubetypes
"k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/kubelet/util/format"
"k8s.io/kubernetes/pkg/kubelet/util/format"
utilfile
"k8s.io/kubernetes/pkg/util/file"
mountutil
"k8s.io/kubernetes/pkg/util/mount"
mountutil
"k8s.io/kubernetes/pkg/util/mount"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler"
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler"
...
@@ -181,7 +180,7 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h
...
@@ -181,7 +180,7 @@ func makeMounts(pod *v1.Pod, podDir string, container *v1.Container, hostName, h
}
}
hostPath
=
filepath
.
Join
(
volumePath
,
mount
.
SubPath
)
hostPath
=
filepath
.
Join
(
volumePath
,
mount
.
SubPath
)
if
subPathExists
,
err
:=
utilfile
.
FileOrSymlinkExists
(
hostPath
);
err
!=
nil
{
if
subPathExists
,
err
:=
mounter
.
ExistsPath
(
hostPath
);
err
!=
nil
{
glog
.
Errorf
(
"Could not determine if subPath %s exists; will not attempt to change its permissions"
,
hostPath
)
glog
.
Errorf
(
"Could not determine if subPath %s exists; will not attempt to change its permissions"
,
hostPath
)
}
else
if
!
subPathExists
{
}
else
if
!
subPathExists
{
// Create the sub path now because if it's auto-created later when referenced, it may have an
// Create the sub path now because if it's auto-created later when referenced, it may have an
...
...
pkg/util/mount/BUILD
View file @
74ba0878
...
@@ -72,11 +72,15 @@ go_library(
...
@@ -72,11 +72,15 @@ go_library(
"//vendor/k8s.io/utils/exec:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
] + select({
] + select({
"@io_bazel_rules_go//go/platform:linux": [
"@io_bazel_rules_go//go/platform:linux": [
"//pkg/util/file:go_default_library",
"//pkg/util/io:go_default_library",
"//pkg/util/io:go_default_library",
"//pkg/util/nsenter:go_default_library",
"//pkg/util/nsenter:go_default_library",
"//vendor/golang.org/x/sys/unix:go_default_library",
"//vendor/golang.org/x/sys/unix:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
],
],
"@io_bazel_rules_go//go/platform:windows": [
"//pkg/util/file:go_default_library",
],
"//conditions:default": [],
"//conditions:default": [],
}),
}),
)
)
...
...
pkg/util/mount/exec_mount.go
View file @
74ba0878
...
@@ -136,7 +136,7 @@ func (m *execMounter) MakeDir(pathname string) error {
...
@@ -136,7 +136,7 @@ func (m *execMounter) MakeDir(pathname string) error {
return
m
.
wrappedMounter
.
MakeDir
(
pathname
)
return
m
.
wrappedMounter
.
MakeDir
(
pathname
)
}
}
func
(
m
*
execMounter
)
ExistsPath
(
pathname
string
)
bool
{
func
(
m
*
execMounter
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
return
m
.
wrappedMounter
.
ExistsPath
(
pathname
)
return
m
.
wrappedMounter
.
ExistsPath
(
pathname
)
}
}
...
...
pkg/util/mount/exec_mount_test.go
View file @
74ba0878
...
@@ -147,8 +147,8 @@ func (fm *fakeMounter) MakeFile(pathname string) error {
...
@@ -147,8 +147,8 @@ func (fm *fakeMounter) MakeFile(pathname string) error {
func
(
fm
*
fakeMounter
)
MakeDir
(
pathname
string
)
error
{
func
(
fm
*
fakeMounter
)
MakeDir
(
pathname
string
)
error
{
return
nil
return
nil
}
}
func
(
fm
*
fakeMounter
)
ExistsPath
(
pathname
string
)
bool
{
func
(
fm
*
fakeMounter
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
return
false
return
false
,
errors
.
New
(
"not implemented"
)
}
}
func
(
fm
*
fakeMounter
)
GetFileType
(
pathname
string
)
(
FileType
,
error
)
{
func
(
fm
*
fakeMounter
)
GetFileType
(
pathname
string
)
(
FileType
,
error
)
{
return
FileTypeFile
,
nil
return
FileTypeFile
,
nil
...
...
pkg/util/mount/exec_mount_unsupported.go
View file @
74ba0878
...
@@ -83,8 +83,8 @@ func (mounter *execMounter) MakeFile(pathname string) error {
...
@@ -83,8 +83,8 @@ func (mounter *execMounter) MakeFile(pathname string) error {
return
nil
return
nil
}
}
func
(
mounter
*
execMounter
)
ExistsPath
(
pathname
string
)
bool
{
func
(
mounter
*
execMounter
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
return
true
return
true
,
errors
.
New
(
"not implemented"
)
}
}
func
(
mounter
*
execMounter
)
PrepareSafeSubpath
(
subPath
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
func
(
mounter
*
execMounter
)
PrepareSafeSubpath
(
subPath
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
...
...
pkg/util/mount/fake.go
View file @
74ba0878
...
@@ -201,8 +201,8 @@ func (f *FakeMounter) MakeFile(pathname string) error {
...
@@ -201,8 +201,8 @@ func (f *FakeMounter) MakeFile(pathname string) error {
return
nil
return
nil
}
}
func
(
f
*
FakeMounter
)
ExistsPath
(
pathname
string
)
bool
{
func
(
f
*
FakeMounter
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
return
false
return
false
,
errors
.
New
(
"not implemented"
)
}
}
func
(
f
*
FakeMounter
)
PrepareSafeSubpath
(
subPath
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
func
(
f
*
FakeMounter
)
PrepareSafeSubpath
(
subPath
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
...
...
pkg/util/mount/mount.go
View file @
74ba0878
...
@@ -91,9 +91,9 @@ type Interface interface {
...
@@ -91,9 +91,9 @@ type Interface interface {
// else. E.g. if the directory already exists, it may exists outside of the
// else. E.g. if the directory already exists, it may exists outside of the
// base due to symlinks.
// base due to symlinks.
SafeMakeDir
(
pathname
string
,
base
string
,
perm
os
.
FileMode
)
error
SafeMakeDir
(
pathname
string
,
base
string
,
perm
os
.
FileMode
)
error
//
ExistsPath checks whether the path exists
.
//
Will operate in the host mount namespace if kubelet is running in a container
.
//
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
ExistsPath
(
pathname
string
)
(
bool
,
error
)
// CleanSubPaths removes any bind-mounts created by PrepareSafeSubpath in given
// CleanSubPaths removes any bind-mounts created by PrepareSafeSubpath in given
// pod volume directory.
// pod volume directory.
CleanSubPaths
(
podDir
string
,
volumeName
string
)
error
CleanSubPaths
(
podDir
string
,
volumeName
string
)
error
...
...
pkg/util/mount/mount_linux.go
View file @
74ba0878
...
@@ -33,6 +33,7 @@ import (
...
@@ -33,6 +33,7 @@ import (
"github.com/golang/glog"
"github.com/golang/glog"
"golang.org/x/sys/unix"
"golang.org/x/sys/unix"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
utilfile
"k8s.io/kubernetes/pkg/util/file"
utilio
"k8s.io/kubernetes/pkg/util/io"
utilio
"k8s.io/kubernetes/pkg/util/io"
utilexec
"k8s.io/utils/exec"
utilexec
"k8s.io/utils/exec"
)
)
...
@@ -447,12 +448,8 @@ func (mounter *Mounter) MakeFile(pathname string) error {
...
@@ -447,12 +448,8 @@ func (mounter *Mounter) MakeFile(pathname string) error {
return
nil
return
nil
}
}
func
(
mounter
*
Mounter
)
ExistsPath
(
pathname
string
)
bool
{
func
(
mounter
*
Mounter
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
_
,
err
:=
os
.
Stat
(
pathname
)
return
utilfile
.
FileExists
(
pathname
)
if
err
!=
nil
{
return
false
}
return
true
}
}
// formatAndMount uses unix utils to format and mount the given disk
// formatAndMount uses unix utils to format and mount the given disk
...
...
pkg/util/mount/mount_unsupported.go
View file @
74ba0878
...
@@ -21,8 +21,6 @@ package mount
...
@@ -21,8 +21,6 @@ package mount
import
(
import
(
"errors"
"errors"
"os"
"os"
"github.com/golang/glog"
)
)
type
Mounter
struct
{
type
Mounter
struct
{
...
@@ -110,9 +108,8 @@ func (mounter *Mounter) MakeFile(pathname string) error {
...
@@ -110,9 +108,8 @@ func (mounter *Mounter) MakeFile(pathname string) error {
return
unsupportedErr
return
unsupportedErr
}
}
func
(
mounter
*
Mounter
)
ExistsPath
(
pathname
string
)
bool
{
func
(
mounter
*
Mounter
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
glog
.
Errorf
(
"%s"
,
unsupportedErr
)
return
true
,
errors
.
New
(
"not implemented"
)
return
true
}
}
func
(
mounter
*
Mounter
)
PrepareSafeSubpath
(
subPath
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
func
(
mounter
*
Mounter
)
PrepareSafeSubpath
(
subPath
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
...
...
pkg/util/mount/mount_windows.go
View file @
74ba0878
...
@@ -29,6 +29,8 @@ import (
...
@@ -29,6 +29,8 @@ import (
"syscall"
"syscall"
"github.com/golang/glog"
"github.com/golang/glog"
utilfile
"k8s.io/kubernetes/pkg/util/file"
)
)
// Mounter provides the default implementation of mount.Interface
// Mounter provides the default implementation of mount.Interface
...
@@ -147,9 +149,13 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
...
@@ -147,9 +149,13 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
if
stat
.
Mode
()
&
os
.
ModeSymlink
!=
0
{
if
stat
.
Mode
()
&
os
.
ModeSymlink
!=
0
{
target
,
err
:=
os
.
Readlink
(
file
)
target
,
err
:=
os
.
Readlink
(
file
)
if
err
!=
nil
{
if
err
!=
nil
{
return
true
,
fmt
.
Errorf
(
"Readlink error: %v"
,
err
)
return
true
,
fmt
.
Errorf
(
"readlink error: %v"
,
err
)
}
exists
,
err
:=
mounter
.
ExistsPath
(
target
)
if
err
!=
nil
{
return
true
,
err
}
}
return
!
mounter
.
ExistsPath
(
target
)
,
nil
return
!
exists
,
nil
}
}
return
true
,
nil
return
true
,
nil
...
@@ -232,12 +238,8 @@ func (mounter *Mounter) MakeFile(pathname string) error {
...
@@ -232,12 +238,8 @@ func (mounter *Mounter) MakeFile(pathname string) error {
}
}
// ExistsPath checks whether the path exists
// ExistsPath checks whether the path exists
func
(
mounter
*
Mounter
)
ExistsPath
(
pathname
string
)
bool
{
func
(
mounter
*
Mounter
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
_
,
err
:=
os
.
Stat
(
pathname
)
return
utilfile
.
FileExists
(
pathname
)
if
err
!=
nil
{
return
false
}
return
true
}
}
// check whether hostPath is within volume path
// check whether hostPath is within volume path
...
...
pkg/util/mount/nsenter_mount.go
View file @
74ba0878
...
@@ -27,6 +27,7 @@ import (
...
@@ -27,6 +27,7 @@ import (
"strings"
"strings"
"github.com/golang/glog"
"github.com/golang/glog"
utilfile
"k8s.io/kubernetes/pkg/util/file"
utilio
"k8s.io/kubernetes/pkg/util/io"
utilio
"k8s.io/kubernetes/pkg/util/io"
"k8s.io/kubernetes/pkg/util/nsenter"
"k8s.io/kubernetes/pkg/util/nsenter"
)
)
...
@@ -281,13 +282,15 @@ func (mounter *NsenterMounter) MakeFile(pathname string) error {
...
@@ -281,13 +282,15 @@ func (mounter *NsenterMounter) MakeFile(pathname string) error {
return
nil
return
nil
}
}
func
(
mounter
*
NsenterMounter
)
ExistsPath
(
pathname
string
)
bool
{
func
(
mounter
*
NsenterMounter
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
args
:=
[]
string
{
pathname
}
// Resolve the symlinks but allow the target not to exist. EvalSymlinks
_
,
err
:=
mounter
.
ne
.
Exec
(
"ls"
,
args
)
.
CombinedOutput
()
// would return an generic error when the target does not exist.
if
err
==
nil
{
hostPath
,
err
:=
mounter
.
ne
.
EvalSymlinks
(
pathname
,
false
/* mustExist */
)
return
true
if
err
!=
nil
{
return
false
,
err
}
}
return
false
kubeletpath
:=
mounter
.
ne
.
KubeletPath
(
hostPath
)
return
utilfile
.
FileExists
(
kubeletpath
)
}
}
func
(
mounter
*
NsenterMounter
)
CleanSubPaths
(
podDir
string
,
volumeName
string
)
error
{
func
(
mounter
*
NsenterMounter
)
CleanSubPaths
(
podDir
string
,
volumeName
string
)
error
{
...
...
pkg/util/mount/nsenter_mount_unsupported.go
View file @
74ba0878
...
@@ -83,8 +83,8 @@ func (*NsenterMounter) MakeFile(pathname string) error {
...
@@ -83,8 +83,8 @@ func (*NsenterMounter) MakeFile(pathname string) error {
return
nil
return
nil
}
}
func
(
*
NsenterMounter
)
ExistsPath
(
pathname
string
)
bool
{
func
(
*
NsenterMounter
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
return
true
return
true
,
errors
.
New
(
"not implemented"
)
}
}
func
(
*
NsenterMounter
)
SafeMakeDir
(
pathname
string
,
base
string
,
perm
os
.
FileMode
)
error
{
func
(
*
NsenterMounter
)
SafeMakeDir
(
pathname
string
,
base
string
,
perm
os
.
FileMode
)
error
{
...
...
pkg/util/removeall/removeall_test.go
View file @
74ba0878
...
@@ -75,8 +75,8 @@ func (mounter *fakeMounter) MakeFile(pathname string) error {
...
@@ -75,8 +75,8 @@ func (mounter *fakeMounter) MakeFile(pathname string) error {
return
nil
return
nil
}
}
func
(
mounter
*
fakeMounter
)
ExistsPath
(
pathname
string
)
bool
{
func
(
mounter
*
fakeMounter
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
return
true
return
true
,
errors
.
New
(
"not implemented"
)
}
}
func
(
mounter
*
fakeMounter
)
PrepareSafeSubpath
(
subPath
mount
.
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
func
(
mounter
*
fakeMounter
)
PrepareSafeSubpath
(
subPath
mount
.
Subpath
)
(
newHostPath
string
,
cleanupAction
func
(),
err
error
)
{
...
...
pkg/volume/host_path/host_path.go
View file @
74ba0878
...
@@ -350,7 +350,8 @@ type fileTypeChecker struct {
...
@@ -350,7 +350,8 @@ type fileTypeChecker struct {
}
}
func
(
ftc
*
fileTypeChecker
)
Exists
()
bool
{
func
(
ftc
*
fileTypeChecker
)
Exists
()
bool
{
return
ftc
.
mounter
.
ExistsPath
(
ftc
.
path
)
exists
,
err
:=
ftc
.
mounter
.
ExistsPath
(
ftc
.
path
)
return
exists
&&
err
==
nil
}
}
func
(
ftc
*
fileTypeChecker
)
IsFile
()
bool
{
func
(
ftc
*
fileTypeChecker
)
IsFile
()
bool
{
...
...
pkg/volume/host_path/host_path_test.go
View file @
74ba0878
...
@@ -369,8 +369,8 @@ func (fftc *fakeFileTypeChecker) MakeDir(pathname string) error {
...
@@ -369,8 +369,8 @@ func (fftc *fakeFileTypeChecker) MakeDir(pathname string) error {
return
nil
return
nil
}
}
func
(
fftc
*
fakeFileTypeChecker
)
ExistsPath
(
pathname
string
)
bool
{
func
(
fftc
*
fakeFileTypeChecker
)
ExistsPath
(
pathname
string
)
(
bool
,
error
)
{
return
true
return
true
,
nil
}
}
func
(
fftc
*
fakeFileTypeChecker
)
GetFileType
(
_
string
)
(
utilmount
.
FileType
,
error
)
{
func
(
fftc
*
fakeFileTypeChecker
)
GetFileType
(
_
string
)
(
utilmount
.
FileType
,
error
)
{
...
...
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