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
32a49828
Unverified
Commit
32a49828
authored
Apr 17, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Apr 17, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #76456 from codenrhoden/mv-exec-mounter
Move ExecMount to pkg/volume/util/exec
parents
23e6f803
96476fd0
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
114 additions
and
32 deletions
+114
-32
BUILD
pkg/kubelet/BUILD
+1
-0
volume_host.go
pkg/kubelet/volume_host.go
+2
-1
BUILD
pkg/util/mount/BUILD
+0
-3
BUILD
pkg/volume/util/BUILD
+1
-0
BUILD
pkg/volume/util/exec/BUILD
+74
-0
exec_mount.go
pkg/volume/util/exec/exec_mount.go
+15
-11
exec_mount_test.go
pkg/volume/util/exec/exec_mount_test.go
+10
-8
exec_mount_unsupported.go
pkg/volume/util/exec/exec_mount_unsupported.go
+11
-9
No files found.
pkg/kubelet/BUILD
View file @
32a49828
...
@@ -110,6 +110,7 @@ go_library(
...
@@ -110,6 +110,7 @@ go_library(
"//pkg/volume:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume/csi:go_default_library",
"//pkg/volume/csi:go_default_library",
"//pkg/volume/util:go_default_library",
"//pkg/volume/util:go_default_library",
"//pkg/volume/util/exec:go_default_library",
"//pkg/volume/util/subpath:go_default_library",
"//pkg/volume/util/subpath:go_default_library",
"//pkg/volume/util/types:go_default_library",
"//pkg/volume/util/types:go_default_library",
"//pkg/volume/util/volumepathhandler:go_default_library",
"//pkg/volume/util/volumepathhandler:go_default_library",
...
...
pkg/kubelet/volume_host.go
View file @
32a49828
...
@@ -43,6 +43,7 @@ import (
...
@@ -43,6 +43,7 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
"k8s.io/kubernetes/pkg/volume/util"
execmnt
"k8s.io/kubernetes/pkg/volume/util/exec"
"k8s.io/kubernetes/pkg/volume/util/subpath"
"k8s.io/kubernetes/pkg/volume/util/subpath"
)
)
...
@@ -230,7 +231,7 @@ func (kvh *kubeletVolumeHost) GetMounter(pluginName string) mount.Interface {
...
@@ -230,7 +231,7 @@ func (kvh *kubeletVolumeHost) GetMounter(pluginName string) mount.Interface {
if
exec
==
nil
{
if
exec
==
nil
{
return
kvh
.
kubelet
.
mounter
return
kvh
.
kubelet
.
mounter
}
}
return
mou
nt
.
NewExecMounter
(
exec
,
kvh
.
kubelet
.
mounter
)
return
execm
nt
.
NewExecMounter
(
exec
,
kvh
.
kubelet
.
mounter
)
}
}
func
(
kvh
*
kubeletVolumeHost
)
GetHostName
()
string
{
func
(
kvh
*
kubeletVolumeHost
)
GetHostName
()
string
{
...
...
pkg/util/mount/BUILD
View file @
32a49828
...
@@ -5,8 +5,6 @@ go_library(
...
@@ -5,8 +5,6 @@ go_library(
srcs = [
srcs = [
"doc.go",
"doc.go",
"exec.go",
"exec.go",
"exec_mount.go",
"exec_mount_unsupported.go",
"fake.go",
"fake.go",
"mount.go",
"mount.go",
"mount_helper_common.go",
"mount_helper_common.go",
...
@@ -38,7 +36,6 @@ go_library(
...
@@ -38,7 +36,6 @@ go_library(
go_test(
go_test(
name = "go_default_test",
name = "go_default_test",
srcs = [
srcs = [
"exec_mount_test.go",
"mount_helper_test.go",
"mount_helper_test.go",
"mount_linux_test.go",
"mount_linux_test.go",
"mount_test.go",
"mount_test.go",
...
...
pkg/volume/util/BUILD
View file @
32a49828
...
@@ -84,6 +84,7 @@ filegroup(
...
@@ -84,6 +84,7 @@ filegroup(
name = "all-srcs",
name = "all-srcs",
srcs = [
srcs = [
":package-srcs",
":package-srcs",
"//pkg/volume/util/exec:all-srcs",
"//pkg/volume/util/fs:all-srcs",
"//pkg/volume/util/fs:all-srcs",
"//pkg/volume/util/nestedpendingoperations:all-srcs",
"//pkg/volume/util/nestedpendingoperations:all-srcs",
"//pkg/volume/util/nsenter:all-srcs",
"//pkg/volume/util/nsenter:all-srcs",
...
...
pkg/volume/util/exec/BUILD
0 → 100644
View file @
32a49828
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"exec_mount.go",
"exec_mount_unsupported.go",
],
importpath = "k8s.io/kubernetes/pkg/volume/util/exec",
visibility = ["//visibility:public"],
deps = select({
"@io_bazel_rules_go//go/platform:android": [
"//pkg/util/mount:go_default_library",
],
"@io_bazel_rules_go//go/platform:darwin": [
"//pkg/util/mount:go_default_library",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"//pkg/util/mount:go_default_library",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"//pkg/util/mount:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux": [
"//pkg/util/mount:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
"@io_bazel_rules_go//go/platform:nacl": [
"//pkg/util/mount:go_default_library",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"//pkg/util/mount:go_default_library",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"//pkg/util/mount:go_default_library",
],
"@io_bazel_rules_go//go/platform:plan9": [
"//pkg/util/mount:go_default_library",
],
"@io_bazel_rules_go//go/platform:solaris": [
"//pkg/util/mount:go_default_library",
],
"@io_bazel_rules_go//go/platform:windows": [
"//pkg/util/mount:go_default_library",
],
"//conditions:default": [],
}),
)
go_test(
name = "go_default_test",
srcs = ["exec_mount_test.go"],
embed = [":go_default_library"],
deps = select({
"@io_bazel_rules_go//go/platform:linux": [
"//pkg/util/mount:go_default_library",
],
"//conditions:default": [],
}),
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
pkg/
util/mount
/exec_mount.go
→
pkg/
volume/util/exec
/exec_mount.go
View file @
32a49828
...
@@ -16,23 +16,27 @@ See the License for the specific language governing permissions and
...
@@ -16,23 +16,27 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
mount
package
exec
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"k8s.io/klog"
"k8s.io/klog"
"k8s.io/kubernetes/pkg/util/mount"
)
)
// ExecMounter is a mounter that uses provided Exec interface to mount and
// ExecMounter is a mounter that uses provided Exec interface to mount and
// unmount a filesystem. For all other calls it uses a wrapped mounter.
// unmount a filesystem. For all other calls it uses a wrapped mounter.
type
execMounter
struct
{
type
execMounter
struct
{
wrappedMounter
Interface
wrappedMounter
mount
.
Interface
exec
Exec
exec
mount
.
Exec
}
}
func
NewExecMounter
(
exec
Exec
,
wrapped
Interface
)
Interface
{
// NewExecMounter returns a mounter that uses provided Exec interface to mount and
// unmount a filesystem. For all other calls it uses a wrapped mounter.
func
NewExecMounter
(
exec
mount
.
Exec
,
wrapped
mount
.
Interface
)
mount
.
Interface
{
return
&
execMounter
{
return
&
execMounter
{
wrappedMounter
:
wrapped
,
wrappedMounter
:
wrapped
,
exec
:
exec
,
exec
:
exec
,
...
@@ -40,11 +44,11 @@ func NewExecMounter(exec Exec, wrapped Interface) Interface {
...
@@ -40,11 +44,11 @@ func NewExecMounter(exec Exec, wrapped Interface) Interface {
}
}
// execMounter implements mount.Interface
// execMounter implements mount.Interface
var
_
Interface
=
&
execMounter
{}
var
_
mount
.
Interface
=
&
execMounter
{}
// Mount runs mount(8) using given exec interface.
// Mount runs mount(8) using given exec interface.
func
(
m
*
execMounter
)
Mount
(
source
string
,
target
string
,
fstype
string
,
options
[]
string
)
error
{
func
(
m
*
execMounter
)
Mount
(
source
string
,
target
string
,
fstype
string
,
options
[]
string
)
error
{
bind
,
bindOpts
,
bindRemountOpts
:=
IsBind
(
options
)
bind
,
bindOpts
,
bindRemountOpts
:=
mount
.
IsBind
(
options
)
if
bind
{
if
bind
{
err
:=
m
.
doExecMount
(
source
,
target
,
fstype
,
bindOpts
)
err
:=
m
.
doExecMount
(
source
,
target
,
fstype
,
bindOpts
)
...
@@ -60,11 +64,11 @@ func (m *execMounter) Mount(source string, target string, fstype string, options
...
@@ -60,11 +64,11 @@ func (m *execMounter) Mount(source string, target string, fstype string, options
// doExecMount calls exec(mount <what> <where>) using given exec interface.
// doExecMount calls exec(mount <what> <where>) using given exec interface.
func
(
m
*
execMounter
)
doExecMount
(
source
,
target
,
fstype
string
,
options
[]
string
)
error
{
func
(
m
*
execMounter
)
doExecMount
(
source
,
target
,
fstype
string
,
options
[]
string
)
error
{
klog
.
V
(
5
)
.
Infof
(
"Exec Mounting %s %s %s %v"
,
source
,
target
,
fstype
,
options
)
klog
.
V
(
5
)
.
Infof
(
"Exec Mounting %s %s %s %v"
,
source
,
target
,
fstype
,
options
)
mountArgs
:=
MakeMountArgs
(
source
,
target
,
fstype
,
options
)
mountArgs
:=
mount
.
MakeMountArgs
(
source
,
target
,
fstype
,
options
)
output
,
err
:=
m
.
exec
.
Run
(
"mount"
,
mountArgs
...
)
output
,
err
:=
m
.
exec
.
Run
(
"mount"
,
mountArgs
...
)
klog
.
V
(
5
)
.
Infof
(
"Exec mounted %v: %v: %s"
,
mountArgs
,
err
,
string
(
output
))
klog
.
V
(
5
)
.
Infof
(
"Exec mounted %v: %v: %s"
,
mountArgs
,
err
,
string
(
output
))
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"mount failed: %v
\n
Mounting command: %s
\n
Mounting arguments: %s %s %s %v
\n
Output: %s
\n
"
,
return
fmt
.
Errorf
(
"mount failed: %v
\n
Mounting command: %s
\n
Mounting arguments: %s %s %s %v
\n
Output: %s"
,
err
,
"mount"
,
source
,
target
,
fstype
,
options
,
string
(
output
))
err
,
"mount"
,
source
,
target
,
fstype
,
options
,
string
(
output
))
}
}
...
@@ -84,7 +88,7 @@ func (m *execMounter) Unmount(target string) error {
...
@@ -84,7 +88,7 @@ func (m *execMounter) Unmount(target string) error {
}
}
// List returns a list of all mounted filesystems.
// List returns a list of all mounted filesystems.
func
(
m
*
execMounter
)
List
()
([]
MountPoint
,
error
)
{
func
(
m
*
execMounter
)
List
()
([]
mount
.
MountPoint
,
error
)
{
return
m
.
wrappedMounter
.
List
()
return
m
.
wrappedMounter
.
List
()
}
}
...
@@ -112,7 +116,7 @@ func (m *execMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (strin
...
@@ -112,7 +116,7 @@ func (m *execMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (strin
return
m
.
wrappedMounter
.
GetDeviceNameFromMount
(
mountPath
,
pluginDir
)
return
m
.
wrappedMounter
.
GetDeviceNameFromMount
(
mountPath
,
pluginDir
)
}
}
func
(
m
*
execMounter
)
IsMountPointMatch
(
mp
MountPoint
,
dir
string
)
bool
{
func
(
m
*
execMounter
)
IsMountPointMatch
(
mp
mount
.
MountPoint
,
dir
string
)
bool
{
return
m
.
wrappedMounter
.
IsMountPointMatch
(
mp
,
dir
)
return
m
.
wrappedMounter
.
IsMountPointMatch
(
mp
,
dir
)
}
}
...
@@ -120,7 +124,7 @@ func (m *execMounter) MakeRShared(path string) error {
...
@@ -120,7 +124,7 @@ func (m *execMounter) MakeRShared(path string) error {
return
m
.
wrappedMounter
.
MakeRShared
(
path
)
return
m
.
wrappedMounter
.
MakeRShared
(
path
)
}
}
func
(
m
*
execMounter
)
GetFileType
(
pathname
string
)
(
FileType
,
error
)
{
func
(
m
*
execMounter
)
GetFileType
(
pathname
string
)
(
mount
.
FileType
,
error
)
{
return
m
.
wrappedMounter
.
GetFileType
(
pathname
)
return
m
.
wrappedMounter
.
GetFileType
(
pathname
)
}
}
...
...
pkg/
util/mount
/exec_mount_test.go
→
pkg/
volume/util/exec
/exec_mount_test.go
View file @
32a49828
...
@@ -16,13 +16,15 @@ See the License for the specific language governing permissions and
...
@@ -16,13 +16,15 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
mount
package
exec
import
(
import
(
"fmt"
"fmt"
"reflect"
"reflect"
"strings"
"strings"
"testing"
"testing"
"k8s.io/kubernetes/pkg/util/mount"
)
)
var
(
var
(
...
@@ -33,7 +35,7 @@ var (
...
@@ -33,7 +35,7 @@ var (
)
)
func
TestMount
(
t
*
testing
.
T
)
{
func
TestMount
(
t
*
testing
.
T
)
{
exec
:=
NewFakeExec
(
func
(
cmd
string
,
args
...
string
)
([]
byte
,
error
)
{
exec
:=
mount
.
NewFakeExec
(
func
(
cmd
string
,
args
...
string
)
([]
byte
,
error
)
{
if
cmd
!=
"mount"
{
if
cmd
!=
"mount"
{
t
.
Errorf
(
"expected mount command, got %q"
,
cmd
)
t
.
Errorf
(
"expected mount command, got %q"
,
cmd
)
}
}
...
@@ -45,7 +47,7 @@ func TestMount(t *testing.T) {
...
@@ -45,7 +47,7 @@ func TestMount(t *testing.T) {
return
nil
,
nil
return
nil
,
nil
})
})
wrappedMounter
:=
&
fakeMounter
{
FakeMounter
:
&
FakeMounter
{},
t
:
t
}
wrappedMounter
:=
&
fakeMounter
{
FakeMounter
:
&
mount
.
FakeMounter
{},
t
:
t
}
mounter
:=
NewExecMounter
(
exec
,
wrappedMounter
)
mounter
:=
NewExecMounter
(
exec
,
wrappedMounter
)
mounter
.
Mount
(
sourcePath
,
destinationPath
,
fsType
,
mountOptions
)
mounter
.
Mount
(
sourcePath
,
destinationPath
,
fsType
,
mountOptions
)
...
@@ -53,7 +55,7 @@ func TestMount(t *testing.T) {
...
@@ -53,7 +55,7 @@ func TestMount(t *testing.T) {
func
TestBindMount
(
t
*
testing
.
T
)
{
func
TestBindMount
(
t
*
testing
.
T
)
{
cmdCount
:=
0
cmdCount
:=
0
exec
:=
NewFakeExec
(
func
(
cmd
string
,
args
...
string
)
([]
byte
,
error
)
{
exec
:=
mount
.
NewFakeExec
(
func
(
cmd
string
,
args
...
string
)
([]
byte
,
error
)
{
cmdCount
++
cmdCount
++
if
cmd
!=
"mount"
{
if
cmd
!=
"mount"
{
t
.
Errorf
(
"expected mount command, got %q"
,
cmd
)
t
.
Errorf
(
"expected mount command, got %q"
,
cmd
)
...
@@ -73,14 +75,14 @@ func TestBindMount(t *testing.T) {
...
@@ -73,14 +75,14 @@ func TestBindMount(t *testing.T) {
return
nil
,
nil
return
nil
,
nil
})
})
wrappedMounter
:=
&
fakeMounter
{
FakeMounter
:
&
FakeMounter
{},
t
:
t
}
wrappedMounter
:=
&
fakeMounter
{
FakeMounter
:
&
mount
.
FakeMounter
{},
t
:
t
}
mounter
:=
NewExecMounter
(
exec
,
wrappedMounter
)
mounter
:=
NewExecMounter
(
exec
,
wrappedMounter
)
bindOptions
:=
append
(
mountOptions
,
"bind"
)
bindOptions
:=
append
(
mountOptions
,
"bind"
)
mounter
.
Mount
(
sourcePath
,
destinationPath
,
fsType
,
bindOptions
)
mounter
.
Mount
(
sourcePath
,
destinationPath
,
fsType
,
bindOptions
)
}
}
func
TestUnmount
(
t
*
testing
.
T
)
{
func
TestUnmount
(
t
*
testing
.
T
)
{
exec
:=
NewFakeExec
(
func
(
cmd
string
,
args
...
string
)
([]
byte
,
error
)
{
exec
:=
mount
.
NewFakeExec
(
func
(
cmd
string
,
args
...
string
)
([]
byte
,
error
)
{
if
cmd
!=
"umount"
{
if
cmd
!=
"umount"
{
t
.
Errorf
(
"expected unmount command, got %q"
,
cmd
)
t
.
Errorf
(
"expected unmount command, got %q"
,
cmd
)
}
}
...
@@ -92,7 +94,7 @@ func TestUnmount(t *testing.T) {
...
@@ -92,7 +94,7 @@ func TestUnmount(t *testing.T) {
return
nil
,
nil
return
nil
,
nil
})
})
wrappedMounter
:=
&
fakeMounter
{
&
FakeMounter
{},
t
}
wrappedMounter
:=
&
fakeMounter
{
&
mount
.
FakeMounter
{},
t
}
mounter
:=
NewExecMounter
(
exec
,
wrappedMounter
)
mounter
:=
NewExecMounter
(
exec
,
wrappedMounter
)
mounter
.
Unmount
(
destinationPath
)
mounter
.
Unmount
(
destinationPath
)
...
@@ -100,7 +102,7 @@ func TestUnmount(t *testing.T) {
...
@@ -100,7 +102,7 @@ func TestUnmount(t *testing.T) {
/* Fake wrapped mounter */
/* Fake wrapped mounter */
type
fakeMounter
struct
{
type
fakeMounter
struct
{
*
FakeMounter
*
mount
.
FakeMounter
t
*
testing
.
T
t
*
testing
.
T
}
}
...
...
pkg/
util/mount
/exec_mount_unsupported.go
→
pkg/
volume/util/exec
/exec_mount_unsupported.go
View file @
32a49828
...
@@ -16,18 +16,20 @@ See the License for the specific language governing permissions and
...
@@ -16,18 +16,20 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
mount
package
exec
import
(
import
(
"errors"
"errors"
"os"
"os"
"k8s.io/kubernetes/pkg/util/mount"
)
)
type
execMounter
struct
{}
type
execMounter
struct
{}
//
ExecMounter i
s a mounter that uses provided Exec interface to mount and
//
NewExecMounter return
s a mounter that uses provided Exec interface to mount and
// unmount a filesystem. For all other calls it uses a wrapped mounter.
// unmount a filesystem. For all other calls it uses a wrapped mounter.
func
NewExecMounter
(
exec
Exec
,
wrapped
Interface
)
Interface
{
func
NewExecMounter
(
exec
mount
.
Exec
,
wrapped
mount
.
Interface
)
mount
.
Interface
{
return
&
execMounter
{}
return
&
execMounter
{}
}
}
...
@@ -39,11 +41,11 @@ func (mounter *execMounter) Unmount(target string) error {
...
@@ -39,11 +41,11 @@ func (mounter *execMounter) Unmount(target string) error {
return
nil
return
nil
}
}
func
(
mounter
*
execMounter
)
List
()
([]
MountPoint
,
error
)
{
func
(
mounter
*
execMounter
)
List
()
([]
mount
.
MountPoint
,
error
)
{
return
[]
MountPoint
{},
nil
return
[]
mount
.
MountPoint
{},
nil
}
}
func
(
mounter
*
execMounter
)
IsMountPointMatch
(
mp
MountPoint
,
dir
string
)
bool
{
func
(
mounter
*
execMounter
)
IsMountPointMatch
(
mp
mount
.
MountPoint
,
dir
string
)
bool
{
return
(
mp
.
Path
==
dir
)
return
(
mp
.
Path
==
dir
)
}
}
...
@@ -67,8 +69,8 @@ func (mounter *execMounter) MakeRShared(path string) error {
...
@@ -67,8 +69,8 @@ func (mounter *execMounter) MakeRShared(path string) error {
return
nil
return
nil
}
}
func
(
mounter
*
execMounter
)
GetFileType
(
pathname
string
)
(
FileType
,
error
)
{
func
(
mounter
*
execMounter
)
GetFileType
(
pathname
string
)
(
mount
.
FileType
,
error
)
{
return
FileType
(
"fake"
),
errors
.
New
(
"not implemented"
)
return
mount
.
FileType
(
"fake"
),
errors
.
New
(
"not implemented"
)
}
}
func
(
mounter
*
execMounter
)
MakeDir
(
pathname
string
)
error
{
func
(
mounter
*
execMounter
)
MakeDir
(
pathname
string
)
error
{
...
@@ -83,7 +85,7 @@ func (mounter *execMounter) ExistsPath(pathname string) (bool, error) {
...
@@ -83,7 +85,7 @@ func (mounter *execMounter) ExistsPath(pathname string) (bool, error) {
return
true
,
errors
.
New
(
"not implemented"
)
return
true
,
errors
.
New
(
"not implemented"
)
}
}
func
(
m
*
execMounter
)
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
{
func
(
m
ounter
*
execMounter
)
EvalHostSymlinks
(
pathname
string
)
(
string
,
error
)
{
return
""
,
errors
.
New
(
"not implemented"
)
return
""
,
errors
.
New
(
"not implemented"
)
}
}
...
...
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