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
b5c34d0c
Unverified
Commit
b5c34d0c
authored
May 01, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 01, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #74734 from codenrhoden/move-mountspath
Move MountsInGlobalPDPath from mount pkg to volume
parents
576ec2ce
78d109e2
Hide whitespace changes
Inline
Side-by-side
Showing
77 changed files
with
272 additions
and
273 deletions
+272
-273
fake.go
pkg/util/mount/fake.go
+2
-2
mount.go
pkg/util/mount/mount.go
+8
-9
mount_linux.go
pkg/util/mount/mount_linux.go
+8
-9
mount_unsupported.go
pkg/util/mount/mount_unsupported.go
+2
-2
mount_windows.go
pkg/util/mount/mount_windows.go
+5
-5
aws_ebs.go
pkg/volume/awsebs/aws_ebs.go
+3
-3
attacher.go
pkg/volume/azure_dd/attacher.go
+1
-1
azure_common.go
pkg/volume/azure_dd/azure_common.go
+2
-2
azure_dd.go
pkg/volume/azure_dd/azure_dd.go
+2
-2
cephfs.go
pkg/volume/cephfs/cephfs.go
+2
-2
cephfs_test.go
pkg/volume/cephfs/cephfs_test.go
+2
-2
cinder.go
pkg/volume/cinder/cinder.go
+4
-3
cinder_block_test.go
pkg/volume/cinder/cinder_block_test.go
+4
-4
cinder_test.go
pkg/volume/cinder/cinder_test.go
+3
-3
configmap_test.go
pkg/volume/configmap/configmap_test.go
+4
-4
csi_attacher.go
pkg/volume/csi/csi_attacher.go
+1
-2
csi_block.go
pkg/volume/csi/csi_block.go
+2
-3
csi_block_test.go
pkg/volume/csi/csi_block_test.go
+8
-9
csi_mounter.go
pkg/volume/csi/csi_mounter.go
+3
-2
csi_mounter_test.go
pkg/volume/csi/csi_mounter_test.go
+4
-3
csi_plugin_test.go
pkg/volume/csi/csi_plugin_test.go
+1
-1
csi_util.go
pkg/volume/csi/csi_util.go
+5
-5
csi_util_test.go
pkg/volume/csi/csi_util_test.go
+3
-2
downwardapi_test.go
pkg/volume/downwardapi/downwardapi_test.go
+5
-5
empty_dir.go
pkg/volume/emptydir/empty_dir.go
+2
-2
empty_dir_test.go
pkg/volume/emptydir/empty_dir_test.go
+4
-4
fc_util.go
pkg/volume/fc/fc_util.go
+5
-6
flexvolume_test.go
pkg/volume/flexvolume/flexvolume_test.go
+4
-4
plugin.go
pkg/volume/flexvolume/plugin.go
+5
-5
probe_test.go
pkg/volume/flexvolume/probe_test.go
+13
-13
flocker.go
pkg/volume/flocker/flocker.go
+2
-2
attacher.go
pkg/volume/gcepd/attacher.go
+1
-1
gce_pd.go
pkg/volume/gcepd/gce_pd.go
+4
-4
gce_pd_block.go
pkg/volume/gcepd/gce_pd_block.go
+1
-2
gce_pd_block_test.go
pkg/volume/gcepd/gce_pd_block_test.go
+4
-4
gce_pd_test.go
pkg/volume/gcepd/gce_pd_test.go
+2
-2
gce_util.go
pkg/volume/gcepd/gce_util.go
+2
-3
git_repo.go
pkg/volume/git_repo/git_repo.go
+3
-4
git_repo_test.go
pkg/volume/git_repo/git_repo_test.go
+2
-2
glusterfs.go
pkg/volume/glusterfs/glusterfs.go
+3
-3
iscsi_util.go
pkg/volume/iscsi/iscsi_util.go
+4
-5
local.go
pkg/volume/local/local.go
+1
-1
local_test.go
pkg/volume/local/local_test.go
+6
-7
attacher.go
pkg/volume/photon_pd/attacher.go
+1
-1
photon_pd.go
pkg/volume/photon_pd/photon_pd.go
+4
-4
photon_pd_test.go
pkg/volume/photon_pd/photon_pd_test.go
+2
-2
portworx_test.go
pkg/volume/portworx/portworx_test.go
+2
-2
projected_test.go
pkg/volume/projected/projected_test.go
+4
-4
quobyte.go
pkg/volume/quobyte/quobyte.go
+2
-2
rbd.go
pkg/volume/rbd/rbd.go
+2
-2
rbd_util.go
pkg/volume/rbd/rbd_util.go
+11
-10
sio_client.go
pkg/volume/scaleio/sio_client.go
+1
-2
sio_util_test.go
pkg/volume/scaleio/sio_util_test.go
+3
-3
sio_volume.go
pkg/volume/scaleio/sio_volume.go
+3
-3
sio_volume_test.go
pkg/volume/scaleio/sio_volume_test.go
+2
-2
secret_test.go
pkg/volume/secret/secret_test.go
+4
-4
storageos.go
pkg/volume/storageos/storageos.go
+1
-2
storageos_test.go
pkg/volume/storageos/storageos_test.go
+2
-2
storageos_util.go
pkg/volume/storageos/storageos_util.go
+2
-2
testing.go
pkg/volume/testing/testing.go
+10
-10
atomic_writer.go
pkg/volume/util/atomic_writer.go
+9
-9
atomic_writer_test.go
pkg/volume/util/atomic_writer_test.go
+7
-8
device_util_linux.go
pkg/volume/util/device_util_linux.go
+3
-3
exec_mount.go
pkg/volume/util/exec/exec_mount.go
+2
-2
exec_mount_unsupported.go
pkg/volume/util/exec/exec_mount_unsupported.go
+1
-1
nested_volumes.go
pkg/volume/util/nested_volumes.go
+3
-3
nested_volumes_test.go
pkg/volume/util/nested_volumes_test.go
+2
-2
nsenter_mount.go
pkg/volume/util/nsenter/nsenter_mount.go
+2
-2
nsenter_mount_unsupported.go
pkg/volume/util/nsenter/nsenter_mount_unsupported.go
+1
-1
operation_generator.go
pkg/volume/util/operationexecutor/operation_generator.go
+2
-2
util.go
pkg/volume/util/util.go
+13
-3
volume_path_handler.go
pkg/volume/util/volumepathhandler/volume_path_handler.go
+6
-7
attacher.go
pkg/volume/vsphere_volume/attacher.go
+2
-2
vsphere_volume.go
pkg/volume/vsphere_volume/vsphere_volume.go
+4
-4
vsphere_volume_block.go
pkg/volume/vsphere_volume/vsphere_volume_block.go
+1
-2
vsphere_volume_block_test.go
pkg/volume/vsphere_volume/vsphere_volume_block_test.go
+4
-4
vsphere_volume_test.go
pkg/volume/vsphere_volume/vsphere_volume_test.go
+2
-2
No files found.
pkg/util/mount/fake.go
View file @
b5c34d0c
...
@@ -182,8 +182,8 @@ func (f *FakeMounter) PathIsDevice(pathname string) (bool, error) {
...
@@ -182,8 +182,8 @@ func (f *FakeMounter) PathIsDevice(pathname string) (bool, error) {
return
true
,
nil
return
true
,
nil
}
}
func
(
f
*
FakeMounter
)
GetDeviceNameFromMount
(
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
(
f
*
FakeMounter
)
GetDeviceNameFromMount
(
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
return
getDeviceNameFromMount
(
f
,
mountPath
,
pluginDir
)
return
getDeviceNameFromMount
(
f
,
mountPath
,
plugin
Mount
Dir
)
}
}
func
(
f
*
FakeMounter
)
MakeRShared
(
path
string
)
error
{
func
(
f
*
FakeMounter
)
MakeRShared
(
path
string
)
error
{
...
...
pkg/util/mount/mount.go
View file @
b5c34d0c
...
@@ -29,13 +29,12 @@ type FileType string
...
@@ -29,13 +29,12 @@ type FileType string
const
(
const
(
// Default mount command if mounter path is not specified
// Default mount command if mounter path is not specified
defaultMountCommand
=
"mount"
defaultMountCommand
=
"mount"
MountsInGlobalPDPath
=
"mounts"
FileTypeDirectory
FileType
=
"Directory"
FileTypeDirectory
FileType
=
"Directory"
FileTypeFile
FileType
=
"File"
FileTypeFile
FileType
=
"File"
FileTypeSocket
FileType
=
"Socket"
FileTypeSocket
FileType
=
"Socket"
FileTypeCharDev
FileType
=
"CharDevice"
FileTypeCharDev
FileType
=
"CharDevice"
FileTypeBlockDev
FileType
=
"BlockDevice"
FileTypeBlockDev
FileType
=
"BlockDevice"
)
)
type
Interface
interface
{
type
Interface
interface
{
...
@@ -62,8 +61,8 @@ type Interface interface {
...
@@ -62,8 +61,8 @@ type Interface interface {
// PathIsDevice determines if a path is a device.
// PathIsDevice determines if a path is a device.
PathIsDevice
(
pathname
string
)
(
bool
,
error
)
PathIsDevice
(
pathname
string
)
(
bool
,
error
)
// GetDeviceNameFromMount finds the device name by checking the mount path
// GetDeviceNameFromMount finds the device name by checking the mount path
// to get the global mount path w
hich matches
its plugin directory
// to get the global mount path w
ithin
its plugin directory
GetDeviceNameFromMount
(
mountPath
,
pluginDir
string
)
(
string
,
error
)
GetDeviceNameFromMount
(
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
// MakeRShared checks that given path is on a mount with 'rshared' mount
// MakeRShared checks that given path is on a mount with 'rshared' mount
// propagation. If not, it bind-mounts the path as rshared.
// propagation. If not, it bind-mounts the path as rshared.
MakeRShared
(
path
string
)
error
MakeRShared
(
path
string
)
error
...
...
pkg/util/mount/mount_linux.go
View file @
b5c34d0c
...
@@ -304,19 +304,19 @@ func ExclusiveOpenFailsOnDevice(pathname string) (bool, error) {
...
@@ -304,19 +304,19 @@ func ExclusiveOpenFailsOnDevice(pathname string) (bool, error) {
}
}
//GetDeviceNameFromMount: given a mount point, find the device name from its global mount point
//GetDeviceNameFromMount: given a mount point, find the device name from its global mount point
func
(
mounter
*
Mounter
)
GetDeviceNameFromMount
(
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
(
mounter
*
Mounter
)
GetDeviceNameFromMount
(
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
return
GetDeviceNameFromMountLinux
(
mounter
,
mountPath
,
pluginDir
)
return
GetDeviceNameFromMountLinux
(
mounter
,
mountPath
,
plugin
Mount
Dir
)
}
}
func
getDeviceNameFromMount
(
mounter
Interface
,
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
getDeviceNameFromMount
(
mounter
Interface
,
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
return
GetDeviceNameFromMountLinux
(
mounter
,
mountPath
,
pluginDir
)
return
GetDeviceNameFromMountLinux
(
mounter
,
mountPath
,
plugin
Mount
Dir
)
}
}
// GetDeviceNameFromMountLinux find the device name from /proc/mounts in which
// GetDeviceNameFromMountLinux find the device name from /proc/mounts in which
// the mount path reference should match the given plugin directory. In case no mount path reference
// the mount path reference should match the given plugin
mount
directory. In case no mount path reference
// matches, returns the volume name taken from its given mountPath
// matches, returns the volume name taken from its given mountPath
// This implementation is shared with NsEnterMounter
// This implementation is shared with NsEnterMounter
func
GetDeviceNameFromMountLinux
(
mounter
Interface
,
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
GetDeviceNameFromMountLinux
(
mounter
Interface
,
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
refs
,
err
:=
mounter
.
GetMountRefs
(
mountPath
)
refs
,
err
:=
mounter
.
GetMountRefs
(
mountPath
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
V
(
4
)
.
Infof
(
"GetMountRefs failed for mount path %q: %v"
,
mountPath
,
err
)
klog
.
V
(
4
)
.
Infof
(
"GetMountRefs failed for mount path %q: %v"
,
mountPath
,
err
)
...
@@ -326,10 +326,9 @@ func GetDeviceNameFromMountLinux(mounter Interface, mountPath, pluginDir string)
...
@@ -326,10 +326,9 @@ func GetDeviceNameFromMountLinux(mounter Interface, mountPath, pluginDir string)
klog
.
V
(
4
)
.
Infof
(
"Directory %s is not mounted"
,
mountPath
)
klog
.
V
(
4
)
.
Infof
(
"Directory %s is not mounted"
,
mountPath
)
return
""
,
fmt
.
Errorf
(
"directory %s is not mounted"
,
mountPath
)
return
""
,
fmt
.
Errorf
(
"directory %s is not mounted"
,
mountPath
)
}
}
basemountPath
:=
path
.
Join
(
pluginDir
,
MountsInGlobalPDPath
)
for
_
,
ref
:=
range
refs
{
for
_
,
ref
:=
range
refs
{
if
strings
.
HasPrefix
(
ref
,
basemountPath
)
{
if
strings
.
HasPrefix
(
ref
,
pluginMountDir
)
{
volumeID
,
err
:=
filepath
.
Rel
(
basemountPath
,
ref
)
volumeID
,
err
:=
filepath
.
Rel
(
pluginMountDir
,
ref
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Errorf
(
"Failed to get volume id from mount %s - %v"
,
mountPath
,
err
)
klog
.
Errorf
(
"Failed to get volume id from mount %s - %v"
,
mountPath
,
err
)
return
""
,
err
return
""
,
err
...
...
pkg/util/mount/mount_unsupported.go
View file @
b5c34d0c
...
@@ -58,11 +58,11 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
...
@@ -58,11 +58,11 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
return
true
,
unsupportedErr
return
true
,
unsupportedErr
}
}
func
(
mounter
*
Mounter
)
GetDeviceNameFromMount
(
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
(
mounter
*
Mounter
)
GetDeviceNameFromMount
(
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
return
""
,
unsupportedErr
return
""
,
unsupportedErr
}
}
func
getDeviceNameFromMount
(
mounter
Interface
,
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
getDeviceNameFromMount
(
mounter
Interface
,
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
return
""
,
unsupportedErr
return
""
,
unsupportedErr
}
}
...
...
pkg/util/mount/mount_windows.go
View file @
b5c34d0c
...
@@ -196,14 +196,14 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
...
@@ -196,14 +196,14 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
}
}
// GetDeviceNameFromMount given a mnt point, find the device
// GetDeviceNameFromMount given a mnt point, find the device
func
(
mounter
*
Mounter
)
GetDeviceNameFromMount
(
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
(
mounter
*
Mounter
)
GetDeviceNameFromMount
(
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
return
getDeviceNameFromMount
(
mounter
,
mountPath
,
pluginDir
)
return
getDeviceNameFromMount
(
mounter
,
mountPath
,
plugin
Mount
Dir
)
}
}
// getDeviceNameFromMount find the device(drive) name in which
// getDeviceNameFromMount find the device(drive) name in which
// the mount path reference should match the given plugin directory. In case no mount path reference
// the mount path reference should match the given plugin
mount
directory. In case no mount path reference
// matches, returns the volume name taken from its given mountPath
// matches, returns the volume name taken from its given mountPath
func
getDeviceNameFromMount
(
mounter
Interface
,
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
getDeviceNameFromMount
(
mounter
Interface
,
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
refs
,
err
:=
mounter
.
GetMountRefs
(
mountPath
)
refs
,
err
:=
mounter
.
GetMountRefs
(
mountPath
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
V
(
4
)
.
Infof
(
"GetMountRefs failed for mount path %q: %v"
,
mountPath
,
err
)
klog
.
V
(
4
)
.
Infof
(
"GetMountRefs failed for mount path %q: %v"
,
mountPath
,
err
)
...
@@ -212,7 +212,7 @@ func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (str
...
@@ -212,7 +212,7 @@ func getDeviceNameFromMount(mounter Interface, mountPath, pluginDir string) (str
if
len
(
refs
)
==
0
{
if
len
(
refs
)
==
0
{
return
""
,
fmt
.
Errorf
(
"directory %s is not mounted"
,
mountPath
)
return
""
,
fmt
.
Errorf
(
"directory %s is not mounted"
,
mountPath
)
}
}
basemountPath
:=
normalizeWindowsPath
(
p
ath
.
Join
(
pluginDir
,
MountsInGlobalPDPath
)
)
basemountPath
:=
normalizeWindowsPath
(
p
luginMountDir
)
for
_
,
ref
:=
range
refs
{
for
_
,
ref
:=
range
refs
{
if
strings
.
Contains
(
ref
,
basemountPath
)
{
if
strings
.
Contains
(
ref
,
basemountPath
)
{
volumeID
,
err
:=
filepath
.
Rel
(
normalizeWindowsPath
(
basemountPath
),
ref
)
volumeID
,
err
:=
filepath
.
Rel
(
normalizeWindowsPath
(
basemountPath
),
ref
)
...
...
pkg/volume/awsebs/aws_ebs.go
View file @
b5c34d0c
...
@@ -250,8 +250,8 @@ func getVolumeSource(
...
@@ -250,8 +250,8 @@ func getVolumeSource(
func
(
plugin
*
awsElasticBlockStorePlugin
)
ConstructVolumeSpec
(
volName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
func
(
plugin
*
awsElasticBlockStorePlugin
)
ConstructVolumeSpec
(
volName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
plugin
Dir
:=
plugin
.
host
.
GetPluginDir
(
plugin
.
GetPluginName
())
plugin
MntDir
:=
util
.
GetPluginMountDir
(
plugin
.
host
,
plugin
.
GetPluginName
())
volumeID
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
pluginDir
)
volumeID
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
plugin
Mnt
Dir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -451,7 +451,7 @@ func makeGlobalPDPath(host volume.VolumeHost, volumeID aws.KubernetesVolumeID) s
...
@@ -451,7 +451,7 @@ func makeGlobalPDPath(host volume.VolumeHost, volumeID aws.KubernetesVolumeID) s
// Clean up the URI to be more fs-friendly
// Clean up the URI to be more fs-friendly
name
:=
string
(
volumeID
)
name
:=
string
(
volumeID
)
name
=
strings
.
Replace
(
name
,
"://"
,
"/"
,
-
1
)
name
=
strings
.
Replace
(
name
,
"://"
,
"/"
,
-
1
)
return
filepath
.
Join
(
host
.
GetPluginDir
(
awsElasticBlockStorePluginName
),
mount
.
MountsInGlobalPDPath
,
name
)
return
filepath
.
Join
(
host
.
GetPluginDir
(
awsElasticBlockStorePluginName
),
util
.
MountsInGlobalPDPath
,
name
)
}
}
func
(
ebs
*
awsElasticBlockStore
)
GetPath
()
string
{
func
(
ebs
*
awsElasticBlockStore
)
GetPath
()
string
{
...
...
pkg/volume/azure_dd/attacher.go
View file @
b5c34d0c
...
@@ -199,7 +199,7 @@ func (a *azureDiskAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error
...
@@ -199,7 +199,7 @@ func (a *azureDiskAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error
}
}
if
volumeSource
.
Kind
==
nil
{
// this spec was constructed from info on the node
if
volumeSource
.
Kind
==
nil
{
// this spec was constructed from info on the node
pdPath
:=
filepath
.
Join
(
a
.
plugin
.
host
.
GetPluginDir
(
azureDataDiskPluginName
),
mount
.
MountsInGlobalPDPath
,
volumeSource
.
DataDiskURI
)
pdPath
:=
filepath
.
Join
(
a
.
plugin
.
host
.
GetPluginDir
(
azureDataDiskPluginName
),
util
.
MountsInGlobalPDPath
,
volumeSource
.
DataDiskURI
)
return
pdPath
,
nil
return
pdPath
,
nil
}
}
...
...
pkg/volume/azure_dd/azure_common.go
View file @
b5c34d0c
...
@@ -31,8 +31,8 @@ import (
...
@@ -31,8 +31,8 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
api
"k8s.io/kubernetes/pkg/apis/core"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
"k8s.io/legacy-cloud-providers/azure"
"k8s.io/legacy-cloud-providers/azure"
utilstrings
"k8s.io/utils/strings"
utilstrings
"k8s.io/utils/strings"
)
)
...
@@ -80,7 +80,7 @@ func makeGlobalPDPath(host volume.VolumeHost, diskUri string, isManaged bool) (s
...
@@ -80,7 +80,7 @@ func makeGlobalPDPath(host volume.VolumeHost, diskUri string, isManaged bool) (s
}
}
// "{m for managed b for blob}{hashed diskUri or DiskId depending on disk kind }"
// "{m for managed b for blob}{hashed diskUri or DiskId depending on disk kind }"
diskName
:=
fmt
.
Sprintf
(
uniqueDiskNameTemplate
,
prefix
,
hashedDiskUri
)
diskName
:=
fmt
.
Sprintf
(
uniqueDiskNameTemplate
,
prefix
,
hashedDiskUri
)
pdPath
:=
filepath
.
Join
(
host
.
GetPluginDir
(
azureDataDiskPluginName
),
mount
.
MountsInGlobalPDPath
,
diskName
)
pdPath
:=
filepath
.
Join
(
host
.
GetPluginDir
(
azureDataDiskPluginName
),
util
.
MountsInGlobalPDPath
,
diskName
)
return
pdPath
,
nil
return
pdPath
,
nil
}
}
...
...
pkg/volume/azure_dd/azure_dd.go
View file @
b5c34d0c
...
@@ -328,8 +328,8 @@ var _ volume.NodeExpandableVolumePlugin = &azureDataDiskPlugin{}
...
@@ -328,8 +328,8 @@ var _ volume.NodeExpandableVolumePlugin = &azureDataDiskPlugin{}
func
(
plugin
*
azureDataDiskPlugin
)
ConstructVolumeSpec
(
volumeName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
func
(
plugin
*
azureDataDiskPlugin
)
ConstructVolumeSpec
(
volumeName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
plugin
Dir
:=
plugin
.
host
.
GetPluginDir
(
plugin
.
GetPluginName
())
plugin
MntDir
:=
util
.
GetPluginMountDir
(
plugin
.
host
,
plugin
.
GetPluginName
())
sourceName
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
pluginDir
)
sourceName
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
plugin
Mnt
Dir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
pkg/volume/cephfs/cephfs.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"fmt"
"fmt"
"os"
"os"
"os/exec"
"os/exec"
"path"
"path
/filepath
"
"runtime"
"runtime"
"strings"
"strings"
...
@@ -384,7 +384,7 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
...
@@ -384,7 +384,7 @@ func (cephfsVolume *cephfs) execFuseMount(mountpoint string) error {
return
err
return
err
}
}
keyringFile
=
path
.
Join
(
keyringPath
,
fileName
)
keyringFile
=
file
path
.
Join
(
keyringPath
,
fileName
)
}
else
{
}
else
{
keyringFile
=
cephfsVolume
.
secretFile
keyringFile
=
cephfsVolume
.
secretFile
...
...
pkg/volume/cephfs/cephfs_test.go
View file @
b5c34d0c
...
@@ -18,7 +18,7 @@ package cephfs
...
@@ -18,7 +18,7 @@ package cephfs
import
(
import
(
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -83,7 +83,7 @@ func TestPlugin(t *testing.T) {
...
@@ -83,7 +83,7 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"Got a nil Mounter"
)
t
.
Errorf
(
"Got a nil Mounter"
)
}
}
volumePath
:=
mounter
.
GetPath
()
volumePath
:=
mounter
.
GetPath
()
volpath
:=
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~cephfs/vol1"
)
volpath
:=
file
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~cephfs/vol1"
)
if
volumePath
!=
volpath
{
if
volumePath
!=
volpath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
volumePath
)
t
.
Errorf
(
"Got unexpected path: %s"
,
volumePath
)
}
}
...
...
pkg/volume/cinder/cinder.go
View file @
b5c34d0c
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"fmt"
"fmt"
"os"
"os"
"path"
"path"
"path/filepath"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
...
@@ -266,8 +267,8 @@ func (plugin *cinderPlugin) getCloudProvider() (BlockStorageProvider, error) {
...
@@ -266,8 +267,8 @@ func (plugin *cinderPlugin) getCloudProvider() (BlockStorageProvider, error) {
func
(
plugin
*
cinderPlugin
)
ConstructVolumeSpec
(
volumeName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
func
(
plugin
*
cinderPlugin
)
ConstructVolumeSpec
(
volumeName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
plugin
Dir
:=
plugin
.
host
.
GetPluginDir
(
plugin
.
GetPluginName
())
plugin
MntDir
:=
util
.
GetPluginMountDir
(
plugin
.
host
,
plugin
.
GetPluginName
())
sourceName
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
pluginDir
)
sourceName
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
plugin
Mnt
Dir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -449,7 +450,7 @@ func (b *cinderVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -449,7 +450,7 @@ func (b *cinderVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
}
}
func
makeGlobalPDName
(
host
volume
.
VolumeHost
,
devName
string
)
string
{
func
makeGlobalPDName
(
host
volume
.
VolumeHost
,
devName
string
)
string
{
return
path
.
Join
(
host
.
GetPluginDir
(
cinderVolumePluginName
),
mount
.
MountsInGlobalPDPath
,
devName
)
return
filepath
.
Join
(
host
.
GetPluginDir
(
cinderVolumePluginName
),
util
.
MountsInGlobalPDPath
,
devName
)
}
}
func
(
cd
*
cinderVolume
)
GetPath
()
string
{
func
(
cd
*
cinderVolume
)
GetPath
()
string
{
...
...
pkg/volume/cinder/cinder_block_test.go
View file @
b5c34d0c
...
@@ -18,7 +18,7 @@ package cinder
...
@@ -18,7 +18,7 @@ package cinder
import
(
import
(
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -47,7 +47,7 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) {
...
@@ -47,7 +47,7 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) {
//deferred clean up
//deferred clean up
defer
os
.
RemoveAll
(
tmpVDir
)
defer
os
.
RemoveAll
(
tmpVDir
)
expectedGlobalPath
:=
path
.
Join
(
tmpVDir
,
testGlobalPath
)
expectedGlobalPath
:=
file
path
.
Join
(
tmpVDir
,
testGlobalPath
)
//Bad Path
//Bad Path
badspec
,
err
:=
getVolumeSpecFromGlobalMapPath
(
""
)
badspec
,
err
:=
getVolumeSpecFromGlobalMapPath
(
""
)
...
@@ -102,8 +102,8 @@ func TestGetPodAndPluginMapPaths(t *testing.T) {
...
@@ -102,8 +102,8 @@ func TestGetPodAndPluginMapPaths(t *testing.T) {
//deferred clean up
//deferred clean up
defer
os
.
RemoveAll
(
tmpVDir
)
defer
os
.
RemoveAll
(
tmpVDir
)
expectedGlobalPath
:=
path
.
Join
(
tmpVDir
,
testGlobalPath
)
expectedGlobalPath
:=
file
path
.
Join
(
tmpVDir
,
testGlobalPath
)
expectedPodPath
:=
path
.
Join
(
tmpVDir
,
testPodPath
)
expectedPodPath
:=
file
path
.
Join
(
tmpVDir
,
testPodPath
)
spec
:=
getTestVolume
(
false
,
true
/*isBlock*/
)
spec
:=
getTestVolume
(
false
,
true
/*isBlock*/
)
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
...
...
pkg/volume/cinder/cinder_test.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package cinder
...
@@ -19,7 +19,7 @@ package cinder
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"time"
"time"
...
@@ -64,7 +64,7 @@ type fakePDManager struct {
...
@@ -64,7 +64,7 @@ type fakePDManager struct {
}
}
func
getFakeDeviceName
(
host
volume
.
VolumeHost
,
pdName
string
)
string
{
func
getFakeDeviceName
(
host
volume
.
VolumeHost
,
pdName
string
)
string
{
return
path
.
Join
(
host
.
GetPluginDir
(
cinderVolumePluginName
),
"device"
,
pdName
)
return
file
path
.
Join
(
host
.
GetPluginDir
(
cinderVolumePluginName
),
"device"
,
pdName
)
}
}
// Real Cinder AttachDisk attaches a cinder volume. If it is not yet mounted,
// Real Cinder AttachDisk attaches a cinder volume. If it is not yet mounted,
...
@@ -160,7 +160,7 @@ func TestPlugin(t *testing.T) {
...
@@ -160,7 +160,7 @@ func TestPlugin(t *testing.T) {
if
mounter
==
nil
{
if
mounter
==
nil
{
t
.
Errorf
(
"Got a nil Mounter"
)
t
.
Errorf
(
"Got a nil Mounter"
)
}
}
volPath
:=
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~cinder/vol1"
)
volPath
:=
file
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~cinder/vol1"
)
path
:=
mounter
.
GetPath
()
path
:=
mounter
.
GetPath
()
if
path
!=
volPath
{
if
path
!=
volPath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
...
...
pkg/volume/configmap/configmap_test.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path
/filepath
"
"reflect"
"reflect"
"strings"
"strings"
"testing"
"testing"
...
@@ -498,14 +498,14 @@ func TestPluginOptional(t *testing.T) {
...
@@ -498,14 +498,14 @@ func TestPluginOptional(t *testing.T) {
}
}
}
}
datadirSymlink
:=
path
.
Join
(
volumePath
,
"..data"
)
datadirSymlink
:=
file
path
.
Join
(
volumePath
,
"..data"
)
datadir
,
err
:=
os
.
Readlink
(
datadirSymlink
)
datadir
,
err
:=
os
.
Readlink
(
datadirSymlink
)
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
t
.
Fatalf
(
"couldn't find volume path's data dir, %s"
,
datadirSymlink
)
t
.
Fatalf
(
"couldn't find volume path's data dir, %s"
,
datadirSymlink
)
}
else
if
err
!=
nil
{
}
else
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't read symlink, %s"
,
datadirSymlink
)
t
.
Fatalf
(
"couldn't read symlink, %s"
,
datadirSymlink
)
}
}
datadirPath
:=
path
.
Join
(
volumePath
,
datadir
)
datadirPath
:=
file
path
.
Join
(
volumePath
,
datadir
)
infos
,
err
:=
ioutil
.
ReadDir
(
volumePath
)
infos
,
err
:=
ioutil
.
ReadDir
(
volumePath
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -689,7 +689,7 @@ func configMap(namespace, name string) v1.ConfigMap {
...
@@ -689,7 +689,7 @@ func configMap(namespace, name string) v1.ConfigMap {
func
doTestConfigMapDataInVolume
(
volumePath
string
,
configMap
v1
.
ConfigMap
,
t
*
testing
.
T
)
{
func
doTestConfigMapDataInVolume
(
volumePath
string
,
configMap
v1
.
ConfigMap
,
t
*
testing
.
T
)
{
for
key
,
value
:=
range
configMap
.
Data
{
for
key
,
value
:=
range
configMap
.
Data
{
configMapDataHostPath
:=
path
.
Join
(
volumePath
,
key
)
configMapDataHostPath
:=
file
path
.
Join
(
volumePath
,
key
)
if
_
,
err
:=
os
.
Stat
(
configMapDataHostPath
);
err
!=
nil
{
if
_
,
err
:=
os
.
Stat
(
configMapDataHostPath
);
err
!=
nil
{
t
.
Fatalf
(
"SetUp() failed, couldn't find configMap data on disk: %v"
,
configMapDataHostPath
)
t
.
Fatalf
(
"SetUp() failed, couldn't find configMap data on disk: %v"
,
configMapDataHostPath
)
}
else
{
}
else
{
...
...
pkg/volume/csi/csi_attacher.go
View file @
b5c34d0c
...
@@ -22,7 +22,6 @@ import (
...
@@ -22,7 +22,6 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"strings"
"strings"
"time"
"time"
...
@@ -598,7 +597,7 @@ func makeDeviceMountPath(plugin *csiPlugin, spec *volume.Spec) (string, error) {
...
@@ -598,7 +597,7 @@ func makeDeviceMountPath(plugin *csiPlugin, spec *volume.Spec) (string, error) {
return
""
,
fmt
.
Errorf
(
"makeDeviceMountPath failed, pv name empty"
)
return
""
,
fmt
.
Errorf
(
"makeDeviceMountPath failed, pv name empty"
)
}
}
return
path
.
Join
(
plugin
.
host
.
GetPluginDir
(
plugin
.
GetPluginName
()),
persistentVolumeInGlobalPath
,
pvName
,
globalMountInGlobalPath
),
nil
return
file
path
.
Join
(
plugin
.
host
.
GetPluginDir
(
plugin
.
GetPluginName
()),
persistentVolumeInGlobalPath
,
pvName
,
globalMountInGlobalPath
),
nil
}
}
func
getDriverAndVolNameFromDeviceMountPath
(
k8s
kubernetes
.
Interface
,
deviceMountPath
string
)
(
string
,
string
,
error
)
{
func
getDriverAndVolNameFromDeviceMountPath
(
k8s
kubernetes
.
Interface
,
deviceMountPath
string
)
(
string
,
string
,
error
)
{
...
...
pkg/volume/csi/csi_block.go
View file @
b5c34d0c
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"k8s.io/klog"
"k8s.io/klog"
...
@@ -63,14 +62,14 @@ func (m *csiBlockMapper) GetGlobalMapPath(spec *volume.Spec) (string, error) {
...
@@ -63,14 +62,14 @@ func (m *csiBlockMapper) GetGlobalMapPath(spec *volume.Spec) (string, error) {
// Example: plugins/kubernetes.io/csi/volumeDevices/staging/{pvname}
// Example: plugins/kubernetes.io/csi/volumeDevices/staging/{pvname}
func
(
m
*
csiBlockMapper
)
getStagingPath
()
string
{
func
(
m
*
csiBlockMapper
)
getStagingPath
()
string
{
sanitizedSpecVolID
:=
utilstrings
.
EscapeQualifiedName
(
m
.
specName
)
sanitizedSpecVolID
:=
utilstrings
.
EscapeQualifiedName
(
m
.
specName
)
return
path
.
Join
(
m
.
plugin
.
host
.
GetVolumeDevicePluginDir
(
CSIPluginName
),
"staging"
,
sanitizedSpecVolID
)
return
file
path
.
Join
(
m
.
plugin
.
host
.
GetVolumeDevicePluginDir
(
CSIPluginName
),
"staging"
,
sanitizedSpecVolID
)
}
}
// getPublishPath returns a publish path for a file (on the node) that should be used on NodePublishVolume/NodeUnpublishVolume
// getPublishPath returns a publish path for a file (on the node) that should be used on NodePublishVolume/NodeUnpublishVolume
// Example: plugins/kubernetes.io/csi/volumeDevices/publish/{pvname}
// Example: plugins/kubernetes.io/csi/volumeDevices/publish/{pvname}
func
(
m
*
csiBlockMapper
)
getPublishPath
()
string
{
func
(
m
*
csiBlockMapper
)
getPublishPath
()
string
{
sanitizedSpecVolID
:=
utilstrings
.
EscapeQualifiedName
(
m
.
specName
)
sanitizedSpecVolID
:=
utilstrings
.
EscapeQualifiedName
(
m
.
specName
)
return
path
.
Join
(
m
.
plugin
.
host
.
GetVolumeDevicePluginDir
(
CSIPluginName
),
"publish"
,
sanitizedSpecVolID
)
return
file
path
.
Join
(
m
.
plugin
.
host
.
GetVolumeDevicePluginDir
(
CSIPluginName
),
"publish"
,
sanitizedSpecVolID
)
}
}
// GetPodDeviceMapPath returns pod's device file which will be mapped to a volume
// GetPodDeviceMapPath returns pod's device file which will be mapped to a volume
...
...
pkg/volume/csi/csi_block_test.go
View file @
b5c34d0c
...
@@ -19,7 +19,6 @@ package csi
...
@@ -19,7 +19,6 @@ package csi
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"testing"
"testing"
...
@@ -64,12 +63,12 @@ func TestBlockMapperGetGlobalMapPath(t *testing.T) {
...
@@ -64,12 +63,12 @@ func TestBlockMapperGetGlobalMapPath(t *testing.T) {
{
{
name
:
"simple specName"
,
name
:
"simple specName"
,
specVolumeName
:
"spec-0"
,
specVolumeName
:
"spec-0"
,
path
:
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/%s/%s"
,
"spec-0"
,
"dev"
)),
path
:
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/%s/%s"
,
"spec-0"
,
"dev"
)),
},
},
{
{
name
:
"specName with dots"
,
name
:
"specName with dots"
,
specVolumeName
:
"test.spec.1"
,
specVolumeName
:
"test.spec.1"
,
path
:
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/%s/%s"
,
"test.spec.1"
,
"dev"
)),
path
:
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/%s/%s"
,
"test.spec.1"
,
"dev"
)),
},
},
}
}
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
...
@@ -104,12 +103,12 @@ func TestBlockMapperGetStagingPath(t *testing.T) {
...
@@ -104,12 +103,12 @@ func TestBlockMapperGetStagingPath(t *testing.T) {
{
{
name
:
"simple specName"
,
name
:
"simple specName"
,
specVolumeName
:
"spec-0"
,
specVolumeName
:
"spec-0"
,
path
:
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/staging/%s"
,
"spec-0"
)),
path
:
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/staging/%s"
,
"spec-0"
)),
},
},
{
{
name
:
"specName with dots"
,
name
:
"specName with dots"
,
specVolumeName
:
"test.spec.1"
,
specVolumeName
:
"test.spec.1"
,
path
:
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/staging/%s"
,
"test.spec.1"
)),
path
:
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/staging/%s"
,
"test.spec.1"
)),
},
},
}
}
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
...
@@ -141,12 +140,12 @@ func TestBlockMapperGetPublishPath(t *testing.T) {
...
@@ -141,12 +140,12 @@ func TestBlockMapperGetPublishPath(t *testing.T) {
{
{
name
:
"simple specName"
,
name
:
"simple specName"
,
specVolumeName
:
"spec-0"
,
specVolumeName
:
"spec-0"
,
path
:
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/publish/%s"
,
"spec-0"
)),
path
:
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/publish/%s"
,
"spec-0"
)),
},
},
{
{
name
:
"specName with dots"
,
name
:
"specName with dots"
,
specVolumeName
:
"test.spec.1"
,
specVolumeName
:
"test.spec.1"
,
path
:
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/publish/%s"
,
"test.spec.1"
)),
path
:
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"plugins/kubernetes.io/csi/volumeDevices/publish/%s"
,
"test.spec.1"
)),
},
},
}
}
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
...
@@ -178,12 +177,12 @@ func TestBlockMapperGetDeviceMapPath(t *testing.T) {
...
@@ -178,12 +177,12 @@ func TestBlockMapperGetDeviceMapPath(t *testing.T) {
{
{
name
:
"simple specName"
,
name
:
"simple specName"
,
specVolumeName
:
"spec-0"
,
specVolumeName
:
"spec-0"
,
path
:
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"pods/%s/volumeDevices/kubernetes.io~csi"
,
testPodUID
)),
path
:
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"pods/%s/volumeDevices/kubernetes.io~csi"
,
testPodUID
)),
},
},
{
{
name
:
"specName with dots"
,
name
:
"specName with dots"
,
specVolumeName
:
"test.spec.1"
,
specVolumeName
:
"test.spec.1"
,
path
:
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"pods/%s/volumeDevices/kubernetes.io~csi"
,
testPodUID
)),
path
:
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"pods/%s/volumeDevices/kubernetes.io~csi"
,
testPodUID
)),
},
},
}
}
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
...
...
pkg/volume/csi/csi_mounter.go
View file @
b5c34d0c
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"fmt"
"fmt"
"os"
"os"
"path"
"path"
"path/filepath"
"k8s.io/klog"
"k8s.io/klog"
...
@@ -75,7 +76,7 @@ type csiMountMgr struct {
...
@@ -75,7 +76,7 @@ type csiMountMgr struct {
var
_
volume
.
Volume
=
&
csiMountMgr
{}
var
_
volume
.
Volume
=
&
csiMountMgr
{}
func
(
c
*
csiMountMgr
)
GetPath
()
string
{
func
(
c
*
csiMountMgr
)
GetPath
()
string
{
dir
:=
path
.
Join
(
getTargetPath
(
c
.
podUID
,
c
.
specVolumeID
,
c
.
plugin
.
host
),
"/mount"
)
dir
:=
file
path
.
Join
(
getTargetPath
(
c
.
podUID
,
c
.
specVolumeID
,
c
.
plugin
.
host
),
"/mount"
)
klog
.
V
(
4
)
.
Info
(
log
(
"mounter.GetPath generated [%s]"
,
dir
))
klog
.
V
(
4
)
.
Info
(
log
(
"mounter.GetPath generated [%s]"
,
dir
))
return
dir
return
dir
}
}
...
@@ -440,7 +441,7 @@ func removeMountDir(plug *csiPlugin, mountPath string) error {
...
@@ -440,7 +441,7 @@ func removeMountDir(plug *csiPlugin, mountPath string) error {
}
}
// remove volume data file as well
// remove volume data file as well
volPath
:=
path
.
Dir
(
mountPath
)
volPath
:=
path
.
Dir
(
mountPath
)
dataFile
:=
path
.
Join
(
volPath
,
volDataFileName
)
dataFile
:=
file
path
.
Join
(
volPath
,
volDataFileName
)
klog
.
V
(
4
)
.
Info
(
log
(
"also deleting volume info data file [%s]"
,
dataFile
))
klog
.
V
(
4
)
.
Info
(
log
(
"also deleting volume info data file [%s]"
,
dataFile
))
if
err
:=
os
.
Remove
(
dataFile
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
if
err
:=
os
.
Remove
(
dataFile
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
klog
.
Error
(
log
(
"failed to delete volume data file [%s]: %v"
,
dataFile
,
err
))
klog
.
Error
(
log
(
"failed to delete volume data file [%s]: %v"
,
dataFile
,
err
))
...
...
pkg/volume/csi/csi_mounter_test.go
View file @
b5c34d0c
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"math/rand"
"math/rand"
"os"
"os"
"path"
"path"
"path/filepath"
"testing"
"testing"
"reflect"
"reflect"
...
@@ -60,12 +61,12 @@ func TestMounterGetPath(t *testing.T) {
...
@@ -60,12 +61,12 @@ func TestMounterGetPath(t *testing.T) {
{
{
name
:
"simple specName"
,
name
:
"simple specName"
,
specVolumeName
:
"spec-0"
,
specVolumeName
:
"spec-0"
,
path
:
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"pods/%s/volumes/kubernetes.io~csi/%s/%s"
,
testPodUID
,
"spec-0"
,
"/mount"
)),
path
:
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"pods/%s/volumes/kubernetes.io~csi/%s/%s"
,
testPodUID
,
"spec-0"
,
"/mount"
)),
},
},
{
{
name
:
"specName with dots"
,
name
:
"specName with dots"
,
specVolumeName
:
"test.spec.1"
,
specVolumeName
:
"test.spec.1"
,
path
:
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"pods/%s/volumes/kubernetes.io~csi/%s/%s"
,
testPodUID
,
"test.spec.1"
,
"/mount"
)),
path
:
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"pods/%s/volumes/kubernetes.io~csi/%s/%s"
,
testPodUID
,
"test.spec.1"
,
"/mount"
)),
},
},
}
}
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
...
@@ -649,7 +650,7 @@ func TestUnmounterTeardown(t *testing.T) {
...
@@ -649,7 +650,7 @@ func TestUnmounterTeardown(t *testing.T) {
pv
:=
makeTestPV
(
"test-pv"
,
10
,
testDriver
,
testVol
)
pv
:=
makeTestPV
(
"test-pv"
,
10
,
testDriver
,
testVol
)
// save the data file prior to unmount
// save the data file prior to unmount
dir
:=
path
.
Join
(
getTargetPath
(
testPodUID
,
pv
.
ObjectMeta
.
Name
,
plug
.
host
),
"/mount"
)
dir
:=
file
path
.
Join
(
getTargetPath
(
testPodUID
,
pv
.
ObjectMeta
.
Name
,
plug
.
host
),
"/mount"
)
if
err
:=
os
.
MkdirAll
(
dir
,
0755
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
if
err
:=
os
.
MkdirAll
(
dir
,
0755
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"failed to create dir [%s]: %v"
,
dir
,
err
)
t
.
Errorf
(
"failed to create dir [%s]: %v"
,
dir
,
err
)
}
}
...
...
pkg/volume/csi/csi_plugin_test.go
View file @
b5c34d0c
...
@@ -756,7 +756,7 @@ func TestPluginNewUnmounter(t *testing.T) {
...
@@ -756,7 +756,7 @@ func TestPluginNewUnmounter(t *testing.T) {
pv
:=
makeTestPV
(
"test-pv"
,
10
,
testDriver
,
testVol
)
pv
:=
makeTestPV
(
"test-pv"
,
10
,
testDriver
,
testVol
)
// save the data file to re-create client
// save the data file to re-create client
dir
:=
path
.
Join
(
getTargetPath
(
testPodUID
,
pv
.
ObjectMeta
.
Name
,
plug
.
host
),
"/mount"
)
dir
:=
file
path
.
Join
(
getTargetPath
(
testPodUID
,
pv
.
ObjectMeta
.
Name
,
plug
.
host
),
"/mount"
)
if
err
:=
os
.
MkdirAll
(
dir
,
0755
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
if
err
:=
os
.
MkdirAll
(
dir
,
0755
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"failed to create dir [%s]: %v"
,
dir
,
err
)
t
.
Errorf
(
"failed to create dir [%s]: %v"
,
dir
,
err
)
}
}
...
...
pkg/volume/csi/csi_util.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"time"
"time"
api
"k8s.io/api/core/v1"
api
"k8s.io/api/core/v1"
...
@@ -54,7 +54,7 @@ func getCredentialsFromSecret(k8s kubernetes.Interface, secretRef *api.SecretRef
...
@@ -54,7 +54,7 @@ func getCredentialsFromSecret(k8s kubernetes.Interface, secretRef *api.SecretRef
// saveVolumeData persists parameter data as json file at the provided location
// saveVolumeData persists parameter data as json file at the provided location
func
saveVolumeData
(
dir
string
,
fileName
string
,
data
map
[
string
]
string
)
error
{
func
saveVolumeData
(
dir
string
,
fileName
string
,
data
map
[
string
]
string
)
error
{
dataFilePath
:=
path
.
Join
(
dir
,
fileName
)
dataFilePath
:=
file
path
.
Join
(
dir
,
fileName
)
klog
.
V
(
4
)
.
Info
(
log
(
"saving volume data file [%s]"
,
dataFilePath
))
klog
.
V
(
4
)
.
Info
(
log
(
"saving volume data file [%s]"
,
dataFilePath
))
file
,
err
:=
os
.
Create
(
dataFilePath
)
file
,
err
:=
os
.
Create
(
dataFilePath
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -73,7 +73,7 @@ func saveVolumeData(dir string, fileName string, data map[string]string) error {
...
@@ -73,7 +73,7 @@ func saveVolumeData(dir string, fileName string, data map[string]string) error {
// loadVolumeData loads volume info from specified json file/location
// loadVolumeData loads volume info from specified json file/location
func
loadVolumeData
(
dir
string
,
fileName
string
)
(
map
[
string
]
string
,
error
)
{
func
loadVolumeData
(
dir
string
,
fileName
string
)
(
map
[
string
]
string
,
error
)
{
// remove /mount at the end
// remove /mount at the end
dataFileName
:=
path
.
Join
(
dir
,
fileName
)
dataFileName
:=
file
path
.
Join
(
dir
,
fileName
)
klog
.
V
(
4
)
.
Info
(
log
(
"loading volume data file [%s]"
,
dataFileName
))
klog
.
V
(
4
)
.
Info
(
log
(
"loading volume data file [%s]"
,
dataFileName
))
file
,
err
:=
os
.
Open
(
dataFileName
)
file
,
err
:=
os
.
Open
(
dataFileName
)
...
@@ -114,7 +114,7 @@ func log(msg string, parts ...interface{}) string {
...
@@ -114,7 +114,7 @@ func log(msg string, parts ...interface{}) string {
// path: plugins/kubernetes.io/csi/volumeDevices/{specVolumeID}/dev
// path: plugins/kubernetes.io/csi/volumeDevices/{specVolumeID}/dev
func
getVolumeDevicePluginDir
(
specVolID
string
,
host
volume
.
VolumeHost
)
string
{
func
getVolumeDevicePluginDir
(
specVolID
string
,
host
volume
.
VolumeHost
)
string
{
sanitizedSpecVolID
:=
utilstrings
.
EscapeQualifiedName
(
specVolID
)
sanitizedSpecVolID
:=
utilstrings
.
EscapeQualifiedName
(
specVolID
)
return
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
CSIPluginName
),
sanitizedSpecVolID
,
"dev"
)
return
file
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
CSIPluginName
),
sanitizedSpecVolID
,
"dev"
)
}
}
// getVolumeDeviceDataDir returns the path where the CSI plugin keeps the
// getVolumeDeviceDataDir returns the path where the CSI plugin keeps the
...
@@ -122,7 +122,7 @@ func getVolumeDevicePluginDir(specVolID string, host volume.VolumeHost) string {
...
@@ -122,7 +122,7 @@ func getVolumeDevicePluginDir(specVolID string, host volume.VolumeHost) string {
// path: plugins/kubernetes.io/csi/volumeDevices/{specVolumeID}/data
// path: plugins/kubernetes.io/csi/volumeDevices/{specVolumeID}/data
func
getVolumeDeviceDataDir
(
specVolID
string
,
host
volume
.
VolumeHost
)
string
{
func
getVolumeDeviceDataDir
(
specVolID
string
,
host
volume
.
VolumeHost
)
string
{
sanitizedSpecVolID
:=
utilstrings
.
EscapeQualifiedName
(
specVolID
)
sanitizedSpecVolID
:=
utilstrings
.
EscapeQualifiedName
(
specVolID
)
return
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
CSIPluginName
),
sanitizedSpecVolID
,
"data"
)
return
file
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
CSIPluginName
),
sanitizedSpecVolID
,
"data"
)
}
}
// hasReadWriteOnce returns true if modes contains v1.ReadWriteOnce
// hasReadWriteOnce returns true if modes contains v1.ReadWriteOnce
...
...
pkg/volume/csi/csi_util_test.go
View file @
b5c34d0c
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path"
"path/filepath"
"testing"
"testing"
api
"k8s.io/api/core/v1"
api
"k8s.io/api/core/v1"
...
@@ -104,7 +105,7 @@ func TestSaveVolumeData(t *testing.T) {
...
@@ -104,7 +105,7 @@ func TestSaveVolumeData(t *testing.T) {
for
i
,
tc
:=
range
testCases
{
for
i
,
tc
:=
range
testCases
{
t
.
Logf
(
"test case: %s"
,
tc
.
name
)
t
.
Logf
(
"test case: %s"
,
tc
.
name
)
specVolID
:=
fmt
.
Sprintf
(
"spec-volid-%d"
,
i
)
specVolID
:=
fmt
.
Sprintf
(
"spec-volid-%d"
,
i
)
mountDir
:=
path
.
Join
(
getTargetPath
(
testPodUID
,
specVolID
,
plug
.
host
),
"/mount"
)
mountDir
:=
file
path
.
Join
(
getTargetPath
(
testPodUID
,
specVolID
,
plug
.
host
),
"/mount"
)
if
err
:=
os
.
MkdirAll
(
mountDir
,
0755
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
if
err
:=
os
.
MkdirAll
(
mountDir
,
0755
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"failed to create dir [%s]: %v"
,
mountDir
,
err
)
t
.
Errorf
(
"failed to create dir [%s]: %v"
,
mountDir
,
err
)
}
}
...
@@ -116,7 +117,7 @@ func TestSaveVolumeData(t *testing.T) {
...
@@ -116,7 +117,7 @@ func TestSaveVolumeData(t *testing.T) {
}
}
// did file get created
// did file get created
dataDir
:=
getTargetPath
(
testPodUID
,
specVolID
,
plug
.
host
)
dataDir
:=
getTargetPath
(
testPodUID
,
specVolID
,
plug
.
host
)
file
:=
path
.
Join
(
dataDir
,
volDataFileName
)
file
:=
file
path
.
Join
(
dataDir
,
volDataFileName
)
if
_
,
err
:=
os
.
Stat
(
file
);
err
!=
nil
{
if
_
,
err
:=
os
.
Stat
(
file
);
err
!=
nil
{
t
.
Errorf
(
"failed to create data dir: %v"
,
err
)
t
.
Errorf
(
"failed to create data dir: %v"
,
err
)
}
}
...
...
pkg/volume/downwardapi/downwardapi_test.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -314,7 +314,7 @@ type stepName struct {
...
@@ -314,7 +314,7 @@ type stepName struct {
func
(
step
stepName
)
getName
()
string
{
return
step
.
name
}
func
(
step
stepName
)
getName
()
string
{
return
step
.
name
}
func
doVerifyLinesInFile
(
t
*
testing
.
T
,
volumePath
,
filename
string
,
expected
string
)
{
func
doVerifyLinesInFile
(
t
*
testing
.
T
,
volumePath
,
filename
string
,
expected
string
)
{
data
,
err
:=
ioutil
.
ReadFile
(
path
.
Join
(
volumePath
,
filename
))
data
,
err
:=
ioutil
.
ReadFile
(
file
path
.
Join
(
volumePath
,
filename
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
err
.
Error
())
t
.
Errorf
(
err
.
Error
())
return
return
...
@@ -350,7 +350,7 @@ type verifyMode struct {
...
@@ -350,7 +350,7 @@ type verifyMode struct {
}
}
func
(
step
verifyMode
)
run
(
test
*
downwardAPITest
)
{
func
(
step
verifyMode
)
run
(
test
*
downwardAPITest
)
{
fileInfo
,
err
:=
os
.
Stat
(
path
.
Join
(
test
.
volumePath
,
step
.
name
))
fileInfo
,
err
:=
os
.
Stat
(
file
path
.
Join
(
test
.
volumePath
,
step
.
name
))
if
err
!=
nil
{
if
err
!=
nil
{
test
.
t
.
Errorf
(
err
.
Error
())
test
.
t
.
Errorf
(
err
.
Error
())
return
return
...
@@ -374,7 +374,7 @@ func (step reSetUp) run(test *downwardAPITest) {
...
@@ -374,7 +374,7 @@ func (step reSetUp) run(test *downwardAPITest) {
test
.
pod
.
ObjectMeta
.
Labels
=
step
.
newLabels
test
.
pod
.
ObjectMeta
.
Labels
=
step
.
newLabels
}
}
currentTarget
,
err
:=
os
.
Readlink
(
path
.
Join
(
test
.
volumePath
,
downwardAPIDir
))
currentTarget
,
err
:=
os
.
Readlink
(
file
path
.
Join
(
test
.
volumePath
,
downwardAPIDir
))
if
err
!=
nil
{
if
err
!=
nil
{
test
.
t
.
Errorf
(
"labels file should be a link... %s
\n
"
,
err
.
Error
())
test
.
t
.
Errorf
(
"labels file should be a link... %s
\n
"
,
err
.
Error
())
}
}
...
@@ -385,7 +385,7 @@ func (step reSetUp) run(test *downwardAPITest) {
...
@@ -385,7 +385,7 @@ func (step reSetUp) run(test *downwardAPITest) {
}
}
// get the link of the link
// get the link of the link
currentTarget2
,
err
:=
os
.
Readlink
(
path
.
Join
(
test
.
volumePath
,
downwardAPIDir
))
currentTarget2
,
err
:=
os
.
Readlink
(
file
path
.
Join
(
test
.
volumePath
,
downwardAPIDir
))
if
err
!=
nil
{
if
err
!=
nil
{
test
.
t
.
Errorf
(
".current should be a link... %s
\n
"
,
err
.
Error
())
test
.
t
.
Errorf
(
".current should be a link... %s
\n
"
,
err
.
Error
())
}
}
...
...
pkg/volume/emptydir/empty_dir.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package emptydir
...
@@ -19,7 +19,7 @@ package emptydir
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
...
@@ -420,7 +420,7 @@ func (ed *emptyDir) teardownTmpfsOrHugetlbfs(dir string) error {
...
@@ -420,7 +420,7 @@ func (ed *emptyDir) teardownTmpfsOrHugetlbfs(dir string) error {
}
}
func
(
ed
*
emptyDir
)
getMetaDir
()
string
{
func
(
ed
*
emptyDir
)
getMetaDir
()
string
{
return
path
.
Join
(
ed
.
plugin
.
host
.
GetPodPluginDir
(
ed
.
pod
.
UID
,
utilstrings
.
EscapeQualifiedName
(
emptyDirPluginName
)),
ed
.
volName
)
return
file
path
.
Join
(
ed
.
plugin
.
host
.
GetPodPluginDir
(
ed
.
pod
.
UID
,
utilstrings
.
EscapeQualifiedName
(
emptyDirPluginName
)),
ed
.
volName
)
}
}
func
getVolumeSource
(
spec
*
volume
.
Spec
)
(
*
v1
.
EmptyDirVolumeSource
,
bool
)
{
func
getVolumeSource
(
spec
*
volume
.
Spec
)
(
*
v1
.
EmptyDirVolumeSource
,
bool
)
{
...
...
pkg/volume/emptydir/empty_dir_test.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ package emptydir
...
@@ -20,7 +20,7 @@ package emptydir
import
(
import
(
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -107,8 +107,8 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
...
@@ -107,8 +107,8 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
defer
os
.
RemoveAll
(
basePath
)
defer
os
.
RemoveAll
(
basePath
)
var
(
var
(
volumePath
=
path
.
Join
(
basePath
,
"pods/poduid/volumes/kubernetes.io~empty-dir/test-volume"
)
volumePath
=
file
path
.
Join
(
basePath
,
"pods/poduid/volumes/kubernetes.io~empty-dir/test-volume"
)
metadataDir
=
path
.
Join
(
basePath
,
"pods/poduid/plugins/kubernetes.io~empty-dir/test-volume"
)
metadataDir
=
file
path
.
Join
(
basePath
,
"pods/poduid/plugins/kubernetes.io~empty-dir/test-volume"
)
plug
=
makePluginUnderTest
(
t
,
"kubernetes.io/empty-dir"
,
basePath
)
plug
=
makePluginUnderTest
(
t
,
"kubernetes.io/empty-dir"
,
basePath
)
volumeName
=
"test-volume"
volumeName
=
"test-volume"
...
@@ -250,7 +250,7 @@ func TestPluginBackCompat(t *testing.T) {
...
@@ -250,7 +250,7 @@ func TestPluginBackCompat(t *testing.T) {
}
}
volPath
:=
mounter
.
GetPath
()
volPath
:=
mounter
.
GetPath
()
if
volPath
!=
path
.
Join
(
basePath
,
"pods/poduid/volumes/kubernetes.io~empty-dir/vol1"
)
{
if
volPath
!=
file
path
.
Join
(
basePath
,
"pods/poduid/volumes/kubernetes.io~empty-dir/vol1"
)
{
t
.
Errorf
(
"Got unexpected path: %s"
,
volPath
)
t
.
Errorf
(
"Got unexpected path: %s"
,
volPath
)
}
}
}
}
...
...
pkg/volume/fc/fc_util.go
View file @
b5c34d0c
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"strconv"
"strconv"
"strings"
"strings"
...
@@ -136,18 +135,18 @@ func scsiHostRescan(io ioHandler) {
...
@@ -136,18 +135,18 @@ func scsiHostRescan(io ioHandler) {
func
makePDNameInternal
(
host
volume
.
VolumeHost
,
wwns
[]
string
,
lun
string
,
wwids
[]
string
)
string
{
func
makePDNameInternal
(
host
volume
.
VolumeHost
,
wwns
[]
string
,
lun
string
,
wwids
[]
string
)
string
{
if
len
(
wwns
)
!=
0
{
if
len
(
wwns
)
!=
0
{
w
:=
strings
.
Join
(
wwns
,
"-"
)
w
:=
strings
.
Join
(
wwns
,
"-"
)
return
path
.
Join
(
host
.
GetPluginDir
(
fcPluginName
),
w
+
"-lun-"
+
lun
)
return
file
path
.
Join
(
host
.
GetPluginDir
(
fcPluginName
),
w
+
"-lun-"
+
lun
)
}
}
return
path
.
Join
(
host
.
GetPluginDir
(
fcPluginName
),
strings
.
Join
(
wwids
,
"-"
))
return
file
path
.
Join
(
host
.
GetPluginDir
(
fcPluginName
),
strings
.
Join
(
wwids
,
"-"
))
}
}
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/fc/volumeDevices/target-lun-0
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/fc/volumeDevices/target-lun-0
func
makeVDPDNameInternal
(
host
volume
.
VolumeHost
,
wwns
[]
string
,
lun
string
,
wwids
[]
string
)
string
{
func
makeVDPDNameInternal
(
host
volume
.
VolumeHost
,
wwns
[]
string
,
lun
string
,
wwids
[]
string
)
string
{
if
len
(
wwns
)
!=
0
{
if
len
(
wwns
)
!=
0
{
w
:=
strings
.
Join
(
wwns
,
"-"
)
w
:=
strings
.
Join
(
wwns
,
"-"
)
return
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
fcPluginName
),
w
+
"-lun-"
+
lun
)
return
file
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
fcPluginName
),
w
+
"-lun-"
+
lun
)
}
}
return
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
fcPluginName
),
strings
.
Join
(
wwids
,
"-"
))
return
file
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
fcPluginName
),
strings
.
Join
(
wwids
,
"-"
))
}
}
func
parsePDName
(
path
string
)
(
wwns
[]
string
,
lun
int32
,
wwids
[]
string
,
err
error
)
{
func
parsePDName
(
path
string
)
(
wwns
[]
string
,
lun
int32
,
wwids
[]
string
,
err
error
)
{
...
@@ -360,7 +359,7 @@ func (util *fcUtil) DetachBlockFCDisk(c fcDiskUnmapper, mapPath, devicePath stri
...
@@ -360,7 +359,7 @@ func (util *fcUtil) DetachBlockFCDisk(c fcDiskUnmapper, mapPath, devicePath stri
}
}
for
_
,
fi
:=
range
fis
{
for
_
,
fi
:=
range
fis
{
if
strings
.
Contains
(
fi
.
Name
(),
volumeInfo
)
{
if
strings
.
Contains
(
fi
.
Name
(),
volumeInfo
)
{
devicePath
=
path
.
Join
(
searchPath
,
fi
.
Name
())
devicePath
=
file
path
.
Join
(
searchPath
,
fi
.
Name
())
klog
.
V
(
5
)
.
Infof
(
"fc: updated devicePath: %s"
,
devicePath
)
klog
.
V
(
5
)
.
Infof
(
"fc: updated devicePath: %s"
,
devicePath
)
break
break
}
}
...
...
pkg/volume/flexvolume/flexvolume_test.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"bytes"
"bytes"
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"text/template"
"text/template"
...
@@ -132,12 +132,12 @@ func installPluginUnderTest(t *testing.T, vendorName, plugName, tmpDir string, e
...
@@ -132,12 +132,12 @@ func installPluginUnderTest(t *testing.T, vendorName, plugName, tmpDir string, e
if
vendorName
!=
""
{
if
vendorName
!=
""
{
vendoredName
=
fmt
.
Sprintf
(
"%s~%s"
,
vendorName
,
plugName
)
vendoredName
=
fmt
.
Sprintf
(
"%s~%s"
,
vendorName
,
plugName
)
}
}
pluginDir
:=
path
.
Join
(
tmpDir
,
vendoredName
)
pluginDir
:=
file
path
.
Join
(
tmpDir
,
vendoredName
)
err
:=
os
.
MkdirAll
(
pluginDir
,
0777
)
err
:=
os
.
MkdirAll
(
pluginDir
,
0777
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to create plugin: %v"
,
err
)
t
.
Errorf
(
"Failed to create plugin: %v"
,
err
)
}
}
pluginExec
:=
path
.
Join
(
pluginDir
,
plugName
)
pluginExec
:=
file
path
.
Join
(
pluginDir
,
plugName
)
f
,
err
:=
os
.
Create
(
pluginExec
)
f
,
err
:=
os
.
Create
(
pluginExec
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to install plugin"
)
t
.
Errorf
(
"Failed to install plugin"
)
...
@@ -149,7 +149,7 @@ func installPluginUnderTest(t *testing.T, vendorName, plugName, tmpDir string, e
...
@@ -149,7 +149,7 @@ func installPluginUnderTest(t *testing.T, vendorName, plugName, tmpDir string, e
if
execTemplateData
==
nil
{
if
execTemplateData
==
nil
{
execTemplateData
=
&
map
[
string
]
interface
{}{
execTemplateData
=
&
map
[
string
]
interface
{}{
"DevicePath"
:
"/dev/sdx"
,
"DevicePath"
:
"/dev/sdx"
,
"OutputFile"
:
path
.
Join
(
pluginDir
,
plugName
+
".out"
),
"OutputFile"
:
file
path
.
Join
(
pluginDir
,
plugName
+
".out"
),
}
}
}
}
...
...
pkg/volume/flexvolume/plugin.go
View file @
b5c34d0c
...
@@ -18,7 +18,7 @@ package flexvolume
...
@@ -18,7 +18,7 @@ package flexvolume
import
(
import
(
"fmt"
"fmt"
"path"
"path
/filepath
"
"runtime"
"runtime"
"strings"
"strings"
"sync"
"sync"
...
@@ -69,7 +69,7 @@ type PluginFactory interface {
...
@@ -69,7 +69,7 @@ type PluginFactory interface {
type
pluginFactory
struct
{}
type
pluginFactory
struct
{}
func
(
pluginFactory
)
NewFlexVolumePlugin
(
pluginDir
,
name
string
,
runner
exec
.
Interface
)
(
volume
.
VolumePlugin
,
error
)
{
func
(
pluginFactory
)
NewFlexVolumePlugin
(
pluginDir
,
name
string
,
runner
exec
.
Interface
)
(
volume
.
VolumePlugin
,
error
)
{
execPath
:=
path
.
Join
(
pluginDir
,
name
)
execPath
:=
file
path
.
Join
(
pluginDir
,
name
)
driverName
:=
utilstrings
.
UnescapeQualifiedName
(
name
)
driverName
:=
utilstrings
.
UnescapeQualifiedName
(
name
)
...
@@ -105,7 +105,7 @@ func (plugin *flexVolumePlugin) Init(host volume.VolumeHost) error {
...
@@ -105,7 +105,7 @@ func (plugin *flexVolumePlugin) Init(host volume.VolumeHost) error {
func
(
plugin
*
flexVolumePlugin
)
getExecutable
()
string
{
func
(
plugin
*
flexVolumePlugin
)
getExecutable
()
string
{
parts
:=
strings
.
Split
(
plugin
.
driverName
,
"/"
)
parts
:=
strings
.
Split
(
plugin
.
driverName
,
"/"
)
execName
:=
parts
[
len
(
parts
)
-
1
]
execName
:=
parts
[
len
(
parts
)
-
1
]
execPath
:=
path
.
Join
(
plugin
.
execPath
,
execName
)
execPath
:=
file
path
.
Join
(
plugin
.
execPath
,
execName
)
if
runtime
.
GOOS
==
"windows"
{
if
runtime
.
GOOS
==
"windows"
{
execPath
=
util
.
GetWindowsPath
(
execPath
)
execPath
=
util
.
GetWindowsPath
(
execPath
)
}
}
...
@@ -315,8 +315,8 @@ func (plugin *flexVolumePlugin) getDeviceMountPath(spec *volume.Spec) (string, e
...
@@ -315,8 +315,8 @@ func (plugin *flexVolumePlugin) getDeviceMountPath(spec *volume.Spec) (string, e
return
""
,
fmt
.
Errorf
(
"GetVolumeName failed from getDeviceMountPath: %s"
,
err
)
return
""
,
fmt
.
Errorf
(
"GetVolumeName failed from getDeviceMountPath: %s"
,
err
)
}
}
mountsDir
:=
path
.
Join
(
plugin
.
host
.
GetPluginDir
(
flexVolumePluginName
),
plugin
.
driverName
,
"mounts"
)
mountsDir
:=
file
path
.
Join
(
plugin
.
host
.
GetPluginDir
(
flexVolumePluginName
),
plugin
.
driverName
,
"mounts"
)
return
path
.
Join
(
mountsDir
,
volumeName
),
nil
return
file
path
.
Join
(
mountsDir
,
volumeName
),
nil
}
}
func
(
plugin
*
flexVolumePlugin
)
RequiresFSResize
()
bool
{
func
(
plugin
*
flexVolumePlugin
)
RequiresFSResize
()
bool
{
...
...
pkg/volume/flexvolume/probe_test.go
View file @
b5c34d0c
...
@@ -18,7 +18,7 @@ package flexvolume
...
@@ -18,7 +18,7 @@ package flexvolume
import
(
import
(
"fmt"
"fmt"
"path"
"path
/filepath
"
"testing"
"testing"
"github.com/fsnotify/fsnotify"
"github.com/fsnotify/fsnotify"
...
@@ -71,8 +71,8 @@ func TestProberAddRemoveDriver(t *testing.T) {
...
@@ -71,8 +71,8 @@ func TestProberAddRemoveDriver(t *testing.T) {
// add driver
// add driver
const
driverName2
=
"fake-driver2"
const
driverName2
=
"fake-driver2"
driverPath
:=
path
.
Join
(
pluginDir
,
driverName2
)
driverPath
:=
file
path
.
Join
(
pluginDir
,
driverName2
)
executablePath
:=
path
.
Join
(
driverPath
,
driverName2
)
executablePath
:=
file
path
.
Join
(
driverPath
,
driverName2
)
installDriver
(
driverName2
,
fs
)
installDriver
(
driverName2
,
fs
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
driverPath
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
driverPath
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
executablePath
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
executablePath
)
...
@@ -95,7 +95,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
...
@@ -95,7 +95,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
// Call probe after a non-driver file is added in a subdirectory. should return 1 event.
// Call probe after a non-driver file is added in a subdirectory. should return 1 event.
fp
:=
path
.
Join
(
driverPath
,
"dummyfile"
)
fp
:=
file
path
.
Join
(
driverPath
,
"dummyfile"
)
fs
.
Create
(
fp
)
fs
.
Create
(
fp
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
fp
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
fp
)
...
@@ -115,7 +115,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
...
@@ -115,7 +115,7 @@ func TestProberAddRemoveDriver(t *testing.T) {
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
// Call probe after a subdirectory is added in a driver directory. should return 1 event.
// Call probe after a subdirectory is added in a driver directory. should return 1 event.
subdirPath
:=
path
.
Join
(
driverPath
,
"subdir"
)
subdirPath
:=
file
path
.
Join
(
driverPath
,
"subdir"
)
fs
.
Create
(
subdirPath
)
fs
.
Create
(
subdirPath
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
subdirPath
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
subdirPath
)
...
@@ -196,7 +196,7 @@ func TestRemovePluginDir(t *testing.T) {
...
@@ -196,7 +196,7 @@ func TestRemovePluginDir(t *testing.T) {
// Arrange
// Arrange
driverPath
,
fs
,
watcher
,
_
:=
initTestEnvironment
(
t
)
driverPath
,
fs
,
watcher
,
_
:=
initTestEnvironment
(
t
)
fs
.
RemoveAll
(
pluginDir
)
fs
.
RemoveAll
(
pluginDir
)
watcher
.
TriggerEvent
(
fsnotify
.
Remove
,
path
.
Join
(
driverPath
,
driverName
))
watcher
.
TriggerEvent
(
fsnotify
.
Remove
,
file
path
.
Join
(
driverPath
,
driverName
))
watcher
.
TriggerEvent
(
fsnotify
.
Remove
,
driverPath
)
watcher
.
TriggerEvent
(
fsnotify
.
Remove
,
driverPath
)
watcher
.
TriggerEvent
(
fsnotify
.
Remove
,
pluginDir
)
watcher
.
TriggerEvent
(
fsnotify
.
Remove
,
pluginDir
)
...
@@ -216,7 +216,7 @@ func TestNestedDriverDir(t *testing.T) {
...
@@ -216,7 +216,7 @@ func TestNestedDriverDir(t *testing.T) {
// test add testDriverName
// test add testDriverName
testDriverName
:=
"testDriverName"
testDriverName
:=
"testDriverName"
testDriverPath
:=
path
.
Join
(
pluginDir
,
testDriverName
)
testDriverPath
:=
file
path
.
Join
(
pluginDir
,
testDriverName
)
fs
.
MkdirAll
(
testDriverPath
,
0666
)
fs
.
MkdirAll
(
testDriverPath
,
0666
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
testDriverPath
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
testDriverPath
)
// Assert
// Assert
...
@@ -227,7 +227,7 @@ func TestNestedDriverDir(t *testing.T) {
...
@@ -227,7 +227,7 @@ func TestNestedDriverDir(t *testing.T) {
basePath
:=
testDriverPath
basePath
:=
testDriverPath
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
10
;
i
++
{
subdirName
:=
"subdirName"
subdirName
:=
"subdirName"
subdirPath
:=
path
.
Join
(
basePath
,
subdirName
)
subdirPath
:=
file
path
.
Join
(
basePath
,
subdirName
)
fs
.
MkdirAll
(
subdirPath
,
0666
)
fs
.
MkdirAll
(
subdirPath
,
0666
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
subdirPath
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
subdirPath
)
// Assert
// Assert
...
@@ -246,9 +246,9 @@ func TestProberMultipleEvents(t *testing.T) {
...
@@ -246,9 +246,9 @@ func TestProberMultipleEvents(t *testing.T) {
for
i
:=
0
;
i
<
iterations
;
i
++
{
for
i
:=
0
;
i
<
iterations
;
i
++
{
newDriver
:=
fmt
.
Sprintf
(
"multi-event-driver%d"
,
1
)
newDriver
:=
fmt
.
Sprintf
(
"multi-event-driver%d"
,
1
)
installDriver
(
newDriver
,
fs
)
installDriver
(
newDriver
,
fs
)
driverPath
:=
path
.
Join
(
pluginDir
,
newDriver
)
driverPath
:=
file
path
.
Join
(
pluginDir
,
newDriver
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
driverPath
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
driverPath
)
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
path
.
Join
(
driverPath
,
newDriver
))
watcher
.
TriggerEvent
(
fsnotify
.
Create
,
file
path
.
Join
(
driverPath
,
newDriver
))
}
}
// Act
// Act
...
@@ -284,9 +284,9 @@ func TestProberError(t *testing.T) {
...
@@ -284,9 +284,9 @@ func TestProberError(t *testing.T) {
// Installs a mock driver (an empty file) in the mock fs.
// Installs a mock driver (an empty file) in the mock fs.
func
installDriver
(
driverName
string
,
fs
utilfs
.
Filesystem
)
{
func
installDriver
(
driverName
string
,
fs
utilfs
.
Filesystem
)
{
driverPath
:=
path
.
Join
(
pluginDir
,
driverName
)
driverPath
:=
file
path
.
Join
(
pluginDir
,
driverName
)
fs
.
MkdirAll
(
driverPath
,
0666
)
fs
.
MkdirAll
(
driverPath
,
0666
)
fs
.
Create
(
path
.
Join
(
driverPath
,
driverName
))
fs
.
Create
(
file
path
.
Join
(
driverPath
,
driverName
))
}
}
// Initializes mocks, installs a single driver in the mock fs, then initializes prober.
// Initializes mocks, installs a single driver in the mock fs, then initializes prober.
...
@@ -303,7 +303,7 @@ func initTestEnvironment(t *testing.T) (
...
@@ -303,7 +303,7 @@ func initTestEnvironment(t *testing.T) (
fs
:
fs
,
fs
:
fs
,
factory
:
fakePluginFactory
{
error
:
false
},
factory
:
fakePluginFactory
{
error
:
false
},
}
}
driverPath
=
path
.
Join
(
pluginDir
,
driverName
)
driverPath
=
file
path
.
Join
(
pluginDir
,
driverName
)
installDriver
(
driverName
,
fs
)
installDriver
(
driverName
,
fs
)
prober
.
Init
()
prober
.
Init
()
...
...
pkg/volume/flocker/flocker.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package flocker
...
@@ -19,7 +19,7 @@ package flocker
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"time"
"time"
flockerapi
"github.com/clusterhq/flocker-go"
flockerapi
"github.com/clusterhq/flocker-go"
...
@@ -81,7 +81,7 @@ func getPath(uid types.UID, volName string, host volume.VolumeHost) string {
...
@@ -81,7 +81,7 @@ func getPath(uid types.UID, volName string, host volume.VolumeHost) string {
}
}
func
makeGlobalFlockerPath
(
datasetUUID
string
)
string
{
func
makeGlobalFlockerPath
(
datasetUUID
string
)
string
{
return
path
.
Join
(
defaultMountPath
,
datasetUUID
)
return
file
path
.
Join
(
defaultMountPath
,
datasetUUID
)
}
}
func
(
p
*
flockerPlugin
)
Init
(
host
volume
.
VolumeHost
)
error
{
func
(
p
*
flockerPlugin
)
Init
(
host
volume
.
VolumeHost
)
error
{
...
...
pkg/volume/gcepd/attacher.go
View file @
b5c34d0c
...
@@ -104,7 +104,7 @@ func (attacher *gcePersistentDiskAttacher) Attach(spec *volume.Spec, nodeName ty
...
@@ -104,7 +104,7 @@ func (attacher *gcePersistentDiskAttacher) Attach(spec *volume.Spec, nodeName ty
}
}
}
}
return
path
.
Join
(
diskByIDPath
,
diskGooglePrefix
+
pdName
),
nil
return
file
path
.
Join
(
diskByIDPath
,
diskGooglePrefix
+
pdName
),
nil
}
}
func
(
attacher
*
gcePersistentDiskAttacher
)
VolumesAreAttached
(
specs
[]
*
volume
.
Spec
,
nodeName
types
.
NodeName
)
(
map
[
*
volume
.
Spec
]
bool
,
error
)
{
func
(
attacher
*
gcePersistentDiskAttacher
)
VolumesAreAttached
(
specs
[]
*
volume
.
Spec
,
nodeName
types
.
NodeName
)
(
map
[
*
volume
.
Spec
]
bool
,
error
)
{
...
...
pkg/volume/gcepd/gce_pd.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"context"
"context"
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"runtime"
"runtime"
"strconv"
"strconv"
"strings"
"strings"
...
@@ -288,8 +288,8 @@ var _ volume.NodeExpandableVolumePlugin = &gcePersistentDiskPlugin{}
...
@@ -288,8 +288,8 @@ var _ volume.NodeExpandableVolumePlugin = &gcePersistentDiskPlugin{}
func
(
plugin
*
gcePersistentDiskPlugin
)
ConstructVolumeSpec
(
volumeName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
func
(
plugin
*
gcePersistentDiskPlugin
)
ConstructVolumeSpec
(
volumeName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
plugin
Dir
:=
plugin
.
host
.
GetPluginDir
(
plugin
.
GetPluginName
())
plugin
MntDir
:=
util
.
GetPluginMountDir
(
plugin
.
host
,
plugin
.
GetPluginName
())
sourceName
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
pluginDir
)
sourceName
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
plugin
Mnt
Dir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -427,7 +427,7 @@ func (b *gcePersistentDiskMounter) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -427,7 +427,7 @@ func (b *gcePersistentDiskMounter) SetUpAt(dir string, fsGroup *int64) error {
}
}
func
makeGlobalPDName
(
host
volume
.
VolumeHost
,
devName
string
)
string
{
func
makeGlobalPDName
(
host
volume
.
VolumeHost
,
devName
string
)
string
{
return
path
.
Join
(
host
.
GetPluginDir
(
gcePersistentDiskPluginName
),
mount
.
MountsInGlobalPDPath
,
devName
)
return
filepath
.
Join
(
host
.
GetPluginDir
(
gcePersistentDiskPluginName
),
util
.
MountsInGlobalPDPath
,
devName
)
}
}
func
(
b
*
gcePersistentDiskMounter
)
GetPath
()
string
{
func
(
b
*
gcePersistentDiskMounter
)
GetPath
()
string
{
...
...
pkg/volume/gcepd/gce_pd_block.go
View file @
b5c34d0c
...
@@ -18,7 +18,6 @@ package gcepd
...
@@ -18,7 +18,6 @@ package gcepd
import
(
import
(
"fmt"
"fmt"
"path"
"path/filepath"
"path/filepath"
"strconv"
"strconv"
...
@@ -163,7 +162,7 @@ func (pd *gcePersistentDisk) GetGlobalMapPath(spec *volume.Spec) (string, error)
...
@@ -163,7 +162,7 @@ func (pd *gcePersistentDisk) GetGlobalMapPath(spec *volume.Spec) (string, error)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
return
path
.
Join
(
pd
.
plugin
.
host
.
GetVolumeDevicePluginDir
(
gcePersistentDiskPluginName
),
string
(
volumeSource
.
PDName
)),
nil
return
file
path
.
Join
(
pd
.
plugin
.
host
.
GetVolumeDevicePluginDir
(
gcePersistentDiskPluginName
),
string
(
volumeSource
.
PDName
)),
nil
}
}
// GetPodDeviceMapPath returns pod device map path and volume name
// GetPodDeviceMapPath returns pod device map path and volume name
...
...
pkg/volume/gcepd/gce_pd_block_test.go
View file @
b5c34d0c
...
@@ -18,7 +18,7 @@ package gcepd
...
@@ -18,7 +18,7 @@ package gcepd
import
(
import
(
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -47,7 +47,7 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) {
...
@@ -47,7 +47,7 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) {
//deferred clean up
//deferred clean up
defer
os
.
RemoveAll
(
tmpVDir
)
defer
os
.
RemoveAll
(
tmpVDir
)
expectedGlobalPath
:=
path
.
Join
(
tmpVDir
,
testGlobalPath
)
expectedGlobalPath
:=
file
path
.
Join
(
tmpVDir
,
testGlobalPath
)
//Bad Path
//Bad Path
badspec
,
err
:=
getVolumeSpecFromGlobalMapPath
(
""
)
badspec
,
err
:=
getVolumeSpecFromGlobalMapPath
(
""
)
...
@@ -102,8 +102,8 @@ func TestGetPodAndPluginMapPaths(t *testing.T) {
...
@@ -102,8 +102,8 @@ func TestGetPodAndPluginMapPaths(t *testing.T) {
//deferred clean up
//deferred clean up
defer
os
.
RemoveAll
(
tmpVDir
)
defer
os
.
RemoveAll
(
tmpVDir
)
expectedGlobalPath
:=
path
.
Join
(
tmpVDir
,
testGlobalPath
)
expectedGlobalPath
:=
file
path
.
Join
(
tmpVDir
,
testGlobalPath
)
expectedPodPath
:=
path
.
Join
(
tmpVDir
,
testPodPath
)
expectedPodPath
:=
file
path
.
Join
(
tmpVDir
,
testPodPath
)
spec
:=
getTestVolume
(
false
,
tmpVDir
,
true
/*isBlock*/
)
spec
:=
getTestVolume
(
false
,
tmpVDir
,
true
/*isBlock*/
)
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
...
...
pkg/volume/gcepd/gce_pd_test.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package gcepd
...
@@ -19,7 +19,7 @@ package gcepd
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"reflect"
"reflect"
"sort"
"sort"
"testing"
"testing"
...
@@ -135,7 +135,7 @@ func TestPlugin(t *testing.T) {
...
@@ -135,7 +135,7 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"Got a nil Mounter"
)
t
.
Errorf
(
"Got a nil Mounter"
)
}
}
volPath
:=
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~gce-pd/vol1"
)
volPath
:=
file
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~gce-pd/vol1"
)
path
:=
mounter
.
GetPath
()
path
:=
mounter
.
GetPath
()
if
path
!=
volPath
{
if
path
!=
volPath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
...
...
pkg/volume/gcepd/gce_util.go
View file @
b5c34d0c
...
@@ -18,7 +18,6 @@ package gcepd
...
@@ -18,7 +18,6 @@ package gcepd
import
(
import
(
"fmt"
"fmt"
"path"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"strings"
"strings"
...
@@ -272,8 +271,8 @@ func parseScsiSerial(output string) (string, error) {
...
@@ -272,8 +271,8 @@ func parseScsiSerial(output string) (string, error) {
// Returns list of all /dev/disk/by-id/* paths for given PD.
// Returns list of all /dev/disk/by-id/* paths for given PD.
func
getDiskByIDPaths
(
pdName
string
,
partition
string
)
[]
string
{
func
getDiskByIDPaths
(
pdName
string
,
partition
string
)
[]
string
{
devicePaths
:=
[]
string
{
devicePaths
:=
[]
string
{
path
.
Join
(
diskByIDPath
,
diskGooglePrefix
+
pdName
),
file
path
.
Join
(
diskByIDPath
,
diskGooglePrefix
+
pdName
),
path
.
Join
(
diskByIDPath
,
diskScsiGooglePrefix
+
pdName
),
file
path
.
Join
(
diskByIDPath
,
diskScsiGooglePrefix
+
pdName
),
}
}
if
partition
!=
""
{
if
partition
!=
""
{
...
...
pkg/volume/git_repo/git_repo.go
View file @
b5c34d0c
...
@@ -19,7 +19,6 @@ package git_repo
...
@@ -19,7 +19,6 @@ package git_repo
import
(
import
(
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"path"
"path/filepath"
"path/filepath"
"strings"
"strings"
...
@@ -225,10 +224,10 @@ func (b *gitRepoVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -225,10 +224,10 @@ func (b *gitRepoVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
switch
{
switch
{
case
len
(
b
.
target
)
!=
0
&&
filepath
.
Clean
(
b
.
target
)
==
"."
:
case
len
(
b
.
target
)
!=
0
&&
filepath
.
Clean
(
b
.
target
)
==
"."
:
// if target dir is '.', use the current dir
// if target dir is '.', use the current dir
subdir
=
path
.
Join
(
dir
)
subdir
=
file
path
.
Join
(
dir
)
case
len
(
files
)
==
1
:
case
len
(
files
)
==
1
:
// if target is not '.', use the generated folder
// if target is not '.', use the generated folder
subdir
=
path
.
Join
(
dir
,
files
[
0
]
.
Name
())
subdir
=
file
path
.
Join
(
dir
,
files
[
0
]
.
Name
())
default
:
default
:
// if target is not '.', but generated many files, it's wrong
// if target is not '.', but generated many files, it's wrong
return
fmt
.
Errorf
(
"unexpected directory contents: %v"
,
files
)
return
fmt
.
Errorf
(
"unexpected directory contents: %v"
,
files
)
...
@@ -248,7 +247,7 @@ func (b *gitRepoVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -248,7 +247,7 @@ func (b *gitRepoVolumeMounter) SetUpAt(dir string, fsGroup *int64) error {
}
}
func
(
b
*
gitRepoVolumeMounter
)
getMetaDir
()
string
{
func
(
b
*
gitRepoVolumeMounter
)
getMetaDir
()
string
{
return
path
.
Join
(
b
.
plugin
.
host
.
GetPodPluginDir
(
b
.
podUID
,
utilstrings
.
EscapeQualifiedName
(
gitRepoPluginName
)),
b
.
volName
)
return
file
path
.
Join
(
b
.
plugin
.
host
.
GetPodPluginDir
(
b
.
podUID
,
utilstrings
.
EscapeQualifiedName
(
gitRepoPluginName
)),
b
.
volName
)
}
}
func
(
b
*
gitRepoVolumeMounter
)
execCommand
(
command
string
,
args
[]
string
,
dir
string
)
([]
byte
,
error
)
{
func
(
b
*
gitRepoVolumeMounter
)
execCommand
(
command
string
,
args
[]
string
,
dir
string
)
([]
byte
,
error
)
{
...
...
pkg/volume/git_repo/git_repo_test.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path
/filepath
"
"reflect"
"reflect"
"strings"
"strings"
"testing"
"testing"
...
@@ -393,7 +393,7 @@ func doTestSetUp(scenario struct {
...
@@ -393,7 +393,7 @@ func doTestSetUp(scenario struct {
if
expected
.
cmd
[
1
]
==
"clone"
{
if
expected
.
cmd
[
1
]
==
"clone"
{
fakeOutputs
=
append
(
fakeOutputs
,
func
()
([]
byte
,
error
)
{
fakeOutputs
=
append
(
fakeOutputs
,
func
()
([]
byte
,
error
)
{
// git clone, it creates new dir/files
// git clone, it creates new dir/files
os
.
MkdirAll
(
path
.
Join
(
fcmd
.
Dirs
[
0
],
expected
.
dir
),
0750
)
os
.
MkdirAll
(
file
path
.
Join
(
fcmd
.
Dirs
[
0
],
expected
.
dir
),
0750
)
return
[]
byte
{},
nil
return
[]
byte
{},
nil
})
})
}
else
{
}
else
{
...
...
pkg/volume/glusterfs/glusterfs.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"fmt"
"fmt"
"math"
"math"
"os"
"os"
"path"
"path
/filepath
"
"runtime"
"runtime"
"strconv"
"strconv"
dstrings
"strings"
dstrings
"strings"
...
@@ -347,7 +347,7 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error {
...
@@ -347,7 +347,7 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error {
// If logfile has not been provided, create driver specific log file.
// If logfile has not been provided, create driver specific log file.
if
!
hasLogFile
{
if
!
hasLogFile
{
p
:=
path
.
Join
(
b
.
glusterfs
.
plugin
.
host
.
GetPluginDir
(
glusterfsPluginName
),
b
.
glusterfs
.
volName
)
p
:=
file
path
.
Join
(
b
.
glusterfs
.
plugin
.
host
.
GetPluginDir
(
glusterfsPluginName
),
b
.
glusterfs
.
volName
)
if
err
:=
os
.
MkdirAll
(
p
,
0750
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
p
,
0750
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to create directory %v: %v"
,
p
,
err
)
return
fmt
.
Errorf
(
"failed to create directory %v: %v"
,
p
,
err
)
}
}
...
@@ -355,7 +355,7 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error {
...
@@ -355,7 +355,7 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error {
// adding log-level ERROR to remove noise
// adding log-level ERROR to remove noise
// and more specific log path so each pod has
// and more specific log path so each pod has
// its own log based on PV + Pod
// its own log based on PV + Pod
log
=
path
.
Join
(
p
,
b
.
pod
.
Name
+
"-glusterfs.log"
)
log
=
file
path
.
Join
(
p
,
b
.
pod
.
Name
+
"-glusterfs.log"
)
// Use derived log file in gluster fuse mount
// Use derived log file in gluster fuse mount
options
=
append
(
options
,
"log-file="
+
log
)
options
=
append
(
options
,
"log-file="
+
log
)
...
...
pkg/volume/iscsi/iscsi_util.go
View file @
b5c34d0c
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"strconv"
"strconv"
...
@@ -186,12 +185,12 @@ func getDevicePrefixRefCount(mounter mount.Interface, deviceNamePrefix string) (
...
@@ -186,12 +185,12 @@ func getDevicePrefixRefCount(mounter mount.Interface, deviceNamePrefix string) (
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/iscsi/iface_name/portal-some_iqn-lun-lun_id
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/iscsi/iface_name/portal-some_iqn-lun-lun_id
func
makePDNameInternal
(
host
volume
.
VolumeHost
,
portal
string
,
iqn
string
,
lun
string
,
iface
string
)
string
{
func
makePDNameInternal
(
host
volume
.
VolumeHost
,
portal
string
,
iqn
string
,
lun
string
,
iface
string
)
string
{
return
path
.
Join
(
host
.
GetPluginDir
(
iscsiPluginName
),
"iface-"
+
iface
,
portal
+
"-"
+
iqn
+
"-lun-"
+
lun
)
return
file
path
.
Join
(
host
.
GetPluginDir
(
iscsiPluginName
),
"iface-"
+
iface
,
portal
+
"-"
+
iqn
+
"-lun-"
+
lun
)
}
}
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/iscsi/volumeDevices/iface_name/portal-some_iqn-lun-lun_id
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/iscsi/volumeDevices/iface_name/portal-some_iqn-lun-lun_id
func
makeVDPDNameInternal
(
host
volume
.
VolumeHost
,
portal
string
,
iqn
string
,
lun
string
,
iface
string
)
string
{
func
makeVDPDNameInternal
(
host
volume
.
VolumeHost
,
portal
string
,
iqn
string
,
lun
string
,
iface
string
)
string
{
return
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
iscsiPluginName
),
"iface-"
+
iface
,
portal
+
"-"
+
iqn
+
"-lun-"
+
lun
)
return
file
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
iscsiPluginName
),
"iface-"
+
iface
,
portal
+
"-"
+
iqn
+
"-lun-"
+
lun
)
}
}
type
ISCSIUtil
struct
{}
type
ISCSIUtil
struct
{}
...
@@ -207,7 +206,7 @@ func (util *ISCSIUtil) MakeGlobalVDPDName(iscsi iscsiDisk) string {
...
@@ -207,7 +206,7 @@ func (util *ISCSIUtil) MakeGlobalVDPDName(iscsi iscsiDisk) string {
}
}
func
(
util
*
ISCSIUtil
)
persistISCSI
(
conf
iscsiDisk
,
mnt
string
)
error
{
func
(
util
*
ISCSIUtil
)
persistISCSI
(
conf
iscsiDisk
,
mnt
string
)
error
{
file
:=
path
.
Join
(
mnt
,
"iscsi.json"
)
file
:=
file
path
.
Join
(
mnt
,
"iscsi.json"
)
fp
,
err
:=
os
.
Create
(
file
)
fp
,
err
:=
os
.
Create
(
file
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"iscsi: create %s err %s"
,
file
,
err
)
return
fmt
.
Errorf
(
"iscsi: create %s err %s"
,
file
,
err
)
...
@@ -221,7 +220,7 @@ func (util *ISCSIUtil) persistISCSI(conf iscsiDisk, mnt string) error {
...
@@ -221,7 +220,7 @@ func (util *ISCSIUtil) persistISCSI(conf iscsiDisk, mnt string) error {
}
}
func
(
util
*
ISCSIUtil
)
loadISCSI
(
conf
*
iscsiDisk
,
mnt
string
)
error
{
func
(
util
*
ISCSIUtil
)
loadISCSI
(
conf
*
iscsiDisk
,
mnt
string
)
error
{
file
:=
path
.
Join
(
mnt
,
"iscsi.json"
)
file
:=
file
path
.
Join
(
mnt
,
"iscsi.json"
)
fp
,
err
:=
os
.
Open
(
file
)
fp
,
err
:=
os
.
Open
(
file
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"iscsi: open %s err %s"
,
file
,
err
)
return
fmt
.
Errorf
(
"iscsi: open %s err %s"
,
file
,
err
)
...
...
pkg/volume/local/local.go
View file @
b5c34d0c
...
@@ -222,7 +222,7 @@ func (plugin *localVolumePlugin) ConstructBlockVolumeSpec(podUID types.UID, volu
...
@@ -222,7 +222,7 @@ func (plugin *localVolumePlugin) ConstructBlockVolumeSpec(podUID types.UID, volu
}
}
func
(
plugin
*
localVolumePlugin
)
generateBlockDeviceBaseGlobalPath
()
string
{
func
(
plugin
*
localVolumePlugin
)
generateBlockDeviceBaseGlobalPath
()
string
{
return
filepath
.
Join
(
plugin
.
host
.
GetPluginDir
(
localVolumePluginName
),
mount
.
MountsInGlobalPDPath
)
return
filepath
.
Join
(
plugin
.
host
.
GetPluginDir
(
localVolumePluginName
),
util
.
MountsInGlobalPDPath
)
}
}
func
(
plugin
*
localVolumePlugin
)
getGlobalLocalPath
(
spec
*
volume
.
Spec
)
(
string
,
error
)
{
func
(
plugin
*
localVolumePlugin
)
getGlobalLocalPath
(
spec
*
volume
.
Spec
)
(
string
,
error
)
{
...
...
pkg/volume/local/local_test.go
View file @
b5c34d0c
...
@@ -21,7 +21,6 @@ package local
...
@@ -21,7 +21,6 @@ package local
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"reflect"
"reflect"
"runtime"
"runtime"
...
@@ -302,7 +301,7 @@ func TestMountUnmount(t *testing.T) {
...
@@ -302,7 +301,7 @@ func TestMountUnmount(t *testing.T) {
t
.
Fatalf
(
"Got a nil Mounter"
)
t
.
Fatalf
(
"Got a nil Mounter"
)
}
}
volPath
:=
path
.
Join
(
tmpDir
,
testMountPath
)
volPath
:=
file
path
.
Join
(
tmpDir
,
testMountPath
)
path
:=
mounter
.
GetPath
()
path
:=
mounter
.
GetPath
()
if
path
!=
volPath
{
if
path
!=
volPath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
...
@@ -356,7 +355,7 @@ func TestMapUnmap(t *testing.T) {
...
@@ -356,7 +355,7 @@ func TestMapUnmap(t *testing.T) {
t
.
Fatalf
(
"Got a nil Mounter"
)
t
.
Fatalf
(
"Got a nil Mounter"
)
}
}
expectedGlobalPath
:=
path
.
Join
(
tmpDir
,
testGlobalPath
)
expectedGlobalPath
:=
file
path
.
Join
(
tmpDir
,
testGlobalPath
)
globalPath
,
err
:=
mapper
.
GetGlobalMapPath
(
volSpec
)
globalPath
,
err
:=
mapper
.
GetGlobalMapPath
(
volSpec
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to get global path: %v"
,
err
)
t
.
Errorf
(
"Failed to get global path: %v"
,
err
)
...
@@ -364,7 +363,7 @@ func TestMapUnmap(t *testing.T) {
...
@@ -364,7 +363,7 @@ func TestMapUnmap(t *testing.T) {
if
globalPath
!=
expectedGlobalPath
{
if
globalPath
!=
expectedGlobalPath
{
t
.
Errorf
(
"Got unexpected path: %s, expected %s"
,
globalPath
,
expectedGlobalPath
)
t
.
Errorf
(
"Got unexpected path: %s, expected %s"
,
globalPath
,
expectedGlobalPath
)
}
}
expectedPodPath
:=
path
.
Join
(
tmpDir
,
testPodPath
)
expectedPodPath
:=
file
path
.
Join
(
tmpDir
,
testPodPath
)
podPath
,
volName
:=
mapper
.
GetPodDeviceMapPath
()
podPath
,
volName
:=
mapper
.
GetPodDeviceMapPath
()
if
podPath
!=
expectedPodPath
{
if
podPath
!=
expectedPodPath
{
t
.
Errorf
(
"Got unexpected pod path: %s, expected %s"
,
podPath
,
expectedPodPath
)
t
.
Errorf
(
"Got unexpected pod path: %s, expected %s"
,
podPath
,
expectedPodPath
)
...
@@ -407,7 +406,7 @@ func testFSGroupMount(plug volume.VolumePlugin, pod *v1.Pod, tmpDir string, fsGr
...
@@ -407,7 +406,7 @@ func testFSGroupMount(plug volume.VolumePlugin, pod *v1.Pod, tmpDir string, fsGr
return
fmt
.
Errorf
(
"Got a nil Mounter"
)
return
fmt
.
Errorf
(
"Got a nil Mounter"
)
}
}
volPath
:=
path
.
Join
(
tmpDir
,
testMountPath
)
volPath
:=
file
path
.
Join
(
tmpDir
,
testMountPath
)
path
:=
mounter
.
GetPath
()
path
:=
mounter
.
GetPath
()
if
path
!=
volPath
{
if
path
!=
volPath
{
return
fmt
.
Errorf
(
"Got unexpected path: %s"
,
path
)
return
fmt
.
Errorf
(
"Got unexpected path: %s"
,
path
)
...
@@ -423,7 +422,7 @@ func TestConstructVolumeSpec(t *testing.T) {
...
@@ -423,7 +422,7 @@ func TestConstructVolumeSpec(t *testing.T) {
tmpDir
,
plug
:=
getPlugin
(
t
)
tmpDir
,
plug
:=
getPlugin
(
t
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
volPath
:=
path
.
Join
(
tmpDir
,
testMountPath
)
volPath
:=
file
path
.
Join
(
tmpDir
,
testMountPath
)
spec
,
err
:=
plug
.
ConstructVolumeSpec
(
testPVName
,
volPath
)
spec
,
err
:=
plug
.
ConstructVolumeSpec
(
testPVName
,
volPath
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"ConstructVolumeSpec() failed: %v"
,
err
)
t
.
Errorf
(
"ConstructVolumeSpec() failed: %v"
,
err
)
...
@@ -464,7 +463,7 @@ func TestConstructBlockVolumeSpec(t *testing.T) {
...
@@ -464,7 +463,7 @@ func TestConstructBlockVolumeSpec(t *testing.T) {
tmpDir
,
plug
:=
getBlockPlugin
(
t
)
tmpDir
,
plug
:=
getBlockPlugin
(
t
)
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
podPath
:=
path
.
Join
(
tmpDir
,
testPodPath
)
podPath
:=
file
path
.
Join
(
tmpDir
,
testPodPath
)
spec
,
err
:=
plug
.
ConstructBlockVolumeSpec
(
types
.
UID
(
"poduid"
),
testPVName
,
podPath
)
spec
,
err
:=
plug
.
ConstructBlockVolumeSpec
(
types
.
UID
(
"poduid"
),
testPVName
,
podPath
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"ConstructBlockVolumeSpec() failed: %v"
,
err
)
t
.
Errorf
(
"ConstructBlockVolumeSpec() failed: %v"
,
err
)
...
...
pkg/volume/photon_pd/attacher.go
View file @
b5c34d0c
...
@@ -95,7 +95,7 @@ func (attacher *photonPersistentDiskAttacher) Attach(spec *volume.Spec, nodeName
...
@@ -95,7 +95,7 @@ func (attacher *photonPersistentDiskAttacher) Attach(spec *volume.Spec, nodeName
}
}
PdidWithNoHypens
:=
strings
.
Replace
(
volumeSource
.
PdID
,
"-"
,
""
,
-
1
)
PdidWithNoHypens
:=
strings
.
Replace
(
volumeSource
.
PdID
,
"-"
,
""
,
-
1
)
return
path
.
Join
(
diskByIDPath
,
diskPhotonPrefix
+
PdidWithNoHypens
),
nil
return
file
path
.
Join
(
diskByIDPath
,
diskPhotonPrefix
+
PdidWithNoHypens
),
nil
}
}
func
(
attacher
*
photonPersistentDiskAttacher
)
VolumesAreAttached
(
specs
[]
*
volume
.
Spec
,
nodeName
types
.
NodeName
)
(
map
[
*
volume
.
Spec
]
bool
,
error
)
{
func
(
attacher
*
photonPersistentDiskAttacher
)
VolumesAreAttached
(
specs
[]
*
volume
.
Spec
,
nodeName
types
.
NodeName
)
(
map
[
*
volume
.
Spec
]
bool
,
error
)
{
...
...
pkg/volume/photon_pd/photon_pd.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package photon_pd
...
@@ -19,7 +19,7 @@ package photon_pd
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
...
@@ -136,8 +136,8 @@ func (plugin *photonPersistentDiskPlugin) newUnmounterInternal(volName string, p
...
@@ -136,8 +136,8 @@ func (plugin *photonPersistentDiskPlugin) newUnmounterInternal(volName string, p
func
(
plugin
*
photonPersistentDiskPlugin
)
ConstructVolumeSpec
(
volumeSpecName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
func
(
plugin
*
photonPersistentDiskPlugin
)
ConstructVolumeSpec
(
volumeSpecName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
plugin
Dir
:=
plugin
.
host
.
GetPluginDir
(
plugin
.
GetPluginName
())
plugin
MntDir
:=
util
.
GetPluginMountDir
(
plugin
.
host
,
plugin
.
GetPluginName
())
pdID
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
pluginDir
)
pdID
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
plugin
Mnt
Dir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -285,7 +285,7 @@ func (c *photonPersistentDiskUnmounter) TearDownAt(dir string) error {
...
@@ -285,7 +285,7 @@ func (c *photonPersistentDiskUnmounter) TearDownAt(dir string) error {
}
}
func
makeGlobalPDPath
(
host
volume
.
VolumeHost
,
devName
string
)
string
{
func
makeGlobalPDPath
(
host
volume
.
VolumeHost
,
devName
string
)
string
{
return
path
.
Join
(
host
.
GetPluginDir
(
photonPersistentDiskPluginName
),
mount
.
MountsInGlobalPDPath
,
devName
)
return
filepath
.
Join
(
host
.
GetPluginDir
(
photonPersistentDiskPluginName
),
util
.
MountsInGlobalPDPath
,
devName
)
}
}
func
(
ppd
*
photonPersistentDisk
)
GetPath
()
string
{
func
(
ppd
*
photonPersistentDisk
)
GetPath
()
string
{
...
...
pkg/volume/photon_pd/photon_pd_test.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package photon_pd
...
@@ -19,7 +19,7 @@ package photon_pd
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -122,7 +122,7 @@ func TestPlugin(t *testing.T) {
...
@@ -122,7 +122,7 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"Got a nil Mounter"
)
t
.
Errorf
(
"Got a nil Mounter"
)
}
}
volPath
:=
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~photon-pd/vol1"
)
volPath
:=
file
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~photon-pd/vol1"
)
path
:=
mounter
.
GetPath
()
path
:=
mounter
.
GetPath
()
if
path
!=
volPath
{
if
path
!=
volPath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
...
...
pkg/volume/portworx/portworx_test.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package portworx
...
@@ -19,7 +19,7 @@ package portworx
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -157,7 +157,7 @@ func TestPlugin(t *testing.T) {
...
@@ -157,7 +157,7 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"Got a nil Mounter"
)
t
.
Errorf
(
"Got a nil Mounter"
)
}
}
volPath
:=
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~portworx-volume/vol1"
)
volPath
:=
file
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~portworx-volume/vol1"
)
path
:=
mounter
.
GetPath
()
path
:=
mounter
.
GetPath
()
if
path
!=
volPath
{
if
path
!=
volPath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
...
...
pkg/volume/projected/projected_test.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path
/filepath
"
"reflect"
"reflect"
"strings"
"strings"
"testing"
"testing"
...
@@ -1069,14 +1069,14 @@ func TestPluginOptional(t *testing.T) {
...
@@ -1069,14 +1069,14 @@ func TestPluginOptional(t *testing.T) {
}
}
}
}
datadirSymlink
:=
path
.
Join
(
volumePath
,
"..data"
)
datadirSymlink
:=
file
path
.
Join
(
volumePath
,
"..data"
)
datadir
,
err
:=
os
.
Readlink
(
datadirSymlink
)
datadir
,
err
:=
os
.
Readlink
(
datadirSymlink
)
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
t
.
Fatalf
(
"couldn't find volume path's data dir, %s"
,
datadirSymlink
)
t
.
Fatalf
(
"couldn't find volume path's data dir, %s"
,
datadirSymlink
)
}
else
if
err
!=
nil
{
}
else
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't read symlink, %s"
,
datadirSymlink
)
t
.
Fatalf
(
"couldn't read symlink, %s"
,
datadirSymlink
)
}
}
datadirPath
:=
path
.
Join
(
volumePath
,
datadir
)
datadirPath
:=
file
path
.
Join
(
volumePath
,
datadir
)
infos
,
err
:=
ioutil
.
ReadDir
(
volumePath
)
infos
,
err
:=
ioutil
.
ReadDir
(
volumePath
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1227,7 +1227,7 @@ func makeProjection(name string, defaultMode int32, kind string) *v1.ProjectedVo
...
@@ -1227,7 +1227,7 @@ func makeProjection(name string, defaultMode int32, kind string) *v1.ProjectedVo
func
doTestSecretDataInVolume
(
volumePath
string
,
secret
v1
.
Secret
,
t
*
testing
.
T
)
{
func
doTestSecretDataInVolume
(
volumePath
string
,
secret
v1
.
Secret
,
t
*
testing
.
T
)
{
for
key
,
value
:=
range
secret
.
Data
{
for
key
,
value
:=
range
secret
.
Data
{
secretDataHostPath
:=
path
.
Join
(
volumePath
,
key
)
secretDataHostPath
:=
file
path
.
Join
(
volumePath
,
key
)
if
_
,
err
:=
os
.
Stat
(
secretDataHostPath
);
err
!=
nil
{
if
_
,
err
:=
os
.
Stat
(
secretDataHostPath
);
err
!=
nil
{
t
.
Fatalf
(
"SetUp() failed, couldn't find secret data on disk: %v"
,
secretDataHostPath
)
t
.
Fatalf
(
"SetUp() failed, couldn't find secret data on disk: %v"
,
secretDataHostPath
)
}
else
{
}
else
{
...
...
pkg/volume/quobyte/quobyte.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package quobyte
...
@@ -19,7 +19,7 @@ package quobyte
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
gostrings
"strings"
gostrings
"strings"
"github.com/pborman/uuid"
"github.com/pborman/uuid"
...
@@ -286,7 +286,7 @@ func (quobyteVolume *quobyte) GetPath() string {
...
@@ -286,7 +286,7 @@ func (quobyteVolume *quobyte) GetPath() string {
// Quobyte has only one mount in the PluginDir where all Volumes are mounted
// Quobyte has only one mount in the PluginDir where all Volumes are mounted
// The Quobyte client does a fixed-user mapping
// The Quobyte client does a fixed-user mapping
pluginDir
:=
quobyteVolume
.
plugin
.
host
.
GetPluginDir
(
utilstrings
.
EscapeQualifiedName
(
quobytePluginName
))
pluginDir
:=
quobyteVolume
.
plugin
.
host
.
GetPluginDir
(
utilstrings
.
EscapeQualifiedName
(
quobytePluginName
))
return
path
.
Join
(
pluginDir
,
fmt
.
Sprintf
(
"%s#%s@%s"
,
user
,
group
,
quobyteVolume
.
volume
))
return
file
path
.
Join
(
pluginDir
,
fmt
.
Sprintf
(
"%s#%s@%s"
,
user
,
group
,
quobyteVolume
.
volume
))
}
}
type
quobyteUnmounter
struct
{
type
quobyteUnmounter
struct
{
...
...
pkg/volume/rbd/rbd.go
View file @
b5c34d0c
...
@@ -374,8 +374,8 @@ func (plugin *rbdPlugin) newUnmounterInternal(volName string, podUID types.UID,
...
@@ -374,8 +374,8 @@ func (plugin *rbdPlugin) newUnmounterInternal(volName string, podUID types.UID,
func
(
plugin
*
rbdPlugin
)
ConstructVolumeSpec
(
volumeName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
func
(
plugin
*
rbdPlugin
)
ConstructVolumeSpec
(
volumeName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
plugin
Dir
:=
plugin
.
host
.
GetPluginDir
(
plugin
.
GetPluginName
())
plugin
MntDir
:=
volutil
.
GetPluginMountDir
(
plugin
.
host
,
plugin
.
GetPluginName
())
sourceName
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
pluginDir
)
sourceName
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
plugin
Mnt
Dir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/volume/rbd/rbd_util.go
View file @
b5c34d0c
...
@@ -27,7 +27,7 @@ import (
...
@@ -27,7 +27,7 @@ import (
"io/ioutil"
"io/ioutil"
"os"
"os"
"os/exec"
"os/exec"
"path"
"path
/filepath
"
"strconv"
"strconv"
"strings"
"strings"
"time"
"time"
...
@@ -41,6 +41,7 @@ import (
...
@@ -41,6 +41,7 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/node"
"k8s.io/kubernetes/pkg/util/node"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume"
volutil
"k8s.io/kubernetes/pkg/volume/util"
utilpath
"k8s.io/utils/path"
utilpath
"k8s.io/utils/path"
)
)
...
@@ -79,7 +80,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
...
@@ -79,7 +80,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
// https://github.com/torvalds/linux/blob/master/drivers/block/rbd.c
// https://github.com/torvalds/linux/blob/master/drivers/block/rbd.c
name
:=
f
.
Name
()
name
:=
f
.
Name
()
// First match pool, then match name.
// First match pool, then match name.
poolFile
:=
path
.
Join
(
sys_path
,
name
,
"pool"
)
poolFile
:=
file
path
.
Join
(
sys_path
,
name
,
"pool"
)
poolBytes
,
err
:=
ioutil
.
ReadFile
(
poolFile
)
poolBytes
,
err
:=
ioutil
.
ReadFile
(
poolFile
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
V
(
4
)
.
Infof
(
"error reading %s: %v"
,
poolFile
,
err
)
klog
.
V
(
4
)
.
Infof
(
"error reading %s: %v"
,
poolFile
,
err
)
...
@@ -89,7 +90,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
...
@@ -89,7 +90,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
klog
.
V
(
4
)
.
Infof
(
"device %s is not %q: %q"
,
name
,
pool
,
string
(
poolBytes
))
klog
.
V
(
4
)
.
Infof
(
"device %s is not %q: %q"
,
name
,
pool
,
string
(
poolBytes
))
continue
continue
}
}
imgFile
:=
path
.
Join
(
sys_path
,
name
,
"name"
)
imgFile
:=
file
path
.
Join
(
sys_path
,
name
,
"name"
)
imgBytes
,
err
:=
ioutil
.
ReadFile
(
imgFile
)
imgBytes
,
err
:=
ioutil
.
ReadFile
(
imgFile
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
V
(
4
)
.
Infof
(
"error reading %s: %v"
,
imgFile
,
err
)
klog
.
V
(
4
)
.
Infof
(
"error reading %s: %v"
,
imgFile
,
err
)
...
@@ -159,12 +160,12 @@ func getNbdDevFromImageAndPool(pool string, image string) (string, bool) {
...
@@ -159,12 +160,12 @@ func getNbdDevFromImageAndPool(pool string, image string) (string, bool) {
klog
.
V
(
4
)
.
Infof
(
"error reading nbd info directory %s: %v"
,
nbdPath
,
err
)
klog
.
V
(
4
)
.
Infof
(
"error reading nbd info directory %s: %v"
,
nbdPath
,
err
)
continue
continue
}
}
pidBytes
,
err
:=
ioutil
.
ReadFile
(
path
.
Join
(
nbdPath
,
"pid"
))
pidBytes
,
err
:=
ioutil
.
ReadFile
(
file
path
.
Join
(
nbdPath
,
"pid"
))
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
V
(
5
)
.
Infof
(
"did not find valid pid file in dir %s: %v"
,
nbdPath
,
err
)
klog
.
V
(
5
)
.
Infof
(
"did not find valid pid file in dir %s: %v"
,
nbdPath
,
err
)
continue
continue
}
}
cmdlineFileName
:=
path
.
Join
(
"/proc"
,
strings
.
TrimSpace
(
string
(
pidBytes
)),
"cmdline"
)
cmdlineFileName
:=
file
path
.
Join
(
"/proc"
,
strings
.
TrimSpace
(
string
(
pidBytes
)),
"cmdline"
)
rawCmdline
,
err
:=
ioutil
.
ReadFile
(
cmdlineFileName
)
rawCmdline
,
err
:=
ioutil
.
ReadFile
(
cmdlineFileName
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
V
(
4
)
.
Infof
(
"failed to read cmdline file %s: %v"
,
cmdlineFileName
,
err
)
klog
.
V
(
4
)
.
Infof
(
"failed to read cmdline file %s: %v"
,
cmdlineFileName
,
err
)
...
@@ -185,7 +186,7 @@ func getNbdDevFromImageAndPool(pool string, image string) (string, bool) {
...
@@ -185,7 +186,7 @@ func getNbdDevFromImageAndPool(pool string, image string) (string, bool) {
nbdPath
,
imgPath
,
cmdlineArgs
[
2
])
nbdPath
,
imgPath
,
cmdlineArgs
[
2
])
continue
continue
}
}
devicePath
:=
path
.
Join
(
"/dev"
,
"nbd"
+
strconv
.
Itoa
(
i
))
devicePath
:=
file
path
.
Join
(
"/dev"
,
"nbd"
+
strconv
.
Itoa
(
i
))
if
_
,
err
:=
os
.
Lstat
(
devicePath
);
err
!=
nil
{
if
_
,
err
:=
os
.
Lstat
(
devicePath
);
err
!=
nil
{
klog
.
Warningf
(
"Stat device %s for imgpath %s failed %v"
,
devicePath
,
imgPath
,
err
)
klog
.
Warningf
(
"Stat device %s for imgpath %s failed %v"
,
devicePath
,
imgPath
,
err
)
continue
continue
...
@@ -247,7 +248,7 @@ func checkRbdNbdTools(e mount.Exec) bool {
...
@@ -247,7 +248,7 @@ func checkRbdNbdTools(e mount.Exec) bool {
// Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/mounts/pool-image-image.
// Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/mounts/pool-image-image.
func
makePDNameInternal
(
host
volume
.
VolumeHost
,
pool
string
,
image
string
)
string
{
func
makePDNameInternal
(
host
volume
.
VolumeHost
,
pool
string
,
image
string
)
string
{
// Backward compatibility for the deprecated format: /var/lib/kubelet/plugins/kubernetes.io/rbd/rbd/pool-image-image.
// Backward compatibility for the deprecated format: /var/lib/kubelet/plugins/kubernetes.io/rbd/rbd/pool-image-image.
deprecatedDir
:=
path
.
Join
(
host
.
GetPluginDir
(
rbdPluginName
),
"rbd"
,
pool
+
"-image-"
+
image
)
deprecatedDir
:=
file
path
.
Join
(
host
.
GetPluginDir
(
rbdPluginName
),
"rbd"
,
pool
+
"-image-"
+
image
)
info
,
err
:=
os
.
Stat
(
deprecatedDir
)
info
,
err
:=
os
.
Stat
(
deprecatedDir
)
if
err
==
nil
&&
info
.
IsDir
()
{
if
err
==
nil
&&
info
.
IsDir
()
{
// The device mount path has already been created with the deprecated format, return it.
// The device mount path has already been created with the deprecated format, return it.
...
@@ -255,12 +256,12 @@ func makePDNameInternal(host volume.VolumeHost, pool string, image string) strin
...
@@ -255,12 +256,12 @@ func makePDNameInternal(host volume.VolumeHost, pool string, image string) strin
return
deprecatedDir
return
deprecatedDir
}
}
// Return the canonical format path.
// Return the canonical format path.
return
path
.
Join
(
host
.
GetPluginDir
(
rbdPluginName
),
mount
.
MountsInGlobalPDPath
,
pool
+
"-image-"
+
image
)
return
filepath
.
Join
(
host
.
GetPluginDir
(
rbdPluginName
),
volutil
.
MountsInGlobalPDPath
,
pool
+
"-image-"
+
image
)
}
}
// Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/volumeDevices/pool-image-image.
// Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/volumeDevices/pool-image-image.
func
makeVDPDNameInternal
(
host
volume
.
VolumeHost
,
pool
string
,
image
string
)
string
{
func
makeVDPDNameInternal
(
host
volume
.
VolumeHost
,
pool
string
,
image
string
)
string
{
return
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
rbdPluginName
),
pool
+
"-image-"
+
image
)
return
file
path
.
Join
(
host
.
GetVolumeDevicePluginDir
(
rbdPluginName
),
pool
+
"-image-"
+
image
)
}
}
// RBDUtil implements diskManager interface.
// RBDUtil implements diskManager interface.
...
@@ -485,7 +486,7 @@ func (util *RBDUtil) DetachDisk(plugin *rbdPlugin, deviceMountPath string, devic
...
@@ -485,7 +486,7 @@ func (util *RBDUtil) DetachDisk(plugin *rbdPlugin, deviceMountPath string, devic
// Currently, we don't persist rbd info on the disk, but for backward
// Currently, we don't persist rbd info on the disk, but for backward
// compatbility, we need to clean it if found.
// compatbility, we need to clean it if found.
rbdFile
:=
path
.
Join
(
deviceMountPath
,
"rbd.json"
)
rbdFile
:=
file
path
.
Join
(
deviceMountPath
,
"rbd.json"
)
exists
,
err
:=
utilpath
.
Exists
(
utilpath
.
CheckFollowSymlink
,
rbdFile
)
exists
,
err
:=
utilpath
.
Exists
(
utilpath
.
CheckFollowSymlink
,
rbdFile
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/volume/scaleio/sio_client.go
View file @
b5c34d0c
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"strconv"
"strconv"
...
@@ -535,5 +534,5 @@ func (c *sioClient) getSdcPath() string {
...
@@ -535,5 +534,5 @@ func (c *sioClient) getSdcPath() string {
}
}
func
(
c
*
sioClient
)
getSdcCmd
()
string
{
func
(
c
*
sioClient
)
getSdcCmd
()
string
{
return
path
.
Join
(
c
.
getSdcPath
(),
"drv_cfg"
)
return
file
path
.
Join
(
c
.
getSdcPath
(),
"drv_cfg"
)
}
}
pkg/volume/scaleio/sio_util_test.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package scaleio
...
@@ -19,7 +19,7 @@ package scaleio
import
(
import
(
"encoding/gob"
"encoding/gob"
"os"
"os"
"path"
"path
/filepath
"
"reflect"
"reflect"
"testing"
"testing"
...
@@ -152,7 +152,7 @@ func TestUtilSaveConfig(t *testing.T) {
...
@@ -152,7 +152,7 @@ func TestUtilSaveConfig(t *testing.T) {
}
}
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
config
:=
path
.
Join
(
tmpDir
,
testConfigFile
)
config
:=
file
path
.
Join
(
tmpDir
,
testConfigFile
)
data
:=
map
[
string
]
string
{
data
:=
map
[
string
]
string
{
confKey
.
gateway
:
"https://test-gateway/"
,
confKey
.
gateway
:
"https://test-gateway/"
,
confKey
.
secretName
:
"sio-secret"
,
confKey
.
secretName
:
"sio-secret"
,
...
@@ -207,7 +207,7 @@ func TestUtilLoadConfig(t *testing.T) {
...
@@ -207,7 +207,7 @@ func TestUtilLoadConfig(t *testing.T) {
}
}
defer
os
.
RemoveAll
(
tmpDir
)
defer
os
.
RemoveAll
(
tmpDir
)
configFile
:=
path
.
Join
(
tmpDir
,
sioConfigFileName
)
configFile
:=
file
path
.
Join
(
tmpDir
,
sioConfigFileName
)
if
err
:=
saveConfig
(
configFile
,
config
);
err
!=
nil
{
if
err
:=
saveConfig
(
configFile
,
config
);
err
!=
nil
{
t
.
Fatalf
(
"failed to save configFile %s error:%v"
,
configFile
,
err
)
t
.
Fatalf
(
"failed to save configFile %s error:%v"
,
configFile
,
err
)
...
...
pkg/volume/scaleio/sio_volume.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package scaleio
...
@@ -19,7 +19,7 @@ package scaleio
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"strconv"
"strconv"
"strings"
"strings"
...
@@ -359,7 +359,7 @@ func (v *sioVolume) Provision(selectedNode *api.Node, allowedTopologies []api.To
...
@@ -359,7 +359,7 @@ func (v *sioVolume) Provision(selectedNode *api.Node, allowedTopologies []api.To
func
(
v
*
sioVolume
)
setSioMgr
()
error
{
func
(
v
*
sioVolume
)
setSioMgr
()
error
{
klog
.
V
(
4
)
.
Info
(
log
(
"setting up sio mgr for spec %s"
,
v
.
volSpecName
))
klog
.
V
(
4
)
.
Info
(
log
(
"setting up sio mgr for spec %s"
,
v
.
volSpecName
))
podDir
:=
v
.
plugin
.
host
.
GetPodPluginDir
(
v
.
podUID
,
sioPluginName
)
podDir
:=
v
.
plugin
.
host
.
GetPodPluginDir
(
v
.
podUID
,
sioPluginName
)
configName
:=
path
.
Join
(
podDir
,
sioConfigFileName
)
configName
:=
file
path
.
Join
(
podDir
,
sioConfigFileName
)
if
v
.
sioMgr
==
nil
{
if
v
.
sioMgr
==
nil
{
configData
,
err
:=
loadConfig
(
configName
)
// try to load config if exist
configData
,
err
:=
loadConfig
(
configName
)
// try to load config if exist
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -414,7 +414,7 @@ func (v *sioVolume) setSioMgr() error {
...
@@ -414,7 +414,7 @@ func (v *sioVolume) setSioMgr() error {
// resetSioMgr creates scaleio manager from existing (cached) config data
// resetSioMgr creates scaleio manager from existing (cached) config data
func
(
v
*
sioVolume
)
resetSioMgr
()
error
{
func
(
v
*
sioVolume
)
resetSioMgr
()
error
{
podDir
:=
v
.
plugin
.
host
.
GetPodPluginDir
(
v
.
podUID
,
sioPluginName
)
podDir
:=
v
.
plugin
.
host
.
GetPodPluginDir
(
v
.
podUID
,
sioPluginName
)
configName
:=
path
.
Join
(
podDir
,
sioConfigFileName
)
configName
:=
file
path
.
Join
(
podDir
,
sioConfigFileName
)
if
v
.
sioMgr
==
nil
{
if
v
.
sioMgr
==
nil
{
// load config data from disk
// load config data from disk
configData
,
err
:=
loadConfig
(
configName
)
configData
,
err
:=
loadConfig
(
configName
)
...
...
pkg/volume/scaleio/sio_volume_test.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package scaleio
...
@@ -19,7 +19,7 @@ package scaleio
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"strings"
"strings"
"testing"
"testing"
...
@@ -185,7 +185,7 @@ func TestVolumeMounterUnmounter(t *testing.T) {
...
@@ -185,7 +185,7 @@ func TestVolumeMounterUnmounter(t *testing.T) {
sioVol
.
sioMgr
.
client
=
sio
sioVol
.
sioMgr
.
client
=
sio
sioVol
.
sioMgr
.
CreateVolume
(
testSioVol
,
8
)
//create vol ahead of time
sioVol
.
sioMgr
.
CreateVolume
(
testSioVol
,
8
)
//create vol ahead of time
volPath
:=
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"pods/%s/volumes/kubernetes.io~scaleio/%s"
,
podUID
,
testSioVolName
))
volPath
:=
file
path
.
Join
(
tmpDir
,
fmt
.
Sprintf
(
"pods/%s/volumes/kubernetes.io~scaleio/%s"
,
podUID
,
testSioVolName
))
path
:=
sioMounter
.
GetPath
()
path
:=
sioMounter
.
GetPath
()
if
path
!=
volPath
{
if
path
!=
volPath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
...
...
pkg/volume/secret/secret_test.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path
/filepath
"
"reflect"
"reflect"
"runtime"
"runtime"
"strings"
"strings"
...
@@ -527,14 +527,14 @@ func TestPluginOptional(t *testing.T) {
...
@@ -527,14 +527,14 @@ func TestPluginOptional(t *testing.T) {
}
}
}
}
datadirSymlink
:=
path
.
Join
(
volumePath
,
"..data"
)
datadirSymlink
:=
file
path
.
Join
(
volumePath
,
"..data"
)
datadir
,
err
:=
os
.
Readlink
(
datadirSymlink
)
datadir
,
err
:=
os
.
Readlink
(
datadirSymlink
)
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
t
.
Fatalf
(
"couldn't find volume path's data dir, %s"
,
datadirSymlink
)
t
.
Fatalf
(
"couldn't find volume path's data dir, %s"
,
datadirSymlink
)
}
else
if
err
!=
nil
{
}
else
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't read symlink, %s"
,
datadirSymlink
)
t
.
Fatalf
(
"couldn't read symlink, %s"
,
datadirSymlink
)
}
}
datadirPath
:=
path
.
Join
(
volumePath
,
datadir
)
datadirPath
:=
file
path
.
Join
(
volumePath
,
datadir
)
infos
,
err
:=
ioutil
.
ReadDir
(
volumePath
)
infos
,
err
:=
ioutil
.
ReadDir
(
volumePath
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -665,7 +665,7 @@ func secret(namespace, name string) v1.Secret {
...
@@ -665,7 +665,7 @@ func secret(namespace, name string) v1.Secret {
func
doTestSecretDataInVolume
(
volumePath
string
,
secret
v1
.
Secret
,
t
*
testing
.
T
)
{
func
doTestSecretDataInVolume
(
volumePath
string
,
secret
v1
.
Secret
,
t
*
testing
.
T
)
{
for
key
,
value
:=
range
secret
.
Data
{
for
key
,
value
:=
range
secret
.
Data
{
secretDataHostPath
:=
path
.
Join
(
volumePath
,
key
)
secretDataHostPath
:=
file
path
.
Join
(
volumePath
,
key
)
if
_
,
err
:=
os
.
Stat
(
secretDataHostPath
);
err
!=
nil
{
if
_
,
err
:=
os
.
Stat
(
secretDataHostPath
);
err
!=
nil
{
t
.
Fatalf
(
"SetUp() failed, couldn't find secret data on disk: %v"
,
secretDataHostPath
)
t
.
Fatalf
(
"SetUp() failed, couldn't find secret data on disk: %v"
,
secretDataHostPath
)
}
else
{
}
else
{
...
...
pkg/volume/storageos/storageos.go
View file @
b5c34d0c
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"strings"
"strings"
...
@@ -441,7 +440,7 @@ func (b *storageosMounter) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -441,7 +440,7 @@ func (b *storageosMounter) SetUpAt(dir string, fsGroup *int64) error {
}
}
func
makeGlobalPDName
(
host
volume
.
VolumeHost
,
pvName
,
volNamespace
,
volName
string
)
string
{
func
makeGlobalPDName
(
host
volume
.
VolumeHost
,
pvName
,
volNamespace
,
volName
string
)
string
{
return
path
.
Join
(
host
.
GetPluginDir
(
utilstrings
.
EscapeQualifiedName
(
storageosPluginName
)),
mount
.
MountsInGlobalPDPath
,
pvName
+
"."
+
volNamespace
+
"."
+
volName
)
return
filepath
.
Join
(
host
.
GetPluginDir
(
utilstrings
.
EscapeQualifiedName
(
storageosPluginName
)),
util
.
MountsInGlobalPDPath
,
pvName
+
"."
+
volNamespace
+
"."
+
volName
)
}
}
// Given the pod id and PV name, finds the volume's namespace and name from the
// Given the pod id and PV name, finds the volume's namespace and name from the
...
...
pkg/volume/storageos/storageos_test.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package storageos
...
@@ -19,7 +19,7 @@ package storageos
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -202,7 +202,7 @@ func TestPlugin(t *testing.T) {
...
@@ -202,7 +202,7 @@ func TestPlugin(t *testing.T) {
t
.
Fatalf
(
"Got a nil Mounter"
)
t
.
Fatalf
(
"Got a nil Mounter"
)
}
}
expectedPath
:=
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~storageos/vol1-pvname.ns1.vol1"
)
expectedPath
:=
file
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~storageos/vol1-pvname.ns1.vol1"
)
volPath
:=
mounter
.
GetPath
()
volPath
:=
mounter
.
GetPath
()
if
volPath
!=
expectedPath
{
if
volPath
!=
expectedPath
{
t
.
Errorf
(
"Expected path: '%s' got: '%s'"
,
expectedPath
,
volPath
)
t
.
Errorf
(
"Expected path: '%s' got: '%s'"
,
expectedPath
,
volPath
)
...
...
pkg/volume/storageos/storageos_util.go
View file @
b5c34d0c
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"strings"
"strings"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/mount"
...
@@ -174,7 +174,7 @@ func (u *storageosUtil) AttachVolume(b *storageosMounter) (string, error) {
...
@@ -174,7 +174,7 @@ func (u *storageosUtil) AttachVolume(b *storageosMounter) (string, error) {
}
}
}
}
srcPath
:=
path
.
Join
(
b
.
deviceDir
,
vol
.
ID
)
srcPath
:=
file
path
.
Join
(
b
.
deviceDir
,
vol
.
ID
)
dt
,
err
:=
pathDeviceType
(
srcPath
)
dt
,
err
:=
pathDeviceType
(
srcPath
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Warningf
(
"volume source path %q for volume %q not ready (%v)"
,
srcPath
,
b
.
volName
,
err
)
klog
.
Warningf
(
"volume source path %q for volume %q not ready (%v)"
,
srcPath
,
b
.
volName
,
err
)
...
...
pkg/volume/testing/testing.go
View file @
b5c34d0c
...
@@ -21,7 +21,7 @@ import (
...
@@ -21,7 +21,7 @@ import (
"net"
"net"
"os"
"os"
"os/exec"
"os/exec"
"path"
"path
/filepath
"
"strings"
"strings"
"sync"
"sync"
"testing"
"testing"
...
@@ -118,27 +118,27 @@ func NewFakeVolumeHostWithMounterFSType(rootDir string, kubeClient clientset.Int
...
@@ -118,27 +118,27 @@ func NewFakeVolumeHostWithMounterFSType(rootDir string, kubeClient clientset.Int
}
}
func
(
f
*
fakeVolumeHost
)
GetPluginDir
(
podUID
string
)
string
{
func
(
f
*
fakeVolumeHost
)
GetPluginDir
(
podUID
string
)
string
{
return
path
.
Join
(
f
.
rootDir
,
"plugins"
,
podUID
)
return
file
path
.
Join
(
f
.
rootDir
,
"plugins"
,
podUID
)
}
}
func
(
f
*
fakeVolumeHost
)
GetVolumeDevicePluginDir
(
pluginName
string
)
string
{
func
(
f
*
fakeVolumeHost
)
GetVolumeDevicePluginDir
(
pluginName
string
)
string
{
return
path
.
Join
(
f
.
rootDir
,
"plugins"
,
pluginName
,
"volumeDevices"
)
return
file
path
.
Join
(
f
.
rootDir
,
"plugins"
,
pluginName
,
"volumeDevices"
)
}
}
func
(
f
*
fakeVolumeHost
)
GetPodsDir
()
string
{
func
(
f
*
fakeVolumeHost
)
GetPodsDir
()
string
{
return
path
.
Join
(
f
.
rootDir
,
"pods"
)
return
file
path
.
Join
(
f
.
rootDir
,
"pods"
)
}
}
func
(
f
*
fakeVolumeHost
)
GetPodVolumeDir
(
podUID
types
.
UID
,
pluginName
,
volumeName
string
)
string
{
func
(
f
*
fakeVolumeHost
)
GetPodVolumeDir
(
podUID
types
.
UID
,
pluginName
,
volumeName
string
)
string
{
return
path
.
Join
(
f
.
rootDir
,
"pods"
,
string
(
podUID
),
"volumes"
,
pluginName
,
volumeName
)
return
file
path
.
Join
(
f
.
rootDir
,
"pods"
,
string
(
podUID
),
"volumes"
,
pluginName
,
volumeName
)
}
}
func
(
f
*
fakeVolumeHost
)
GetPodVolumeDeviceDir
(
podUID
types
.
UID
,
pluginName
string
)
string
{
func
(
f
*
fakeVolumeHost
)
GetPodVolumeDeviceDir
(
podUID
types
.
UID
,
pluginName
string
)
string
{
return
path
.
Join
(
f
.
rootDir
,
"pods"
,
string
(
podUID
),
"volumeDevices"
,
pluginName
)
return
file
path
.
Join
(
f
.
rootDir
,
"pods"
,
string
(
podUID
),
"volumeDevices"
,
pluginName
)
}
}
func
(
f
*
fakeVolumeHost
)
GetPodPluginDir
(
podUID
types
.
UID
,
pluginName
string
)
string
{
func
(
f
*
fakeVolumeHost
)
GetPodPluginDir
(
podUID
types
.
UID
,
pluginName
string
)
string
{
return
path
.
Join
(
f
.
rootDir
,
"pods"
,
string
(
podUID
),
"plugins"
,
pluginName
)
return
file
path
.
Join
(
f
.
rootDir
,
"pods"
,
string
(
podUID
),
"plugins"
,
pluginName
)
}
}
func
(
f
*
fakeVolumeHost
)
GetKubeClient
()
clientset
.
Interface
{
func
(
f
*
fakeVolumeHost
)
GetKubeClient
()
clientset
.
Interface
{
...
@@ -789,7 +789,7 @@ func (fv *FakeVolume) GetPath() string {
...
@@ -789,7 +789,7 @@ func (fv *FakeVolume) GetPath() string {
}
}
func
(
fv
*
FakeVolume
)
getPath
()
string
{
func
(
fv
*
FakeVolume
)
getPath
()
string
{
return
path
.
Join
(
fv
.
Plugin
.
Host
.
GetPodVolumeDir
(
fv
.
PodUID
,
utilstrings
.
EscapeQualifiedName
(
fv
.
Plugin
.
PluginName
),
fv
.
VolName
))
return
file
path
.
Join
(
fv
.
Plugin
.
Host
.
GetPodVolumeDir
(
fv
.
PodUID
,
utilstrings
.
EscapeQualifiedName
(
fv
.
Plugin
.
PluginName
),
fv
.
VolName
))
}
}
func
(
fv
*
FakeVolume
)
TearDown
()
error
{
func
(
fv
*
FakeVolume
)
TearDown
()
error
{
...
@@ -834,7 +834,7 @@ func (fv *FakeVolume) GetGlobalMapPath(spec *Spec) (string, error) {
...
@@ -834,7 +834,7 @@ func (fv *FakeVolume) GetGlobalMapPath(spec *Spec) (string, error) {
// Block volume support
// Block volume support
func
(
fv
*
FakeVolume
)
getGlobalMapPath
()
(
string
,
error
)
{
func
(
fv
*
FakeVolume
)
getGlobalMapPath
()
(
string
,
error
)
{
return
path
.
Join
(
fv
.
Plugin
.
Host
.
GetVolumeDevicePluginDir
(
utilstrings
.
EscapeQualifiedName
(
fv
.
Plugin
.
PluginName
)),
"pluginDependentPath"
),
nil
return
file
path
.
Join
(
fv
.
Plugin
.
Host
.
GetVolumeDevicePluginDir
(
utilstrings
.
EscapeQualifiedName
(
fv
.
Plugin
.
PluginName
)),
"pluginDependentPath"
),
nil
}
}
// Block volume support
// Block volume support
...
@@ -854,7 +854,7 @@ func (fv *FakeVolume) GetPodDeviceMapPath() (string, string) {
...
@@ -854,7 +854,7 @@ func (fv *FakeVolume) GetPodDeviceMapPath() (string, string) {
// Block volume support
// Block volume support
func
(
fv
*
FakeVolume
)
getPodDeviceMapPath
()
(
string
,
string
)
{
func
(
fv
*
FakeVolume
)
getPodDeviceMapPath
()
(
string
,
string
)
{
return
path
.
Join
(
fv
.
Plugin
.
Host
.
GetPodVolumeDeviceDir
(
fv
.
PodUID
,
utilstrings
.
EscapeQualifiedName
(
fv
.
Plugin
.
PluginName
))),
fv
.
VolName
return
file
path
.
Join
(
fv
.
Plugin
.
Host
.
GetPodVolumeDeviceDir
(
fv
.
PodUID
,
utilstrings
.
EscapeQualifiedName
(
fv
.
Plugin
.
PluginName
))),
fv
.
VolName
}
}
// Block volume support
// Block volume support
...
...
pkg/volume/util/atomic_writer.go
View file @
b5c34d0c
...
@@ -126,7 +126,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
...
@@ -126,7 +126,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
}
}
// (2)
// (2)
dataDirPath
:=
path
.
Join
(
w
.
targetDir
,
dataDirName
)
dataDirPath
:=
file
path
.
Join
(
w
.
targetDir
,
dataDirName
)
oldTsDir
,
err
:=
os
.
Readlink
(
dataDirPath
)
oldTsDir
,
err
:=
os
.
Readlink
(
dataDirPath
)
if
err
!=
nil
{
if
err
!=
nil
{
if
!
os
.
IsNotExist
(
err
)
{
if
!
os
.
IsNotExist
(
err
)
{
...
@@ -137,7 +137,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
...
@@ -137,7 +137,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
// empty oldTsDir indicates that it didn't exist
// empty oldTsDir indicates that it didn't exist
oldTsDir
=
""
oldTsDir
=
""
}
}
oldTsPath
:=
path
.
Join
(
w
.
targetDir
,
oldTsDir
)
oldTsPath
:=
file
path
.
Join
(
w
.
targetDir
,
oldTsDir
)
var
pathsToRemove
sets
.
String
var
pathsToRemove
sets
.
String
// if there was no old version, there's nothing to remove
// if there was no old version, there's nothing to remove
...
@@ -183,7 +183,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
...
@@ -183,7 +183,7 @@ func (w *AtomicWriter) Write(payload map[string]FileProjection) error {
}
}
// (8)
// (8)
newDataDirPath
:=
path
.
Join
(
w
.
targetDir
,
newDataDirName
)
newDataDirPath
:=
file
path
.
Join
(
w
.
targetDir
,
newDataDirName
)
if
err
=
os
.
Symlink
(
tsDirName
,
newDataDirPath
);
err
!=
nil
{
if
err
=
os
.
Symlink
(
tsDirName
,
newDataDirPath
);
err
!=
nil
{
os
.
RemoveAll
(
tsDir
)
os
.
RemoveAll
(
tsDir
)
klog
.
Errorf
(
"%s: error creating symbolic link for atomic update: %v"
,
w
.
logContext
,
err
)
klog
.
Errorf
(
"%s: error creating symbolic link for atomic update: %v"
,
w
.
logContext
,
err
)
...
@@ -279,7 +279,7 @@ func validatePath(targetPath string) error {
...
@@ -279,7 +279,7 @@ func validatePath(targetPath string) error {
// shouldWritePayload returns whether the payload should be written to disk.
// shouldWritePayload returns whether the payload should be written to disk.
func
shouldWritePayload
(
payload
map
[
string
]
FileProjection
,
oldTsDir
string
)
(
bool
,
error
)
{
func
shouldWritePayload
(
payload
map
[
string
]
FileProjection
,
oldTsDir
string
)
(
bool
,
error
)
{
for
userVisiblePath
,
fileProjection
:=
range
payload
{
for
userVisiblePath
,
fileProjection
:=
range
payload
{
shouldWrite
,
err
:=
shouldWriteFile
(
path
.
Join
(
oldTsDir
,
userVisiblePath
),
fileProjection
.
Data
)
shouldWrite
,
err
:=
shouldWriteFile
(
file
path
.
Join
(
oldTsDir
,
userVisiblePath
),
fileProjection
.
Data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
...
@@ -375,7 +375,7 @@ func (w *AtomicWriter) writePayloadToDir(payload map[string]FileProjection, dir
...
@@ -375,7 +375,7 @@ func (w *AtomicWriter) writePayloadToDir(payload map[string]FileProjection, dir
for
userVisiblePath
,
fileProjection
:=
range
payload
{
for
userVisiblePath
,
fileProjection
:=
range
payload
{
content
:=
fileProjection
.
Data
content
:=
fileProjection
.
Data
mode
:=
os
.
FileMode
(
fileProjection
.
Mode
)
mode
:=
os
.
FileMode
(
fileProjection
.
Mode
)
fullPath
:=
path
.
Join
(
dir
,
userVisiblePath
)
fullPath
:=
file
path
.
Join
(
dir
,
userVisiblePath
)
baseDir
,
_
:=
filepath
.
Split
(
fullPath
)
baseDir
,
_
:=
filepath
.
Split
(
fullPath
)
err
:=
os
.
MkdirAll
(
baseDir
,
os
.
ModePerm
)
err
:=
os
.
MkdirAll
(
baseDir
,
os
.
ModePerm
)
...
@@ -419,11 +419,11 @@ func (w *AtomicWriter) createUserVisibleFiles(payload map[string]FileProjection)
...
@@ -419,11 +419,11 @@ func (w *AtomicWriter) createUserVisibleFiles(payload map[string]FileProjection)
slashpos
=
len
(
userVisiblePath
)
slashpos
=
len
(
userVisiblePath
)
}
}
linkname
:=
userVisiblePath
[
:
slashpos
]
linkname
:=
userVisiblePath
[
:
slashpos
]
_
,
err
:=
os
.
Readlink
(
path
.
Join
(
w
.
targetDir
,
linkname
))
_
,
err
:=
os
.
Readlink
(
file
path
.
Join
(
w
.
targetDir
,
linkname
))
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
// The link into the data directory for this path doesn't exist; create it
// The link into the data directory for this path doesn't exist; create it
visibleFile
:=
path
.
Join
(
w
.
targetDir
,
linkname
)
visibleFile
:=
file
path
.
Join
(
w
.
targetDir
,
linkname
)
dataDirFile
:=
path
.
Join
(
dataDirName
,
linkname
)
dataDirFile
:=
file
path
.
Join
(
dataDirName
,
linkname
)
err
=
os
.
Symlink
(
dataDirFile
,
visibleFile
)
err
=
os
.
Symlink
(
dataDirFile
,
visibleFile
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -444,7 +444,7 @@ func (w *AtomicWriter) removeUserVisiblePaths(paths sets.String) error {
...
@@ -444,7 +444,7 @@ func (w *AtomicWriter) removeUserVisiblePaths(paths sets.String) error {
if
strings
.
Contains
(
p
,
ps
)
{
if
strings
.
Contains
(
p
,
ps
)
{
continue
continue
}
}
if
err
:=
os
.
Remove
(
path
.
Join
(
w
.
targetDir
,
p
));
err
!=
nil
{
if
err
:=
os
.
Remove
(
file
path
.
Join
(
w
.
targetDir
,
p
));
err
!=
nil
{
klog
.
Errorf
(
"%s: error pruning old user-visible path %s: %v"
,
w
.
logContext
,
p
,
err
)
klog
.
Errorf
(
"%s: error pruning old user-visible path %s: %v"
,
w
.
logContext
,
p
,
err
)
lasterr
=
err
lasterr
=
err
}
}
...
...
pkg/volume/util/atomic_writer_test.go
View file @
b5c34d0c
...
@@ -22,7 +22,6 @@ import (
...
@@ -22,7 +22,6 @@ import (
"encoding/base64"
"encoding/base64"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"reflect"
"reflect"
"strings"
"strings"
...
@@ -235,7 +234,7 @@ func TestPathsToRemove(t *testing.T) {
...
@@ -235,7 +234,7 @@ func TestPathsToRemove(t *testing.T) {
continue
continue
}
}
dataDirPath
:=
path
.
Join
(
targetDir
,
dataDirName
)
dataDirPath
:=
file
path
.
Join
(
targetDir
,
dataDirName
)
oldTsDir
,
err
:=
os
.
Readlink
(
dataDirPath
)
oldTsDir
,
err
:=
os
.
Readlink
(
dataDirPath
)
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"Data symlink does not exist: %v"
,
dataDirPath
)
t
.
Errorf
(
"Data symlink does not exist: %v"
,
dataDirPath
)
...
@@ -245,7 +244,7 @@ func TestPathsToRemove(t *testing.T) {
...
@@ -245,7 +244,7 @@ func TestPathsToRemove(t *testing.T) {
continue
continue
}
}
actual
,
err
:=
writer
.
pathsToRemove
(
tc
.
payload2
,
path
.
Join
(
targetDir
,
oldTsDir
))
actual
,
err
:=
writer
.
pathsToRemove
(
tc
.
payload2
,
file
path
.
Join
(
targetDir
,
oldTsDir
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"%v: unexpected error determining paths to remove: %v"
,
tc
.
name
,
err
)
t
.
Errorf
(
"%v: unexpected error determining paths to remove: %v"
,
tc
.
name
,
err
)
continue
continue
...
@@ -751,7 +750,7 @@ func TestMultipleUpdates(t *testing.T) {
...
@@ -751,7 +750,7 @@ func TestMultipleUpdates(t *testing.T) {
}
}
func
checkVolumeContents
(
targetDir
,
tcName
string
,
payload
map
[
string
]
FileProjection
,
t
*
testing
.
T
)
{
func
checkVolumeContents
(
targetDir
,
tcName
string
,
payload
map
[
string
]
FileProjection
,
t
*
testing
.
T
)
{
dataDirPath
:=
path
.
Join
(
targetDir
,
dataDirName
)
dataDirPath
:=
file
path
.
Join
(
targetDir
,
dataDirName
)
// use filepath.Walk to reconstruct the payload, then deep equal
// use filepath.Walk to reconstruct the payload, then deep equal
observedPayload
:=
make
(
map
[
string
]
FileProjection
)
observedPayload
:=
make
(
map
[
string
]
FileProjection
)
visitor
:=
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
visitor
:=
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
...
@@ -790,13 +789,13 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec
...
@@ -790,13 +789,13 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec
continue
continue
}
}
if
info
.
Mode
()
&
os
.
ModeSymlink
!=
0
{
if
info
.
Mode
()
&
os
.
ModeSymlink
!=
0
{
p
:=
path
.
Join
(
targetDir
,
info
.
Name
())
p
:=
file
path
.
Join
(
targetDir
,
info
.
Name
())
actual
,
err
:=
os
.
Readlink
(
p
)
actual
,
err
:=
os
.
Readlink
(
p
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unable to read symlink %v: %v"
,
p
,
err
)
t
.
Errorf
(
"Unable to read symlink %v: %v"
,
p
,
err
)
continue
continue
}
}
if
err
:=
filepath
.
Walk
(
path
.
Join
(
targetDir
,
actual
),
visitor
);
err
!=
nil
{
if
err
:=
filepath
.
Walk
(
file
path
.
Join
(
targetDir
,
actual
),
visitor
);
err
!=
nil
{
t
.
Errorf
(
"%v: unexpected error walking directory: %v"
,
tcName
,
err
)
t
.
Errorf
(
"%v: unexpected error walking directory: %v"
,
tcName
,
err
)
}
}
}
}
...
@@ -953,7 +952,7 @@ func TestCreateUserVisibleFiles(t *testing.T) {
...
@@ -953,7 +952,7 @@ func TestCreateUserVisibleFiles(t *testing.T) {
}
}
defer
os
.
RemoveAll
(
targetDir
)
defer
os
.
RemoveAll
(
targetDir
)
dataDirPath
:=
path
.
Join
(
targetDir
,
dataDirName
)
dataDirPath
:=
file
path
.
Join
(
targetDir
,
dataDirName
)
err
=
os
.
MkdirAll
(
dataDirPath
,
0755
)
err
=
os
.
MkdirAll
(
dataDirPath
,
0755
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"%v: unexpected error creating data path: %v"
,
tc
.
name
,
err
)
t
.
Fatalf
(
"%v: unexpected error creating data path: %v"
,
tc
.
name
,
err
)
...
@@ -970,7 +969,7 @@ func TestCreateUserVisibleFiles(t *testing.T) {
...
@@ -970,7 +969,7 @@ func TestCreateUserVisibleFiles(t *testing.T) {
}
}
for
subpath
,
expectedDest
:=
range
tc
.
expected
{
for
subpath
,
expectedDest
:=
range
tc
.
expected
{
visiblePath
:=
path
.
Join
(
targetDir
,
subpath
)
visiblePath
:=
file
path
.
Join
(
targetDir
,
subpath
)
destination
,
err
:=
os
.
Readlink
(
visiblePath
)
destination
,
err
:=
os
.
Readlink
(
visiblePath
)
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
t
.
Fatalf
(
"%v: visible symlink does not exist: %v"
,
tc
.
name
,
visiblePath
)
t
.
Fatalf
(
"%v: visible symlink does not exist: %v"
,
tc
.
name
,
visiblePath
)
...
...
pkg/volume/util/device_util_linux.go
View file @
b5c34d0c
...
@@ -22,7 +22,7 @@ import (
...
@@ -22,7 +22,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"strconv"
"strconv"
"strings"
"strings"
...
@@ -77,10 +77,10 @@ func (handler *deviceHandler) FindSlaveDevicesOnMultipath(dm string) []string {
...
@@ -77,10 +77,10 @@ func (handler *deviceHandler) FindSlaveDevicesOnMultipath(dm string) []string {
return
devices
return
devices
}
}
disk
:=
parts
[
2
]
disk
:=
parts
[
2
]
slavesPath
:=
path
.
Join
(
"/sys/block/"
,
disk
,
"/slaves/"
)
slavesPath
:=
file
path
.
Join
(
"/sys/block/"
,
disk
,
"/slaves/"
)
if
files
,
err
:=
io
.
ReadDir
(
slavesPath
);
err
==
nil
{
if
files
,
err
:=
io
.
ReadDir
(
slavesPath
);
err
==
nil
{
for
_
,
f
:=
range
files
{
for
_
,
f
:=
range
files
{
devices
=
append
(
devices
,
path
.
Join
(
"/dev/"
,
f
.
Name
()))
devices
=
append
(
devices
,
file
path
.
Join
(
"/dev/"
,
f
.
Name
()))
}
}
}
}
return
devices
return
devices
...
...
pkg/volume/util/exec/exec_mount.go
View file @
b5c34d0c
...
@@ -112,8 +112,8 @@ func (m *execMounter) PathIsDevice(pathname string) (bool, error) {
...
@@ -112,8 +112,8 @@ func (m *execMounter) PathIsDevice(pathname string) (bool, error) {
}
}
//GetDeviceNameFromMount given a mount point, find the volume id from checking /proc/mounts
//GetDeviceNameFromMount given a mount point, find the volume id from checking /proc/mounts
func
(
m
*
execMounter
)
GetDeviceNameFromMount
(
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
(
m
*
execMounter
)
GetDeviceNameFromMount
(
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
return
m
.
wrappedMounter
.
GetDeviceNameFromMount
(
mountPath
,
pluginDir
)
return
m
.
wrappedMounter
.
GetDeviceNameFromMount
(
mountPath
,
plugin
Mount
Dir
)
}
}
func
(
m
*
execMounter
)
IsMountPointMatch
(
mp
mount
.
MountPoint
,
dir
string
)
bool
{
func
(
m
*
execMounter
)
IsMountPointMatch
(
mp
mount
.
MountPoint
,
dir
string
)
bool
{
...
...
pkg/volume/util/exec/exec_mount_unsupported.go
View file @
b5c34d0c
...
@@ -53,7 +53,7 @@ func (mounter *execMounter) IsLikelyNotMountPoint(file string) (bool, error) {
...
@@ -53,7 +53,7 @@ func (mounter *execMounter) IsLikelyNotMountPoint(file string) (bool, error) {
return
true
,
nil
return
true
,
nil
}
}
func
(
mounter
*
execMounter
)
GetDeviceNameFromMount
(
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
(
mounter
*
execMounter
)
GetDeviceNameFromMount
(
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
return
""
,
nil
return
""
,
nil
}
}
...
...
pkg/volume/util/nested_volumes.go
View file @
b5c34d0c
...
@@ -18,12 +18,12 @@ package util
...
@@ -18,12 +18,12 @@ package util
import
(
import
(
"fmt"
"fmt"
"k8s.io/api/core/v1"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"sort"
"sort"
"strings"
"strings"
"k8s.io/api/core/v1"
)
)
// getNestedMountpoints returns a list of mountpoint directories that should be created
// getNestedMountpoints returns a list of mountpoint directories that should be created
...
@@ -90,7 +90,7 @@ func MakeNestedMountpoints(name, baseDir string, pod v1.Pod) error {
...
@@ -90,7 +90,7 @@ func MakeNestedMountpoints(name, baseDir string, pod v1.Pod) error {
return
err
return
err
}
}
for
_
,
dir
:=
range
dirs
{
for
_
,
dir
:=
range
dirs
{
err
:=
os
.
MkdirAll
(
path
.
Join
(
baseDir
,
dir
),
0755
)
err
:=
os
.
MkdirAll
(
file
path
.
Join
(
baseDir
,
dir
),
0755
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to create nested volume mountpoints: %v"
,
err
)
return
fmt
.
Errorf
(
"Unable to create nested volume mountpoints: %v"
,
err
)
}
}
...
...
pkg/volume/util/nested_volumes_test.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package util
...
@@ -19,7 +19,7 @@ package util
import
(
import
(
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -206,7 +206,7 @@ func TestGetNestedMountpoints(t *testing.T) {
...
@@ -206,7 +206,7 @@ func TestGetNestedMountpoints(t *testing.T) {
}
}
defer
os
.
RemoveAll
(
dir
)
defer
os
.
RemoveAll
(
dir
)
rootdir
:=
path
.
Join
(
dir
,
"vol"
)
rootdir
:=
file
path
.
Join
(
dir
,
"vol"
)
err
=
os
.
Mkdir
(
rootdir
,
0755
)
err
=
os
.
Mkdir
(
rootdir
,
0755
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error trying to create temp root directory: %v"
,
err
)
t
.
Errorf
(
"Unexpected error trying to create temp root directory: %v"
,
err
)
...
...
pkg/volume/util/nsenter/nsenter_mount.go
View file @
b5c34d0c
...
@@ -228,8 +228,8 @@ func (n *Mounter) PathIsDevice(pathname string) (bool, error) {
...
@@ -228,8 +228,8 @@ func (n *Mounter) PathIsDevice(pathname string) (bool, error) {
}
}
//GetDeviceNameFromMount given a mount point, find the volume id from checking /proc/mounts
//GetDeviceNameFromMount given a mount point, find the volume id from checking /proc/mounts
func
(
n
*
Mounter
)
GetDeviceNameFromMount
(
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
(
n
*
Mounter
)
GetDeviceNameFromMount
(
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
return
mount
.
GetDeviceNameFromMountLinux
(
n
,
mountPath
,
pluginDir
)
return
mount
.
GetDeviceNameFromMountLinux
(
n
,
mountPath
,
plugin
Mount
Dir
)
}
}
// MakeRShared checks if path is shared and bind-mounts it as rshared if needed.
// MakeRShared checks if path is shared and bind-mounts it as rshared if needed.
...
...
pkg/volume/util/nsenter/nsenter_mount_unsupported.go
View file @
b5c34d0c
...
@@ -78,7 +78,7 @@ func (*Mounter) PathIsDevice(pathname string) (bool, error) {
...
@@ -78,7 +78,7 @@ func (*Mounter) PathIsDevice(pathname string) (bool, error) {
// GetDeviceNameFromMount finds the device name from its global mount point using the
// GetDeviceNameFromMount finds the device name from its global mount point using the
// given mountpath and plugin location. It is a noop of unsupported platforms
// given mountpath and plugin location. It is a noop of unsupported platforms
func
(
*
Mounter
)
GetDeviceNameFromMount
(
mountPath
,
pluginDir
string
)
(
string
,
error
)
{
func
(
*
Mounter
)
GetDeviceNameFromMount
(
mountPath
,
plugin
Mount
Dir
string
)
(
string
,
error
)
{
return
""
,
nil
return
""
,
nil
}
}
...
...
pkg/volume/util/operationexecutor/operation_generator.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package operationexecutor
...
@@ -19,7 +19,7 @@ package operationexecutor
import
(
import
(
goerrors
"errors"
goerrors
"errors"
"fmt"
"fmt"
"path"
"path
/filepath
"
"strings"
"strings"
"time"
"time"
...
@@ -848,7 +848,7 @@ func (og *operationGenerator) GenerateUnmountVolumeFunc(
...
@@ -848,7 +848,7 @@ func (og *operationGenerator) GenerateUnmountVolumeFunc(
subpather
:=
og
.
volumePluginMgr
.
Host
.
GetSubpather
()
subpather
:=
og
.
volumePluginMgr
.
Host
.
GetSubpather
()
// Remove all bind-mounts for subPaths
// Remove all bind-mounts for subPaths
podDir
:=
path
.
Join
(
podsDir
,
string
(
volumeToUnmount
.
PodUID
))
podDir
:=
file
path
.
Join
(
podsDir
,
string
(
volumeToUnmount
.
PodUID
))
if
err
:=
subpather
.
CleanSubPaths
(
podDir
,
volumeToUnmount
.
InnerVolumeSpecName
);
err
!=
nil
{
if
err
:=
subpather
.
CleanSubPaths
(
podDir
,
volumeToUnmount
.
InnerVolumeSpecName
);
err
!=
nil
{
return
volumeToUnmount
.
GenerateError
(
"error cleaning subPath mounts"
,
err
)
return
volumeToUnmount
.
GenerateError
(
"error cleaning subPath mounts"
,
err
)
}
}
...
...
pkg/volume/util/util.go
View file @
b5c34d0c
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"reflect"
"reflect"
"strings"
"strings"
...
@@ -58,6 +57,10 @@ const (
...
@@ -58,6 +57,10 @@ const (
// that decides if pod volumes are unmounted when pod is terminated
// that decides if pod volumes are unmounted when pod is terminated
KeepTerminatedPodVolumesAnnotation
string
=
"volumes.kubernetes.io/keep-terminated-pod-volumes"
KeepTerminatedPodVolumesAnnotation
string
=
"volumes.kubernetes.io/keep-terminated-pod-volumes"
// MountsInGlobalPDPath is name of the directory appended to a volume plugin
// name to create the place for volume mounts in the global PD path.
MountsInGlobalPDPath
=
"mounts"
// VolumeGidAnnotationKey is the of the annotation on the PersistentVolume
// VolumeGidAnnotationKey is the of the annotation on the PersistentVolume
// object that specifies a supplemental GID.
// object that specifies a supplemental GID.
VolumeGidAnnotationKey
=
"pv.beta.kubernetes.io/gid"
VolumeGidAnnotationKey
=
"pv.beta.kubernetes.io/gid"
...
@@ -71,7 +74,7 @@ const (
...
@@ -71,7 +74,7 @@ const (
// called 'ready' in the given directory and returns
// called 'ready' in the given directory and returns
// true if that file exists.
// true if that file exists.
func
IsReady
(
dir
string
)
bool
{
func
IsReady
(
dir
string
)
bool
{
readyFile
:=
path
.
Join
(
dir
,
readyFileName
)
readyFile
:=
file
path
.
Join
(
dir
,
readyFileName
)
s
,
err
:=
os
.
Stat
(
readyFile
)
s
,
err
:=
os
.
Stat
(
readyFile
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
return
false
...
@@ -94,7 +97,7 @@ func SetReady(dir string) {
...
@@ -94,7 +97,7 @@ func SetReady(dir string) {
return
return
}
}
readyFile
:=
path
.
Join
(
dir
,
readyFileName
)
readyFile
:=
file
path
.
Join
(
dir
,
readyFileName
)
file
,
err
:=
os
.
Create
(
readyFile
)
file
,
err
:=
os
.
Create
(
readyFile
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Errorf
(
"Can't touch %s: %v"
,
readyFile
,
err
)
klog
.
Errorf
(
"Can't touch %s: %v"
,
readyFile
,
err
)
...
@@ -530,3 +533,10 @@ func MapBlockVolume(
...
@@ -530,3 +533,10 @@ func MapBlockVolume(
return
nil
return
nil
}
}
// GetPluginMountDir returns the global mount directory name appended
// to the given plugin name's plugin directory
func
GetPluginMountDir
(
host
volume
.
VolumeHost
,
name
string
)
string
{
mntDir
:=
filepath
.
Join
(
host
.
GetPluginDir
(
name
),
MountsInGlobalPDPath
)
return
mntDir
}
pkg/volume/util/volumepathhandler/volume_path_handler.go
View file @
b5c34d0c
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path"
"path/filepath"
"path/filepath"
"k8s.io/klog"
"k8s.io/klog"
...
@@ -102,7 +101,7 @@ func (v VolumePathHandler) MapDevice(devicePath string, mapPath string, linkName
...
@@ -102,7 +101,7 @@ func (v VolumePathHandler) MapDevice(devicePath string, mapPath string, linkName
// Remove old symbolic link(or file) then create new one.
// Remove old symbolic link(or file) then create new one.
// This should be done because current symbolic link is
// This should be done because current symbolic link is
// stale across node reboot.
// stale across node reboot.
linkPath
:=
path
.
Join
(
mapPath
,
string
(
linkName
))
linkPath
:=
file
path
.
Join
(
mapPath
,
string
(
linkName
))
if
err
=
os
.
Remove
(
linkPath
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
if
err
=
os
.
Remove
(
linkPath
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
return
err
return
err
}
}
...
@@ -119,7 +118,7 @@ func (v VolumePathHandler) UnmapDevice(mapPath string, linkName string) error {
...
@@ -119,7 +118,7 @@ func (v VolumePathHandler) UnmapDevice(mapPath string, linkName string) error {
klog
.
V
(
5
)
.
Infof
(
"UnmapDevice: linkName %s"
,
linkName
)
klog
.
V
(
5
)
.
Infof
(
"UnmapDevice: linkName %s"
,
linkName
)
// Check symbolic link exists
// Check symbolic link exists
linkPath
:=
path
.
Join
(
mapPath
,
string
(
linkName
))
linkPath
:=
file
path
.
Join
(
mapPath
,
string
(
linkName
))
if
islinkExist
,
checkErr
:=
v
.
IsSymlinkExist
(
linkPath
);
checkErr
!=
nil
{
if
islinkExist
,
checkErr
:=
v
.
IsSymlinkExist
(
linkPath
);
checkErr
!=
nil
{
return
checkErr
return
checkErr
}
else
if
!
islinkExist
{
}
else
if
!
islinkExist
{
...
@@ -176,13 +175,13 @@ func (v VolumePathHandler) GetDeviceSymlinkRefs(devPath string, mapPath string)
...
@@ -176,13 +175,13 @@ func (v VolumePathHandler) GetDeviceSymlinkRefs(devPath string, mapPath string)
continue
continue
}
}
filename
:=
file
.
Name
()
filename
:=
file
.
Name
()
f
ilepath
,
err
:=
os
.
Readlink
(
path
.
Join
(
mapPath
,
filename
))
f
p
,
err
:=
os
.
Readlink
(
file
path
.
Join
(
mapPath
,
filename
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Symbolic link cannot be retrieved %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"Symbolic link cannot be retrieved %v"
,
err
)
}
}
klog
.
V
(
5
)
.
Infof
(
"GetDeviceSymlinkRefs: filepath: %v, devPath: %v"
,
f
ilepath
,
devPath
)
klog
.
V
(
5
)
.
Infof
(
"GetDeviceSymlinkRefs: filepath: %v, devPath: %v"
,
f
p
,
devPath
)
if
f
ilepath
==
devPath
{
if
f
p
==
devPath
{
refs
=
append
(
refs
,
path
.
Join
(
mapPath
,
filename
))
refs
=
append
(
refs
,
file
path
.
Join
(
mapPath
,
filename
))
}
}
}
}
klog
.
V
(
5
)
.
Infof
(
"GetDeviceSymlinkRefs: refs %v"
,
refs
)
klog
.
V
(
5
)
.
Infof
(
"GetDeviceSymlinkRefs: refs %v"
,
refs
)
...
...
pkg/volume/vsphere_volume/attacher.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package vsphere_volume
...
@@ -19,7 +19,7 @@ package vsphere_volume
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"time"
"time"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -90,7 +90,7 @@ func (attacher *vsphereVMDKAttacher) Attach(spec *volume.Spec, nodeName types.No
...
@@ -90,7 +90,7 @@ func (attacher *vsphereVMDKAttacher) Attach(spec *volume.Spec, nodeName types.No
return
""
,
err
return
""
,
err
}
}
return
path
.
Join
(
diskByIDPath
,
diskSCSIPrefix
+
diskUUID
),
nil
return
file
path
.
Join
(
diskByIDPath
,
diskSCSIPrefix
+
diskUUID
),
nil
}
}
func
(
attacher
*
vsphereVMDKAttacher
)
VolumesAreAttached
(
specs
[]
*
volume
.
Spec
,
nodeName
types
.
NodeName
)
(
map
[
*
volume
.
Spec
]
bool
,
error
)
{
func
(
attacher
*
vsphereVMDKAttacher
)
VolumesAreAttached
(
specs
[]
*
volume
.
Spec
,
nodeName
types
.
NodeName
)
(
map
[
*
volume
.
Spec
]
bool
,
error
)
{
...
...
pkg/volume/vsphere_volume/vsphere_volume.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package vsphere_volume
...
@@ -19,7 +19,7 @@ package vsphere_volume
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"strings"
"strings"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -145,8 +145,8 @@ func (plugin *vsphereVolumePlugin) newUnmounterInternal(volName string, podUID t
...
@@ -145,8 +145,8 @@ func (plugin *vsphereVolumePlugin) newUnmounterInternal(volName string, podUID t
func
(
plugin
*
vsphereVolumePlugin
)
ConstructVolumeSpec
(
volumeName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
func
(
plugin
*
vsphereVolumePlugin
)
ConstructVolumeSpec
(
volumeName
,
mountPath
string
)
(
*
volume
.
Spec
,
error
)
{
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
mounter
:=
plugin
.
host
.
GetMounter
(
plugin
.
GetPluginName
())
plugin
Dir
:=
plugin
.
host
.
GetPluginDir
(
plugin
.
GetPluginName
())
plugin
MntDir
:=
util
.
GetPluginMountDir
(
plugin
.
host
,
plugin
.
GetPluginName
())
volumePath
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
pluginDir
)
volumePath
,
err
:=
mounter
.
GetDeviceNameFromMount
(
mountPath
,
plugin
Mnt
Dir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -294,7 +294,7 @@ func (v *vsphereVolumeUnmounter) TearDownAt(dir string) error {
...
@@ -294,7 +294,7 @@ func (v *vsphereVolumeUnmounter) TearDownAt(dir string) error {
}
}
func
makeGlobalPDPath
(
host
volume
.
VolumeHost
,
devName
string
)
string
{
func
makeGlobalPDPath
(
host
volume
.
VolumeHost
,
devName
string
)
string
{
return
path
.
Join
(
host
.
GetPluginDir
(
vsphereVolumePluginName
),
mount
.
MountsInGlobalPDPath
,
devName
)
return
filepath
.
Join
(
host
.
GetPluginDir
(
vsphereVolumePluginName
),
util
.
MountsInGlobalPDPath
,
devName
)
}
}
func
(
vv
*
vsphereVolume
)
GetPath
()
string
{
func
(
vv
*
vsphereVolume
)
GetPath
()
string
{
...
...
pkg/volume/vsphere_volume/vsphere_volume_block.go
View file @
b5c34d0c
...
@@ -18,7 +18,6 @@ package vsphere_volume
...
@@ -18,7 +18,6 @@ package vsphere_volume
import
(
import
(
"fmt"
"fmt"
"path"
"path/filepath"
"path/filepath"
"strings"
"strings"
...
@@ -153,7 +152,7 @@ func (v *vsphereVolume) GetGlobalMapPath(spec *volume.Spec) (string, error) {
...
@@ -153,7 +152,7 @@ func (v *vsphereVolume) GetGlobalMapPath(spec *volume.Spec) (string, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
return
path
.
Join
(
v
.
plugin
.
host
.
GetVolumeDevicePluginDir
(
vsphereVolumePluginName
),
string
(
volumeSource
.
VolumePath
)),
nil
return
file
path
.
Join
(
v
.
plugin
.
host
.
GetVolumeDevicePluginDir
(
vsphereVolumePluginName
),
string
(
volumeSource
.
VolumePath
)),
nil
}
}
func
(
v
*
vsphereVolume
)
GetPodDeviceMapPath
()
(
string
,
string
)
{
func
(
v
*
vsphereVolume
)
GetPodDeviceMapPath
()
(
string
,
string
)
{
...
...
pkg/volume/vsphere_volume/vsphere_volume_block_test.go
View file @
b5c34d0c
...
@@ -18,7 +18,7 @@ package vsphere_volume
...
@@ -18,7 +18,7 @@ package vsphere_volume
import
(
import
(
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -46,7 +46,7 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) {
...
@@ -46,7 +46,7 @@ func TestGetVolumeSpecFromGlobalMapPath(t *testing.T) {
// deferred clean up
// deferred clean up
defer
os
.
RemoveAll
(
tmpVDir
)
defer
os
.
RemoveAll
(
tmpVDir
)
expectedGlobalPath
:=
path
.
Join
(
tmpVDir
,
testGlobalPath
)
expectedGlobalPath
:=
file
path
.
Join
(
tmpVDir
,
testGlobalPath
)
// Bad Path
// Bad Path
badspec
,
err
:=
getVolumeSpecFromGlobalMapPath
(
""
)
badspec
,
err
:=
getVolumeSpecFromGlobalMapPath
(
""
)
...
@@ -80,8 +80,8 @@ func TestGetPodAndPluginMapPaths(t *testing.T) {
...
@@ -80,8 +80,8 @@ func TestGetPodAndPluginMapPaths(t *testing.T) {
// deferred clean up
// deferred clean up
defer
os
.
RemoveAll
(
tmpVDir
)
defer
os
.
RemoveAll
(
tmpVDir
)
expectedGlobalPath
:=
path
.
Join
(
tmpVDir
,
testGlobalPath
)
expectedGlobalPath
:=
file
path
.
Join
(
tmpVDir
,
testGlobalPath
)
expectedPodPath
:=
path
.
Join
(
tmpVDir
,
testPodPath
)
expectedPodPath
:=
file
path
.
Join
(
tmpVDir
,
testPodPath
)
spec
:=
getTestVolume
(
true
)
// block volume
spec
:=
getTestVolume
(
true
)
// block volume
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
:=
volume
.
VolumePluginMgr
{}
...
...
pkg/volume/vsphere_volume/vsphere_volume_test.go
View file @
b5c34d0c
...
@@ -19,7 +19,7 @@ package vsphere_volume
...
@@ -19,7 +19,7 @@ package vsphere_volume
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"path"
"path
/filepath
"
"testing"
"testing"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
...
@@ -117,7 +117,7 @@ func TestPlugin(t *testing.T) {
...
@@ -117,7 +117,7 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"Got a nil Mounter"
)
t
.
Errorf
(
"Got a nil Mounter"
)
}
}
mntPath
:=
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~vsphere-volume/vol1"
)
mntPath
:=
file
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~vsphere-volume/vol1"
)
path
:=
mounter
.
GetPath
()
path
:=
mounter
.
GetPath
()
if
path
!=
mntPath
{
if
path
!=
mntPath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
...
...
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