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
2b44ec5e
Commit
2b44ec5e
authored
Nov 20, 2018
by
saad-ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce csipb dependencies
Remove csipb dependency from everywhere except the CSI client in preperation for supporting multiple CSI clients.
parent
8f666d9e
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
91 additions
and
93 deletions
+91
-93
BUILD
pkg/volume/csi/BUILD
+2
-0
csi_attacher.go
pkg/volume/csi/csi_attacher.go
+2
-21
csi_block.go
pkg/volume/csi/csi_block.go
+2
-2
csi_client.go
pkg/volume/csi/csi_client.go
+25
-9
csi_client_test.go
pkg/volume/csi/csi_client_test.go
+33
-17
csi_mounter.go
pkg/volume/csi/csi_mounter.go
+1
-1
BUILD
pkg/volume/csi/nodeinfomanager/BUILD
+0
-2
nodeinfomanager.go
pkg/volume/csi/nodeinfomanager/nodeinfomanager.go
+13
-15
nodeinfomanager_test.go
pkg/volume/csi/nodeinfomanager/nodeinfomanager_test.go
+13
-26
No files found.
pkg/volume/csi/BUILD
View file @
2b44ec5e
...
@@ -23,6 +23,7 @@ go_library(
...
@@ -23,6 +23,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
...
@@ -86,6 +87,7 @@ filegroup(
...
@@ -86,6 +87,7 @@ filegroup(
name = "all-srcs",
name = "all-srcs",
srcs = [
srcs = [
":package-srcs",
":package-srcs",
"//pkg/volume/csi/csiv0:all-srcs",
"//pkg/volume/csi/fake:all-srcs",
"//pkg/volume/csi/fake:all-srcs",
"//pkg/volume/csi/nodeinfomanager:all-srcs",
"//pkg/volume/csi/nodeinfomanager:all-srcs",
],
],
...
...
pkg/volume/csi/csi_attacher.go
View file @
2b44ec5e
...
@@ -29,7 +29,6 @@ import (
...
@@ -29,7 +29,6 @@ import (
"k8s.io/klog"
"k8s.io/klog"
csipb
"github.com/container-storage-interface/spec/lib/go/csi"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
storage
"k8s.io/api/storage/v1beta1"
storage
"k8s.io/api/storage/v1beta1"
apierrs
"k8s.io/apimachinery/pkg/api/errors"
apierrs
"k8s.io/apimachinery/pkg/api/errors"
...
@@ -349,7 +348,7 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
...
@@ -349,7 +348,7 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
csiTimeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
csiTimeout
)
defer
cancel
()
defer
cancel
()
// Check whether "STAGE_UNSTAGE_VOLUME" is set
// Check whether "STAGE_UNSTAGE_VOLUME" is set
stageUnstageSet
,
err
:=
hasStageUnstageCapability
(
ctx
,
csi
)
stageUnstageSet
,
err
:=
csi
.
NodeSupportsStageUnstage
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -529,7 +528,7 @@ func (c *csiAttacher) UnmountDevice(deviceMountPath string) error {
...
@@ -529,7 +528,7 @@ func (c *csiAttacher) UnmountDevice(deviceMountPath string) error {
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
csiTimeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
csiTimeout
)
defer
cancel
()
defer
cancel
()
// Check whether "STAGE_UNSTAGE_VOLUME" is set
// Check whether "STAGE_UNSTAGE_VOLUME" is set
stageUnstageSet
,
err
:=
hasStageUnstageCapability
(
ctx
,
csi
)
stageUnstageSet
,
err
:=
csi
.
NodeSupportsStageUnstage
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Errorf
(
log
(
"attacher.UnmountDevice failed to check whether STAGE_UNSTAGE_VOLUME set: %v"
,
err
))
klog
.
Errorf
(
log
(
"attacher.UnmountDevice failed to check whether STAGE_UNSTAGE_VOLUME set: %v"
,
err
))
return
err
return
err
...
@@ -563,24 +562,6 @@ func (c *csiAttacher) UnmountDevice(deviceMountPath string) error {
...
@@ -563,24 +562,6 @@ func (c *csiAttacher) UnmountDevice(deviceMountPath string) error {
return
nil
return
nil
}
}
func
hasStageUnstageCapability
(
ctx
context
.
Context
,
csi
csiClient
)
(
bool
,
error
)
{
capabilities
,
err
:=
csi
.
NodeGetCapabilities
(
ctx
)
if
err
!=
nil
{
return
false
,
err
}
stageUnstageSet
:=
false
if
capabilities
==
nil
{
return
false
,
nil
}
for
_
,
capability
:=
range
capabilities
{
if
capability
.
GetRpc
()
.
GetType
()
==
csipb
.
NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME
{
stageUnstageSet
=
true
}
}
return
stageUnstageSet
,
nil
}
// getAttachmentName returns csi-<sha252(volName,csiDriverName,NodeName>
// getAttachmentName returns csi-<sha252(volName,csiDriverName,NodeName>
func
getAttachmentName
(
volName
,
csiDriverName
,
nodeName
string
)
string
{
func
getAttachmentName
(
volName
,
csiDriverName
,
nodeName
string
)
string
{
result
:=
sha256
.
Sum256
([]
byte
(
fmt
.
Sprintf
(
"%s%s%s"
,
volName
,
csiDriverName
,
nodeName
)))
result
:=
sha256
.
Sum256
([]
byte
(
fmt
.
Sprintf
(
"%s%s%s"
,
volName
,
csiDriverName
,
nodeName
)))
...
...
pkg/volume/csi/csi_block.go
View file @
2b44ec5e
...
@@ -96,7 +96,7 @@ func (m *csiBlockMapper) stageVolumeForBlock(
...
@@ -96,7 +96,7 @@ func (m *csiBlockMapper) stageVolumeForBlock(
klog
.
V
(
4
)
.
Infof
(
log
(
"blockMapper.stageVolumeForBlock stagingPath set [%s]"
,
stagingPath
))
klog
.
V
(
4
)
.
Infof
(
log
(
"blockMapper.stageVolumeForBlock stagingPath set [%s]"
,
stagingPath
))
// Check whether "STAGE_UNSTAGE_VOLUME" is set
// Check whether "STAGE_UNSTAGE_VOLUME" is set
stageUnstageSet
,
err
:=
hasStageUnstageCapability
(
ctx
,
csi
)
stageUnstageSet
,
err
:=
csi
.
NodeSupportsStageUnstage
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Error
(
log
(
"blockMapper.stageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v"
,
err
))
klog
.
Error
(
log
(
"blockMapper.stageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v"
,
err
))
return
""
,
err
return
""
,
err
...
@@ -287,7 +287,7 @@ func (m *csiBlockMapper) unpublishVolumeForBlock(ctx context.Context, csi csiCli
...
@@ -287,7 +287,7 @@ func (m *csiBlockMapper) unpublishVolumeForBlock(ctx context.Context, csi csiCli
// unstageVolumeForBlock unstages a block volume from stagingPath
// unstageVolumeForBlock unstages a block volume from stagingPath
func
(
m
*
csiBlockMapper
)
unstageVolumeForBlock
(
ctx
context
.
Context
,
csi
csiClient
,
stagingPath
string
)
error
{
func
(
m
*
csiBlockMapper
)
unstageVolumeForBlock
(
ctx
context
.
Context
,
csi
csiClient
,
stagingPath
string
)
error
{
// Check whether "STAGE_UNSTAGE_VOLUME" is set
// Check whether "STAGE_UNSTAGE_VOLUME" is set
stageUnstageSet
,
err
:=
hasStageUnstageCapability
(
ctx
,
csi
)
stageUnstageSet
,
err
:=
csi
.
NodeSupportsStageUnstage
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Error
(
log
(
"blockMapper.unstageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v"
,
err
))
klog
.
Error
(
log
(
"blockMapper.unstageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v"
,
err
))
return
err
return
err
...
...
pkg/volume/csi/csi_client.go
View file @
2b44ec5e
...
@@ -36,7 +36,7 @@ type csiClient interface {
...
@@ -36,7 +36,7 @@ type csiClient interface {
NodeGetInfo
(
ctx
context
.
Context
)
(
NodeGetInfo
(
ctx
context
.
Context
)
(
nodeID
string
,
nodeID
string
,
maxVolumePerNode
int64
,
maxVolumePerNode
int64
,
accessibleTopology
*
csipb
.
Topology
,
accessibleTopology
map
[
string
]
string
,
err
error
)
err
error
)
NodePublishVolume
(
NodePublishVolume
(
ctx
context
.
Context
,
ctx
context
.
Context
,
...
@@ -66,7 +66,7 @@ type csiClient interface {
...
@@ -66,7 +66,7 @@ type csiClient interface {
volumeContext
map
[
string
]
string
,
volumeContext
map
[
string
]
string
,
)
error
)
error
NodeUnstageVolume
(
ctx
context
.
Context
,
volID
,
stagingTargetPath
string
)
error
NodeUnstageVolume
(
ctx
context
.
Context
,
volID
,
stagingTargetPath
string
)
error
Node
GetCapabilities
(
ctx
context
.
Context
)
([]
*
csipb
.
NodeServiceCapability
,
error
)
Node
SupportsStageUnstage
(
ctx
context
.
Context
)
(
bool
,
error
)
}
}
// csiClient encapsulates all csi-plugin methods
// csiClient encapsulates all csi-plugin methods
...
@@ -110,7 +110,7 @@ func newCsiDriverClient(driverName string) *csiDriverClient {
...
@@ -110,7 +110,7 @@ func newCsiDriverClient(driverName string) *csiDriverClient {
func
(
c
*
csiDriverClient
)
NodeGetInfo
(
ctx
context
.
Context
)
(
func
(
c
*
csiDriverClient
)
NodeGetInfo
(
ctx
context
.
Context
)
(
nodeID
string
,
nodeID
string
,
maxVolumePerNode
int64
,
maxVolumePerNode
int64
,
accessibleTopology
*
csipb
.
Topology
,
accessibleTopology
map
[
string
]
string
,
err
error
)
{
err
error
)
{
klog
.
V
(
4
)
.
Info
(
log
(
"calling NodeGetInfo rpc"
))
klog
.
V
(
4
)
.
Info
(
log
(
"calling NodeGetInfo rpc"
))
...
@@ -125,7 +125,11 @@ func (c *csiDriverClient) NodeGetInfo(ctx context.Context) (
...
@@ -125,7 +125,11 @@ func (c *csiDriverClient) NodeGetInfo(ctx context.Context) (
return
""
,
0
,
nil
,
err
return
""
,
0
,
nil
,
err
}
}
return
res
.
GetNodeId
(),
res
.
GetMaxVolumesPerNode
(),
res
.
GetAccessibleTopology
(),
nil
topology
:=
res
.
GetAccessibleTopology
()
if
topology
!=
nil
{
accessibleTopology
=
topology
.
Segments
}
return
res
.
GetNodeId
(),
res
.
GetMaxVolumesPerNode
(),
accessibleTopology
,
nil
}
}
func
(
c
*
csiDriverClient
)
NodePublishVolume
(
func
(
c
*
csiDriverClient
)
NodePublishVolume
(
...
@@ -288,21 +292,33 @@ func (c *csiDriverClient) NodeUnstageVolume(ctx context.Context, volID, stagingT
...
@@ -288,21 +292,33 @@ func (c *csiDriverClient) NodeUnstageVolume(ctx context.Context, volID, stagingT
return
err
return
err
}
}
func
(
c
*
csiDriverClient
)
Node
GetCapabilities
(
ctx
context
.
Context
)
([]
*
csipb
.
NodeServiceCapability
,
error
)
{
func
(
c
*
csiDriverClient
)
Node
SupportsStageUnstage
(
ctx
context
.
Context
)
(
bool
,
error
)
{
klog
.
V
(
4
)
.
Info
(
log
(
"calling NodeGetCapabilities rpc"
))
klog
.
V
(
4
)
.
Info
(
log
(
"calling NodeGetCapabilities rpc
to determine if NodeSupportsStageUnstage
"
))
nodeClient
,
closer
,
err
:=
c
.
nodeClientCreator
(
c
.
driverName
)
nodeClient
,
closer
,
err
:=
c
.
nodeClientCreator
(
c
.
driverName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
false
,
err
}
}
defer
closer
.
Close
()
defer
closer
.
Close
()
req
:=
&
csipb
.
NodeGetCapabilitiesRequest
{}
req
:=
&
csipb
.
NodeGetCapabilitiesRequest
{}
resp
,
err
:=
nodeClient
.
NodeGetCapabilities
(
ctx
,
req
)
resp
,
err
:=
nodeClient
.
NodeGetCapabilities
(
ctx
,
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
false
,
err
}
capabilities
:=
resp
.
GetCapabilities
()
stageUnstageSet
:=
false
if
capabilities
==
nil
{
return
false
,
nil
}
for
_
,
capability
:=
range
capabilities
{
if
capability
.
GetRpc
()
.
GetType
()
==
csipb
.
NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME
{
stageUnstageSet
=
true
}
}
}
return
resp
.
GetCapabilities
()
,
nil
return
stageUnstageSet
,
nil
}
}
func
asCSIAccessMode
(
am
api
.
PersistentVolumeAccessMode
)
csipb
.
VolumeCapability_AccessMode_Mode
{
func
asCSIAccessMode
(
am
api
.
PersistentVolumeAccessMode
)
csipb
.
VolumeCapability_AccessMode_Mode
{
...
...
pkg/volume/csi/csi_client_test.go
View file @
2b44ec5e
...
@@ -43,10 +43,14 @@ func newFakeCsiDriverClient(t *testing.T, stagingCapable bool) *fakeCsiDriverCli
...
@@ -43,10 +43,14 @@ func newFakeCsiDriverClient(t *testing.T, stagingCapable bool) *fakeCsiDriverCli
func
(
c
*
fakeCsiDriverClient
)
NodeGetInfo
(
ctx
context
.
Context
)
(
func
(
c
*
fakeCsiDriverClient
)
NodeGetInfo
(
ctx
context
.
Context
)
(
nodeID
string
,
nodeID
string
,
maxVolumePerNode
int64
,
maxVolumePerNode
int64
,
accessibleTopology
*
csipb
.
Topology
,
accessibleTopology
map
[
string
]
string
,
err
error
)
{
err
error
)
{
resp
,
err
:=
c
.
nodeClient
.
NodeGetInfo
(
ctx
,
&
csipb
.
NodeGetInfoRequest
{})
resp
,
err
:=
c
.
nodeClient
.
NodeGetInfo
(
ctx
,
&
csipb
.
NodeGetInfoRequest
{})
return
resp
.
GetNodeId
(),
resp
.
GetMaxVolumesPerNode
(),
resp
.
GetAccessibleTopology
(),
err
topology
:=
resp
.
GetAccessibleTopology
()
if
topology
!=
nil
{
accessibleTopology
=
topology
.
Segments
}
return
resp
.
GetNodeId
(),
resp
.
GetMaxVolumesPerNode
(),
accessibleTopology
,
err
}
}
func
(
c
*
fakeCsiDriverClient
)
NodePublishVolume
(
func
(
c
*
fakeCsiDriverClient
)
NodePublishVolume
(
...
@@ -140,14 +144,26 @@ func (c *fakeCsiDriverClient) NodeUnstageVolume(ctx context.Context, volID, stag
...
@@ -140,14 +144,26 @@ func (c *fakeCsiDriverClient) NodeUnstageVolume(ctx context.Context, volID, stag
return
err
return
err
}
}
func
(
c
*
fakeCsiDriverClient
)
Node
GetCapabilities
(
ctx
context
.
Context
)
([]
*
csipb
.
NodeServiceCapability
,
error
)
{
func
(
c
*
fakeCsiDriverClient
)
Node
SupportsStageUnstage
(
ctx
context
.
Context
)
(
bool
,
error
)
{
c
.
t
.
Log
(
"calling fake.NodeGetCapabilities..."
)
c
.
t
.
Log
(
"calling fake.NodeGetCapabilities
for NodeSupportsStageUnstage
..."
)
req
:=
&
csipb
.
NodeGetCapabilitiesRequest
{}
req
:=
&
csipb
.
NodeGetCapabilitiesRequest
{}
resp
,
err
:=
c
.
nodeClient
.
NodeGetCapabilities
(
ctx
,
req
)
resp
,
err
:=
c
.
nodeClient
.
NodeGetCapabilities
(
ctx
,
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
false
,
err
}
capabilities
:=
resp
.
GetCapabilities
()
stageUnstageSet
:=
false
if
capabilities
==
nil
{
return
false
,
nil
}
}
return
resp
.
GetCapabilities
(),
nil
for
_
,
capability
:=
range
capabilities
{
if
capability
.
GetRpc
()
.
GetType
()
==
csipb
.
NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME
{
stageUnstageSet
=
true
}
}
return
stageUnstageSet
,
nil
}
}
func
setupClient
(
t
*
testing
.
T
,
stageUnstageSet
bool
)
csiClient
{
func
setupClient
(
t
*
testing
.
T
,
stageUnstageSet
bool
)
csiClient
{
...
@@ -173,17 +189,15 @@ func TestClientNodeGetInfo(t *testing.T) {
...
@@ -173,17 +189,15 @@ func TestClientNodeGetInfo(t *testing.T) {
name
string
name
string
expectedNodeID
string
expectedNodeID
string
expectedMaxVolumePerNode
int64
expectedMaxVolumePerNode
int64
expectedAccessibleTopology
*
csipb
.
Topology
expectedAccessibleTopology
map
[
string
]
string
mustFail
bool
mustFail
bool
err
error
err
error
}{
}{
{
{
name
:
"test ok"
,
name
:
"test ok"
,
expectedNodeID
:
"node1"
,
expectedNodeID
:
"node1"
,
expectedMaxVolumePerNode
:
16
,
expectedMaxVolumePerNode
:
16
,
expectedAccessibleTopology
:
&
csipb
.
Topology
{
expectedAccessibleTopology
:
map
[
string
]
string
{
"com.example.csi-topology/zone"
:
"zone1"
},
Segments
:
map
[
string
]
string
{
"com.example.csi-topology/zone"
:
"zone1"
},
},
},
},
{
{
name
:
"grpc error"
,
name
:
"grpc error"
,
...
@@ -202,9 +216,11 @@ func TestClientNodeGetInfo(t *testing.T) {
...
@@ -202,9 +216,11 @@ func TestClientNodeGetInfo(t *testing.T) {
nodeClient
:=
fake
.
NewNodeClient
(
false
/* stagingCapable */
)
nodeClient
:=
fake
.
NewNodeClient
(
false
/* stagingCapable */
)
nodeClient
.
SetNextError
(
tc
.
err
)
nodeClient
.
SetNextError
(
tc
.
err
)
nodeClient
.
SetNodeGetInfoResp
(
&
csipb
.
NodeGetInfoResponse
{
nodeClient
.
SetNodeGetInfoResp
(
&
csipb
.
NodeGetInfoResponse
{
NodeId
:
tc
.
expectedNodeID
,
NodeId
:
tc
.
expectedNodeID
,
MaxVolumesPerNode
:
tc
.
expectedMaxVolumePerNode
,
MaxVolumesPerNode
:
tc
.
expectedMaxVolumePerNode
,
AccessibleTopology
:
tc
.
expectedAccessibleTopology
,
AccessibleTopology
:
&
csipb
.
Topology
{
Segments
:
tc
.
expectedAccessibleTopology
,
},
})
})
return
nodeClient
,
fakeCloser
,
nil
return
nodeClient
,
fakeCloser
,
nil
},
},
...
@@ -222,7 +238,7 @@ func TestClientNodeGetInfo(t *testing.T) {
...
@@ -222,7 +238,7 @@ func TestClientNodeGetInfo(t *testing.T) {
}
}
if
!
reflect
.
DeepEqual
(
accessibleTopology
,
tc
.
expectedAccessibleTopology
)
{
if
!
reflect
.
DeepEqual
(
accessibleTopology
,
tc
.
expectedAccessibleTopology
)
{
t
.
Errorf
(
"expected accessibleTopology: %v; got: %v"
,
*
tc
.
expectedAccessibleTopology
,
*
accessibleTopology
)
t
.
Errorf
(
"expected accessibleTopology: %v; got: %v"
,
tc
.
expectedAccessibleTopology
,
accessibleTopology
)
}
}
if
!
tc
.
mustFail
{
if
!
tc
.
mustFail
{
...
...
pkg/volume/csi/csi_mounter.go
View file @
2b44ec5e
...
@@ -121,7 +121,7 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -121,7 +121,7 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
// Check for STAGE_UNSTAGE_VOLUME set and populate deviceMountPath if so
// Check for STAGE_UNSTAGE_VOLUME set and populate deviceMountPath if so
deviceMountPath
:=
""
deviceMountPath
:=
""
stageUnstageSet
,
err
:=
hasStageUnstageCapability
(
ctx
,
csi
)
stageUnstageSet
,
err
:=
csi
.
NodeSupportsStageUnstage
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Error
(
log
(
"mounter.SetUpAt failed to check for STAGE_UNSTAGE_VOLUME capabilty: %v"
,
err
))
klog
.
Error
(
log
(
"mounter.SetUpAt failed to check for STAGE_UNSTAGE_VOLUME capabilty: %v"
,
err
))
return
err
return
err
...
...
pkg/volume/csi/nodeinfomanager/BUILD
View file @
2b44ec5e
...
@@ -21,7 +21,6 @@ go_library(
...
@@ -21,7 +21,6 @@ go_library(
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/csi-api/pkg/apis/csi/v1alpha1:go_default_library",
"//staging/src/k8s.io/csi-api/pkg/apis/csi/v1alpha1:go_default_library",
"//staging/src/k8s.io/csi-api/pkg/client/clientset/versioned:go_default_library",
"//staging/src/k8s.io/csi-api/pkg/client/clientset/versioned:go_default_library",
"//vendor/github.com/container-storage-interface/spec/lib/go/csi:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
],
)
)
...
@@ -63,7 +62,6 @@ go_test(
...
@@ -63,7 +62,6 @@ go_test(
"//staging/src/k8s.io/client-go/util/testing:go_default_library",
"//staging/src/k8s.io/client-go/util/testing:go_default_library",
"//staging/src/k8s.io/csi-api/pkg/apis/csi/v1alpha1:go_default_library",
"//staging/src/k8s.io/csi-api/pkg/apis/csi/v1alpha1:go_default_library",
"//staging/src/k8s.io/csi-api/pkg/client/clientset/versioned/fake:go_default_library",
"//staging/src/k8s.io/csi-api/pkg/client/clientset/versioned/fake:go_default_library",
"//vendor/github.com/container-storage-interface/spec/lib/go/csi:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
],
)
)
pkg/volume/csi/nodeinfomanager/nodeinfomanager.go
View file @
2b44ec5e
...
@@ -23,7 +23,8 @@ import (
...
@@ -23,7 +23,8 @@ import (
"fmt"
"fmt"
"strings"
"strings"
csipb
"github.com/container-storage-interface/spec/lib/go/csi"
"time"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
...
@@ -40,7 +41,6 @@ import (
...
@@ -40,7 +41,6 @@ import (
nodeutil
"k8s.io/kubernetes/pkg/util/node"
nodeutil
"k8s.io/kubernetes/pkg/util/node"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
"k8s.io/kubernetes/pkg/volume/util"
"time"
)
)
const
(
const
(
...
@@ -75,7 +75,7 @@ type Interface interface {
...
@@ -75,7 +75,7 @@ type Interface interface {
// Record in the cluster the given node information from the CSI driver with the given name.
// Record in the cluster the given node information from the CSI driver with the given name.
// Concurrent calls to InstallCSIDriver() is allowed, but they should not be intertwined with calls
// Concurrent calls to InstallCSIDriver() is allowed, but they should not be intertwined with calls
// to other methods in this interface.
// to other methods in this interface.
InstallCSIDriver
(
driverName
string
,
driverNodeID
string
,
maxVolumeLimit
int64
,
topology
*
csipb
.
Topology
)
error
InstallCSIDriver
(
driverName
string
,
driverNodeID
string
,
maxVolumeLimit
int64
,
topology
map
[
string
]
string
)
error
// Remove in the cluster node information from the CSI driver with the given name.
// Remove in the cluster node information from the CSI driver with the given name.
// Concurrent calls to UninstallCSIDriver() is allowed, but they should not be intertwined with calls
// Concurrent calls to UninstallCSIDriver() is allowed, but they should not be intertwined with calls
...
@@ -97,7 +97,7 @@ func NewNodeInfoManager(
...
@@ -97,7 +97,7 @@ func NewNodeInfoManager(
// CSINodeInfo object. If the CSINodeInfo object doesn't yet exist, it will be created.
// CSINodeInfo object. If the CSINodeInfo object doesn't yet exist, it will be created.
// If multiple calls to InstallCSIDriver() are made in parallel, some calls might receive Node or
// If multiple calls to InstallCSIDriver() are made in parallel, some calls might receive Node or
// CSINodeInfo update conflicts, which causes the function to retry the corresponding update.
// CSINodeInfo update conflicts, which causes the function to retry the corresponding update.
func
(
nim
*
nodeInfoManager
)
InstallCSIDriver
(
driverName
string
,
driverNodeID
string
,
maxAttachLimit
int64
,
topology
*
csipb
.
Topology
)
error
{
func
(
nim
*
nodeInfoManager
)
InstallCSIDriver
(
driverName
string
,
driverNodeID
string
,
maxAttachLimit
int64
,
topology
map
[
string
]
string
)
error
{
if
driverNodeID
==
""
{
if
driverNodeID
==
""
{
return
fmt
.
Errorf
(
"error adding CSI driver node info: driverNodeID must not be empty"
)
return
fmt
.
Errorf
(
"error adding CSI driver node info: driverNodeID must not be empty"
)
}
}
...
@@ -321,13 +321,13 @@ func removeNodeIDFromNode(csiDriverName string) nodeUpdateFunc {
...
@@ -321,13 +321,13 @@ func removeNodeIDFromNode(csiDriverName string) nodeUpdateFunc {
// updateTopologyLabels returns a function that updates labels of a Node object with the given
// updateTopologyLabels returns a function that updates labels of a Node object with the given
// topology information.
// topology information.
func
updateTopologyLabels
(
topology
*
csipb
.
Topology
)
nodeUpdateFunc
{
func
updateTopologyLabels
(
topology
map
[
string
]
string
)
nodeUpdateFunc
{
return
func
(
node
*
v1
.
Node
)
(
*
v1
.
Node
,
bool
,
error
)
{
return
func
(
node
*
v1
.
Node
)
(
*
v1
.
Node
,
bool
,
error
)
{
if
topology
==
nil
||
len
(
topology
.
Segments
)
==
0
{
if
topology
==
nil
||
len
(
topology
)
==
0
{
return
node
,
false
,
nil
return
node
,
false
,
nil
}
}
for
k
,
v
:=
range
topology
.
Segments
{
for
k
,
v
:=
range
topology
{
if
curVal
,
exists
:=
node
.
Labels
[
k
];
exists
&&
curVal
!=
v
{
if
curVal
,
exists
:=
node
.
Labels
[
k
];
exists
&&
curVal
!=
v
{
return
nil
,
false
,
fmt
.
Errorf
(
"detected topology value collision: driver reported %q:%q but existing label is %q:%q"
,
k
,
v
,
k
,
curVal
)
return
nil
,
false
,
fmt
.
Errorf
(
"detected topology value collision: driver reported %q:%q but existing label is %q:%q"
,
k
,
v
,
k
,
curVal
)
}
}
...
@@ -336,7 +336,7 @@ func updateTopologyLabels(topology *csipb.Topology) nodeUpdateFunc {
...
@@ -336,7 +336,7 @@ func updateTopologyLabels(topology *csipb.Topology) nodeUpdateFunc {
if
node
.
Labels
==
nil
{
if
node
.
Labels
==
nil
{
node
.
Labels
=
make
(
map
[
string
]
string
)
node
.
Labels
=
make
(
map
[
string
]
string
)
}
}
for
k
,
v
:=
range
topology
.
Segments
{
for
k
,
v
:=
range
topology
{
node
.
Labels
[
k
]
=
v
node
.
Labels
[
k
]
=
v
}
}
return
node
,
true
,
nil
return
node
,
true
,
nil
...
@@ -346,7 +346,7 @@ func updateTopologyLabels(topology *csipb.Topology) nodeUpdateFunc {
...
@@ -346,7 +346,7 @@ func updateTopologyLabels(topology *csipb.Topology) nodeUpdateFunc {
func
(
nim
*
nodeInfoManager
)
updateCSINodeInfo
(
func
(
nim
*
nodeInfoManager
)
updateCSINodeInfo
(
driverName
string
,
driverName
string
,
driverNodeID
string
,
driverNodeID
string
,
topology
*
csipb
.
Topology
)
error
{
topology
map
[
string
]
string
)
error
{
csiKubeClient
:=
nim
.
volumeHost
.
GetCSIClient
()
csiKubeClient
:=
nim
.
volumeHost
.
GetCSIClient
()
if
csiKubeClient
==
nil
{
if
csiKubeClient
==
nil
{
...
@@ -371,7 +371,7 @@ func (nim *nodeInfoManager) tryUpdateCSINodeInfo(
...
@@ -371,7 +371,7 @@ func (nim *nodeInfoManager) tryUpdateCSINodeInfo(
csiKubeClient
csiclientset
.
Interface
,
csiKubeClient
csiclientset
.
Interface
,
driverName
string
,
driverName
string
,
driverNodeID
string
,
driverNodeID
string
,
topology
*
csipb
.
Topology
)
error
{
topology
map
[
string
]
string
)
error
{
nodeInfo
,
err
:=
csiKubeClient
.
CsiV1alpha1
()
.
CSINodeInfos
()
.
Get
(
string
(
nim
.
nodeName
),
metav1
.
GetOptions
{})
nodeInfo
,
err
:=
csiKubeClient
.
CsiV1alpha1
()
.
CSINodeInfos
()
.
Get
(
string
(
nim
.
nodeName
),
metav1
.
GetOptions
{})
if
nodeInfo
==
nil
||
errors
.
IsNotFound
(
err
)
{
if
nodeInfo
==
nil
||
errors
.
IsNotFound
(
err
)
{
...
@@ -428,7 +428,7 @@ func (nim *nodeInfoManager) installDriverToCSINodeInfo(
...
@@ -428,7 +428,7 @@ func (nim *nodeInfoManager) installDriverToCSINodeInfo(
nodeInfo
*
csiv1alpha1
.
CSINodeInfo
,
nodeInfo
*
csiv1alpha1
.
CSINodeInfo
,
driverName
string
,
driverName
string
,
driverNodeID
string
,
driverNodeID
string
,
topology
*
csipb
.
Topology
)
error
{
topology
map
[
string
]
string
)
error
{
csiKubeClient
:=
nim
.
volumeHost
.
GetCSIClient
()
csiKubeClient
:=
nim
.
volumeHost
.
GetCSIClient
()
if
csiKubeClient
==
nil
{
if
csiKubeClient
==
nil
{
...
@@ -436,10 +436,8 @@ func (nim *nodeInfoManager) installDriverToCSINodeInfo(
...
@@ -436,10 +436,8 @@ func (nim *nodeInfoManager) installDriverToCSINodeInfo(
}
}
topologyKeys
:=
make
(
sets
.
String
)
topologyKeys
:=
make
(
sets
.
String
)
if
topology
!=
nil
{
for
k
:=
range
topology
{
for
k
:=
range
topology
.
Segments
{
topologyKeys
.
Insert
(
k
)
topologyKeys
.
Insert
(
k
)
}
}
}
specModified
:=
true
specModified
:=
true
...
...
pkg/volume/csi/nodeinfomanager/nodeinfomanager_test.go
View file @
2b44ec5e
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"fmt"
"fmt"
"testing"
"testing"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
...
@@ -49,7 +48,7 @@ type testcase struct {
...
@@ -49,7 +48,7 @@ type testcase struct {
existingNode
*
v1
.
Node
existingNode
*
v1
.
Node
existingNodeInfo
*
csiv1alpha1
.
CSINodeInfo
existingNodeInfo
*
csiv1alpha1
.
CSINodeInfo
inputNodeID
string
inputNodeID
string
inputTopology
*
csi
.
Topology
inputTopology
map
[
string
]
string
inputVolumeLimit
int64
inputVolumeLimit
int64
expectedNodeIDMap
map
[
string
]
string
expectedNodeIDMap
map
[
string
]
string
expectedTopologyMap
map
[
string
]
sets
.
String
expectedTopologyMap
map
[
string
]
sets
.
String
...
@@ -71,10 +70,8 @@ func TestInstallCSIDriver(t *testing.T) {
...
@@ -71,10 +70,8 @@ func TestInstallCSIDriver(t *testing.T) {
driverName
:
"com.example.csi/driver1"
,
driverName
:
"com.example.csi/driver1"
,
existingNode
:
generateNode
(
nil
/* nodeIDs */
,
nil
/* labels */
,
nil
/*capacity*/
),
existingNode
:
generateNode
(
nil
/* nodeIDs */
,
nil
/* labels */
,
nil
/*capacity*/
),
inputNodeID
:
"com.example.csi/csi-node1"
,
inputNodeID
:
"com.example.csi/csi-node1"
,
inputTopology
:
&
csi
.
Topology
{
inputTopology
:
map
[
string
]
string
{
Segments
:
map
[
string
]
string
{
"com.example.csi/zone"
:
"zoneA"
,
"com.example.csi/zone"
:
"zoneA"
,
},
},
},
expectedNodeIDMap
:
map
[
string
]
string
{
expectedNodeIDMap
:
map
[
string
]
string
{
"com.example.csi/driver1"
:
"com.example.csi/csi-node1"
,
"com.example.csi/driver1"
:
"com.example.csi/csi-node1"
,
...
@@ -104,10 +101,8 @@ func TestInstallCSIDriver(t *testing.T) {
...
@@ -104,10 +101,8 @@ func TestInstallCSIDriver(t *testing.T) {
},
},
),
),
inputNodeID
:
"com.example.csi/csi-node1"
,
inputNodeID
:
"com.example.csi/csi-node1"
,
inputTopology
:
&
csi
.
Topology
{
inputTopology
:
map
[
string
]
string
{
Segments
:
map
[
string
]
string
{
"com.example.csi/zone"
:
"zoneA"
,
"com.example.csi/zone"
:
"zoneA"
,
},
},
},
expectedNodeIDMap
:
map
[
string
]
string
{
expectedNodeIDMap
:
map
[
string
]
string
{
"com.example.csi/driver1"
:
"com.example.csi/csi-node1"
,
"com.example.csi/driver1"
:
"com.example.csi/csi-node1"
,
...
@@ -134,10 +129,8 @@ func TestInstallCSIDriver(t *testing.T) {
...
@@ -134,10 +129,8 @@ func TestInstallCSIDriver(t *testing.T) {
nil
,
/* topologyKeys */
nil
,
/* topologyKeys */
),
),
inputNodeID
:
"com.example.csi/csi-node1"
,
inputNodeID
:
"com.example.csi/csi-node1"
,
inputTopology
:
&
csi
.
Topology
{
inputTopology
:
map
[
string
]
string
{
Segments
:
map
[
string
]
string
{
"com.example.csi/zone"
:
"zoneA"
,
"com.example.csi/zone"
:
"zoneA"
,
},
},
},
expectedNodeIDMap
:
map
[
string
]
string
{
expectedNodeIDMap
:
map
[
string
]
string
{
"com.example.csi/driver1"
:
"com.example.csi/csi-node1"
,
"com.example.csi/driver1"
:
"com.example.csi/csi-node1"
,
...
@@ -168,10 +161,8 @@ func TestInstallCSIDriver(t *testing.T) {
...
@@ -168,10 +161,8 @@ func TestInstallCSIDriver(t *testing.T) {
},
},
),
),
inputNodeID
:
"com.example.csi/csi-node1"
,
inputNodeID
:
"com.example.csi/csi-node1"
,
inputTopology
:
&
csi
.
Topology
{
inputTopology
:
map
[
string
]
string
{
Segments
:
map
[
string
]
string
{
"com.example.csi/zone"
:
"zoneA"
,
"com.example.csi/zone"
:
"zoneA"
,
},
},
},
expectedNodeIDMap
:
map
[
string
]
string
{
expectedNodeIDMap
:
map
[
string
]
string
{
"com.example.csi/driver1"
:
"com.example.csi/csi-node1"
,
"com.example.csi/driver1"
:
"com.example.csi/csi-node1"
,
...
@@ -205,10 +196,8 @@ func TestInstallCSIDriver(t *testing.T) {
...
@@ -205,10 +196,8 @@ func TestInstallCSIDriver(t *testing.T) {
},
},
),
),
inputNodeID
:
"com.example.csi/csi-node1"
,
inputNodeID
:
"com.example.csi/csi-node1"
,
inputTopology
:
&
csi
.
Topology
{
inputTopology
:
map
[
string
]
string
{
Segments
:
map
[
string
]
string
{
"com.example.csi/zone"
:
"other-zone"
,
"com.example.csi/zone"
:
"other-zone"
,
},
},
},
expectFail
:
true
,
expectFail
:
true
,
},
},
...
@@ -231,10 +220,8 @@ func TestInstallCSIDriver(t *testing.T) {
...
@@ -231,10 +220,8 @@ func TestInstallCSIDriver(t *testing.T) {
},
},
),
),
inputNodeID
:
"com.example.csi/other-node"
,
inputNodeID
:
"com.example.csi/other-node"
,
inputTopology
:
&
csi
.
Topology
{
inputTopology
:
map
[
string
]
string
{
Segments
:
map
[
string
]
string
{
"com.example.csi/rack"
:
"rack1"
,
"com.example.csi/rack"
:
"rack1"
,
},
},
},
expectedNodeIDMap
:
map
[
string
]
string
{
expectedNodeIDMap
:
map
[
string
]
string
{
"com.example.csi/driver1"
:
"com.example.csi/other-node"
,
"com.example.csi/driver1"
:
"com.example.csi/other-node"
,
...
...
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