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
0711f427
Commit
0711f427
authored
Jul 05, 2019
by
caiweidong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bugfix: csi raw block that does not need attach mounted failed
Add unit test fix verify-test-featurefates failed
parent
4485c6f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
12 deletions
+104
-12
csi_block.go
pkg/volume/csi/csi_block.go
+21
-12
csi_block_test.go
pkg/volume/csi/csi_block_test.go
+83
-0
No files found.
pkg/volume/csi/csi_block.go
View file @
0711f427
...
@@ -104,9 +104,10 @@ func (m *csiBlockMapper) stageVolumeForBlock(
...
@@ -104,9 +104,10 @@ func (m *csiBlockMapper) stageVolumeForBlock(
klog
.
Infof
(
log
(
"blockMapper.stageVolumeForBlock STAGE_UNSTAGE_VOLUME capability not set. Skipping MountDevice..."
))
klog
.
Infof
(
log
(
"blockMapper.stageVolumeForBlock STAGE_UNSTAGE_VOLUME capability not set. Skipping MountDevice..."
))
return
""
,
nil
return
""
,
nil
}
}
publishVolumeInfo
:=
map
[
string
]
string
{}
publishVolumeInfo
:=
attachment
.
Status
.
AttachmentMetadata
if
attachment
!=
nil
{
publishVolumeInfo
=
attachment
.
Status
.
AttachmentMetadata
}
nodeStageSecrets
:=
map
[
string
]
string
{}
nodeStageSecrets
:=
map
[
string
]
string
{}
if
csiSource
.
NodeStageSecretRef
!=
nil
{
if
csiSource
.
NodeStageSecretRef
!=
nil
{
nodeStageSecrets
,
err
=
getCredentialsFromSecret
(
m
.
k8s
,
csiSource
.
NodeStageSecretRef
)
nodeStageSecrets
,
err
=
getCredentialsFromSecret
(
m
.
k8s
,
csiSource
.
NodeStageSecretRef
)
...
@@ -155,7 +156,10 @@ func (m *csiBlockMapper) publishVolumeForBlock(
...
@@ -155,7 +156,10 @@ func (m *csiBlockMapper) publishVolumeForBlock(
)
(
string
,
error
)
{
)
(
string
,
error
)
{
klog
.
V
(
4
)
.
Infof
(
log
(
"blockMapper.publishVolumeForBlock called"
))
klog
.
V
(
4
)
.
Infof
(
log
(
"blockMapper.publishVolumeForBlock called"
))
publishVolumeInfo
:=
attachment
.
Status
.
AttachmentMetadata
publishVolumeInfo
:=
map
[
string
]
string
{}
if
attachment
!=
nil
{
publishVolumeInfo
=
attachment
.
Status
.
AttachmentMetadata
}
nodePublishSecrets
:=
map
[
string
]
string
{}
nodePublishSecrets
:=
map
[
string
]
string
{}
var
err
error
var
err
error
...
@@ -223,18 +227,23 @@ func (m *csiBlockMapper) SetUpDevice() (string, error) {
...
@@ -223,18 +227,23 @@ func (m *csiBlockMapper) SetUpDevice() (string, error) {
return
""
,
err
return
""
,
err
}
}
// Search for attachment by VolumeAttachment.Spec.Source.PersistentVolumeName
driverName
:=
csiSource
.
Driver
nodeName
:=
string
(
m
.
plugin
.
host
.
GetNodeName
())
skip
,
err
:=
m
.
plugin
.
skipAttach
(
driverName
)
attachID
:=
getAttachmentName
(
csiSource
.
VolumeHandle
,
csiSource
.
Driver
,
nodeName
)
attachment
,
err
:=
m
.
k8s
.
StorageV1
()
.
VolumeAttachments
()
.
Get
(
attachID
,
meta
.
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Error
(
log
(
"blockMapper.SetupDevice failed to
get volume attachment [id=%v]: %v"
,
attachID
,
err
))
klog
.
Error
(
log
(
"blockMapper.SetupDevice failed to
check CSIDriver for %s: %v"
,
driverName
,
err
))
return
""
,
err
return
""
,
err
}
}
if
attachment
==
nil
{
var
attachment
*
storage
.
VolumeAttachment
klog
.
Error
(
log
(
"blockMapper.SetupDevice unable to find VolumeAttachment [id=%s]"
,
attachID
))
if
!
skip
{
return
""
,
errors
.
New
(
"no existing VolumeAttachment found"
)
// Search for attachment by VolumeAttachment.Spec.Source.PersistentVolumeName
nodeName
:=
string
(
m
.
plugin
.
host
.
GetNodeName
())
attachID
:=
getAttachmentName
(
csiSource
.
VolumeHandle
,
csiSource
.
Driver
,
nodeName
)
attachment
,
err
=
m
.
k8s
.
StorageV1
()
.
VolumeAttachments
()
.
Get
(
attachID
,
meta
.
GetOptions
{})
if
err
!=
nil
{
klog
.
Error
(
log
(
"blockMapper.SetupDevice failed to get volume attachment [id=%v]: %v"
,
attachID
,
err
))
return
""
,
err
}
}
}
//TODO (vladimirvivien) implement better AccessModes mapping between k8s and CSI
//TODO (vladimirvivien) implement better AccessModes mapping between k8s and CSI
...
...
pkg/volume/csi/csi_block_test.go
View file @
0711f427
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"testing"
"testing"
api
"k8s.io/api/core/v1"
api
"k8s.io/api/core/v1"
"k8s.io/api/storage/v1beta1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
fakeclient
"k8s.io/client-go/kubernetes/fake"
fakeclient
"k8s.io/client-go/kubernetes/fake"
...
@@ -354,6 +355,88 @@ func TestBlockMapperMapDevice(t *testing.T) {
...
@@ -354,6 +355,88 @@ func TestBlockMapperMapDevice(t *testing.T) {
}
}
}
}
func
TestBlockMapperMapDeviceNotSupportAttach
(
t
*
testing
.
T
)
{
defer
featuregatetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
defer
featuregatetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIDriverRegistry
,
true
)()
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
fakeClient
:=
fakeclient
.
NewSimpleClientset
()
attachRequired
:=
false
fakeDriver
:=
&
v1beta1
.
CSIDriver
{
ObjectMeta
:
meta
.
ObjectMeta
{
Name
:
testDriver
,
},
Spec
:
v1beta1
.
CSIDriverSpec
{
AttachRequired
:
&
attachRequired
,
},
}
_
,
err
:=
plug
.
host
.
GetKubeClient
()
.
StorageV1beta1
()
.
CSIDrivers
()
.
Create
(
fakeDriver
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create a fakeDriver: %v"
,
err
)
}
host
:=
volumetest
.
NewFakeVolumeHostWithCSINodeName
(
tmpDir
,
fakeClient
,
nil
,
"fakeNode"
,
nil
,
)
plug
.
host
=
host
csiMapper
,
_
,
_
,
err
:=
prepareBlockMapperTest
(
plug
,
"test-pv"
,
t
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to make a new Mapper: %v"
,
err
)
}
csiMapper
.
csiClient
=
setupClient
(
t
,
true
)
devicePath
,
err
:=
csiMapper
.
SetUpDevice
()
if
err
!=
nil
{
t
.
Fatalf
(
"mapper failed to SetupDevice: %v"
,
err
)
}
globalMapPath
,
err
:=
csiMapper
.
GetGlobalMapPath
(
csiMapper
.
spec
)
if
err
!=
nil
{
t
.
Fatalf
(
"mapper failed to GetGlobalMapPath: %v"
,
err
)
}
// Actual SetupDevice should create a symlink to or a bind mout of device in devicePath.
// Create dummy file there before calling MapDevice to test it properly.
fd
,
err
:=
os
.
Create
(
devicePath
)
if
err
!=
nil
{
t
.
Fatalf
(
"mapper failed to create dummy file in devicePath: %v"
,
err
)
}
if
err
:=
fd
.
Close
();
err
!=
nil
{
t
.
Fatalf
(
"mapper failed to close dummy file in devicePath: %v"
,
err
)
}
// Map device to global and pod device map path
volumeMapPath
,
volName
:=
csiMapper
.
GetPodDeviceMapPath
()
err
=
csiMapper
.
MapDevice
(
devicePath
,
globalMapPath
,
volumeMapPath
,
volName
,
csiMapper
.
podUID
)
if
err
!=
nil
{
t
.
Fatalf
(
"mapper failed to GetGlobalMapPath: %v"
,
err
)
}
// Check if symlink {globalMapPath}/{podUID} exists
globalMapFilePath
:=
filepath
.
Join
(
globalMapPath
,
string
(
csiMapper
.
podUID
))
if
_
,
err
:=
os
.
Stat
(
globalMapFilePath
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"mapper.MapDevice failed, symlink in globalMapPath not created: %v"
,
err
)
t
.
Errorf
(
"mapper.MapDevice devicePath:%v, globalMapPath: %v, globalMapFilePath: %v"
,
devicePath
,
globalMapPath
,
globalMapFilePath
)
}
else
{
t
.
Errorf
(
"mapper.MapDevice failed: %v"
,
err
)
}
}
// Check if symlink {volumeMapPath}/{volName} exists
volumeMapFilePath
:=
filepath
.
Join
(
volumeMapPath
,
volName
)
if
_
,
err
:=
os
.
Stat
(
volumeMapFilePath
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"mapper.MapDevice failed, symlink in volumeMapPath not created: %v"
,
err
)
}
else
{
t
.
Errorf
(
"mapper.MapDevice failed: %v"
,
err
)
}
}
}
func
TestBlockMapperTearDownDevice
(
t
*
testing
.
T
)
{
func
TestBlockMapperTearDownDevice
(
t
*
testing
.
T
)
{
defer
featuregatetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
defer
featuregatetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
CSIBlockVolume
,
true
)()
...
...
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