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
8d3fdc5a
Commit
8d3fdc5a
authored
May 02, 2018
by
NickrenREN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix UT errors and add new UTs
parent
8173ef1e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
12 deletions
+132
-12
fake.go
pkg/util/mount/fake.go
+1
-1
BUILD
pkg/volume/local/BUILD
+3
-0
local_test.go
pkg/volume/local/local_test.go
+115
-5
testing.go
pkg/volume/testing/testing.go
+13
-6
No files found.
pkg/util/mount/fake.go
View file @
8d3fdc5a
...
@@ -194,7 +194,7 @@ func (f *FakeMounter) GetFileType(pathname string) (FileType, error) {
...
@@ -194,7 +194,7 @@ func (f *FakeMounter) GetFileType(pathname string) (FileType, error) {
if
t
,
ok
:=
f
.
Filesystem
[
pathname
];
ok
{
if
t
,
ok
:=
f
.
Filesystem
[
pathname
];
ok
{
return
t
,
nil
return
t
,
nil
}
}
return
FileType
(
"
fake
"
),
nil
return
FileType
(
"
Directory
"
),
nil
}
}
func
(
f
*
FakeMounter
)
MakeDir
(
pathname
string
)
error
{
func
(
f
*
FakeMounter
)
MakeDir
(
pathname
string
)
error
{
...
...
pkg/volume/local/BUILD
View file @
8d3fdc5a
...
@@ -33,6 +33,7 @@ go_test(
...
@@ -33,6 +33,7 @@ go_test(
embed = [":go_default_library"],
embed = [":go_default_library"],
deps = select({
deps = select({
"@io_bazel_rules_go//go/platform:darwin": [
"@io_bazel_rules_go//go/platform:darwin": [
"//pkg/util/mount:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume/testing:go_default_library",
"//pkg/volume/testing:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
...
@@ -41,6 +42,7 @@ go_test(
...
@@ -41,6 +42,7 @@ go_test(
"//staging/src/k8s.io/client-go/util/testing:go_default_library",
"//staging/src/k8s.io/client-go/util/testing:go_default_library",
],
],
"@io_bazel_rules_go//go/platform:linux": [
"@io_bazel_rules_go//go/platform:linux": [
"//pkg/util/mount:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume/testing:go_default_library",
"//pkg/volume/testing:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
...
@@ -49,6 +51,7 @@ go_test(
...
@@ -49,6 +51,7 @@ go_test(
"//staging/src/k8s.io/client-go/util/testing:go_default_library",
"//staging/src/k8s.io/client-go/util/testing:go_default_library",
],
],
"@io_bazel_rules_go//go/platform:windows": [
"@io_bazel_rules_go//go/platform:windows": [
"//pkg/util/mount:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume/testing:go_default_library",
"//pkg/volume/testing:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
...
...
pkg/volume/local/local_test.go
View file @
8d3fdc5a
...
@@ -31,16 +31,18 @@ import (
...
@@ -31,16 +31,18 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
utiltesting
"k8s.io/client-go/util/testing"
utiltesting
"k8s.io/client-go/util/testing"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume"
volumetest
"k8s.io/kubernetes/pkg/volume/testing"
volumetest
"k8s.io/kubernetes/pkg/volume/testing"
)
)
const
(
const
(
testPVName
=
"pvA"
testPVName
=
"pvA"
testMountPath
=
"pods/poduid/volumes/kubernetes.io~local-volume/pvA"
testMountPath
=
"pods/poduid/volumes/kubernetes.io~local-volume/pvA"
testGlobalPath
=
"plugins/kubernetes.io~local-volume/volumeDevices/pvA"
testGlobalPath
=
"plugins/kubernetes.io~local-volume/volumeDevices/pvA"
testPodPath
=
"pods/poduid/volumeDevices/kubernetes.io~local-volume"
testPodPath
=
"pods/poduid/volumeDevices/kubernetes.io~local-volume"
testNodeName
=
"fakeNodeName"
testNodeName
=
"fakeNodeName"
testBlockFormattingToFSGlobalPath
=
"plugins/kubernetes.io/local-volume/mounts/pvA"
)
)
func
getPlugin
(
t
*
testing
.
T
)
(
string
,
volume
.
VolumePlugin
)
{
func
getPlugin
(
t
*
testing
.
T
)
(
string
,
volume
.
VolumePlugin
)
{
...
@@ -102,6 +104,33 @@ func getPersistentPlugin(t *testing.T) (string, volume.PersistentVolumePlugin) {
...
@@ -102,6 +104,33 @@ func getPersistentPlugin(t *testing.T) (string, volume.PersistentVolumePlugin) {
return
tmpDir
,
plug
return
tmpDir
,
plug
}
}
func
getDeviceMountablePluginWithBlockPath
(
t
*
testing
.
T
,
isBlockDevice
bool
)
(
string
,
volume
.
DeviceMountableVolumePlugin
)
{
tmpDir
,
err
:=
utiltesting
.
MkTmpdir
(
"localVolumeTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
plugMgr
:=
volume
.
VolumePluginMgr
{}
var
pathToFSType
map
[
string
]
mount
.
FileType
if
isBlockDevice
{
pathToFSType
=
map
[
string
]
mount
.
FileType
{
tmpDir
:
mount
.
FileTypeBlockDev
,
}
}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
nil
/* prober */
,
volumetest
.
NewFakeVolumeHostWithMounterFSType
(
tmpDir
,
nil
,
nil
,
pathToFSType
))
plug
,
err
:=
plugMgr
.
FindDeviceMountablePluginByName
(
localVolumePluginName
)
if
err
!=
nil
{
os
.
RemoveAll
(
tmpDir
)
t
.
Fatalf
(
"Can't find the plugin by name"
)
}
if
plug
.
GetPluginName
()
!=
localVolumePluginName
{
t
.
Errorf
(
"Wrong name: %s"
,
plug
.
GetPluginName
())
}
return
tmpDir
,
plug
}
func
getTestVolume
(
readOnly
bool
,
path
string
,
isBlock
bool
)
*
volume
.
Spec
{
func
getTestVolume
(
readOnly
bool
,
path
string
,
isBlock
bool
)
*
volume
.
Spec
{
pv
:=
&
v1
.
PersistentVolume
{
pv
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
...
@@ -179,6 +208,87 @@ func TestInvalidLocalPath(t *testing.T) {
...
@@ -179,6 +208,87 @@ func TestInvalidLocalPath(t *testing.T) {
}
}
}
}
func
TestBlockDeviceGlobalPathAndMountDevice
(
t
*
testing
.
T
)
{
// Block device global mount path testing
tmpBlockDir
,
plug
:=
getDeviceMountablePluginWithBlockPath
(
t
,
true
)
defer
os
.
RemoveAll
(
tmpBlockDir
)
dm
,
err
:=
plug
.
NewDeviceMounter
()
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new device mounter: %v"
,
err
)
}
pvSpec
:=
getTestVolume
(
false
,
tmpBlockDir
,
false
)
expectedGlobalPath
:=
filepath
.
Join
(
tmpBlockDir
,
testBlockFormattingToFSGlobalPath
)
actualPath
,
err
:=
dm
.
GetDeviceMountPath
(
pvSpec
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to get device mount path: %v"
,
err
)
}
if
expectedGlobalPath
!=
actualPath
{
t
.
Fatalf
(
"Expected device mount global path:%s, got: %s"
,
expectedGlobalPath
,
actualPath
)
}
fmt
.
Println
(
"expected global path is:"
,
expectedGlobalPath
)
err
=
dm
.
MountDevice
(
pvSpec
,
tmpBlockDir
,
expectedGlobalPath
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
_
,
err
:=
os
.
Stat
(
actualPath
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"DeviceMounter.MountDevice() failed, device mount path not created: %s"
,
actualPath
)
}
else
{
t
.
Errorf
(
"DeviceMounter.MountDevice() failed: %v"
,
err
)
}
}
du
,
err
:=
plug
.
NewDeviceUnmounter
()
if
err
!=
nil
{
t
.
Fatalf
(
"Create device unmounter error: %v"
,
err
)
}
err
=
du
.
UnmountDevice
(
actualPath
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unmount device error: %v"
,
err
)
}
}
func
TestFSGlobalPathAndMountDevice
(
t
*
testing
.
T
)
{
// FS global path testing
tmpFSDir
,
plug
:=
getDeviceMountablePluginWithBlockPath
(
t
,
false
)
defer
os
.
RemoveAll
(
tmpFSDir
)
dm
,
err
:=
plug
.
NewDeviceMounter
()
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new device mounter: %v"
,
err
)
}
pvSpec
:=
getTestVolume
(
false
,
tmpFSDir
,
false
)
expectedGlobalPath
:=
tmpFSDir
actualPath
,
err
:=
dm
.
GetDeviceMountPath
(
pvSpec
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to get device mount path: %v"
,
err
)
}
if
expectedGlobalPath
!=
actualPath
{
t
.
Fatalf
(
"Expected device mount global path:%s, got: %s"
,
expectedGlobalPath
,
actualPath
)
}
// Actually, we will do nothing if the local path is FS type
err
=
dm
.
MountDevice
(
pvSpec
,
tmpFSDir
,
expectedGlobalPath
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
_
,
err
:=
os
.
Stat
(
expectedGlobalPath
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"DeviceMounter.MountDevice() failed, device mount path not created: %s"
,
expectedGlobalPath
)
}
else
{
t
.
Errorf
(
"DeviceMounter.MountDevice() failed: %v"
,
err
)
}
}
}
func
TestMountUnmount
(
t
*
testing
.
T
)
{
func
TestMountUnmount
(
t
*
testing
.
T
)
{
tmpDir
,
plug
:=
getPlugin
(
t
)
tmpDir
,
plug
:=
getPlugin
(
t
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
...
...
pkg/volume/testing/testing.go
View file @
8d3fdc5a
...
@@ -60,33 +60,40 @@ type fakeVolumeHost struct {
...
@@ -60,33 +60,40 @@ type fakeVolumeHost struct {
}
}
func
NewFakeVolumeHost
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
)
*
fakeVolumeHost
{
func
NewFakeVolumeHost
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
)
*
fakeVolumeHost
{
return
newFakeVolumeHost
(
rootDir
,
kubeClient
,
plugins
,
nil
)
return
newFakeVolumeHost
(
rootDir
,
kubeClient
,
plugins
,
nil
,
nil
)
}
}
func
NewFakeVolumeHostWithCloudProvider
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
,
cloud
cloudprovider
.
Interface
)
*
fakeVolumeHost
{
func
NewFakeVolumeHostWithCloudProvider
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
,
cloud
cloudprovider
.
Interface
)
*
fakeVolumeHost
{
return
newFakeVolumeHost
(
rootDir
,
kubeClient
,
plugins
,
cloud
)
return
newFakeVolumeHost
(
rootDir
,
kubeClient
,
plugins
,
cloud
,
nil
)
}
}
func
NewFakeVolumeHostWithNodeLabels
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
,
labels
map
[
string
]
string
)
*
fakeVolumeHost
{
func
NewFakeVolumeHostWithNodeLabels
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
,
labels
map
[
string
]
string
)
*
fakeVolumeHost
{
volHost
:=
newFakeVolumeHost
(
rootDir
,
kubeClient
,
plugins
,
nil
)
volHost
:=
newFakeVolumeHost
(
rootDir
,
kubeClient
,
plugins
,
nil
,
nil
)
volHost
.
nodeLabels
=
labels
volHost
.
nodeLabels
=
labels
return
volHost
return
volHost
}
}
func
NewFakeVolumeHostWithNodeName
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
,
nodeName
string
)
*
fakeVolumeHost
{
func
NewFakeVolumeHostWithNodeName
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
,
nodeName
string
)
*
fakeVolumeHost
{
volHost
:=
newFakeVolumeHost
(
rootDir
,
kubeClient
,
plugins
,
nil
)
volHost
:=
newFakeVolumeHost
(
rootDir
,
kubeClient
,
plugins
,
nil
,
nil
)
volHost
.
nodeName
=
nodeName
volHost
.
nodeName
=
nodeName
return
volHost
return
volHost
}
}
func
newFakeVolumeHost
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
,
cloud
cloudprovider
.
Interface
)
*
fakeVolumeHost
{
func
newFakeVolumeHost
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
,
cloud
cloudprovider
.
Interface
,
pathToTypeMap
map
[
string
]
mount
.
FileType
)
*
fakeVolumeHost
{
host
:=
&
fakeVolumeHost
{
rootDir
:
rootDir
,
kubeClient
:
kubeClient
,
cloud
:
cloud
}
host
:=
&
fakeVolumeHost
{
rootDir
:
rootDir
,
kubeClient
:
kubeClient
,
cloud
:
cloud
}
host
.
mounter
=
&
mount
.
FakeMounter
{}
host
.
mounter
=
&
mount
.
FakeMounter
{
Filesystem
:
pathToTypeMap
,
}
host
.
exec
=
mount
.
NewFakeExec
(
nil
)
host
.
exec
=
mount
.
NewFakeExec
(
nil
)
host
.
pluginMgr
.
InitPlugins
(
plugins
,
nil
/* prober */
,
host
)
host
.
pluginMgr
.
InitPlugins
(
plugins
,
nil
/* prober */
,
host
)
return
host
return
host
}
}
func
NewFakeVolumeHostWithMounterFSType
(
rootDir
string
,
kubeClient
clientset
.
Interface
,
plugins
[]
VolumePlugin
,
pathToTypeMap
map
[
string
]
mount
.
FileType
)
*
fakeVolumeHost
{
volHost
:=
newFakeVolumeHost
(
rootDir
,
kubeClient
,
plugins
,
nil
,
pathToTypeMap
)
return
volHost
}
func
(
f
*
fakeVolumeHost
)
GetPluginDir
(
podUID
string
)
string
{
func
(
f
*
fakeVolumeHost
)
GetPluginDir
(
podUID
string
)
string
{
return
path
.
Join
(
f
.
rootDir
,
"plugins"
,
podUID
)
return
path
.
Join
(
f
.
rootDir
,
"plugins"
,
podUID
)
}
}
...
...
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