Skip to content

Commit

Permalink
Add volume expansion online/offline toggle to mock driver
Browse files Browse the repository at this point in the history
Adds a CLI flag to the mock driver to disable online volume expansion
and updates csi-sanity to account for the VolumeExpansion plugin
capability.

Signed-off-by: Jose A. Rivera <[email protected]>
  • Loading branch information
jarrpa committed Mar 1, 2019
1 parent ed673d8 commit 4087ca9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/mock-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func main() {
flag.Int64Var(&config.AttachLimit, "attach-limit", 0, "number of attachable volumes on a node")
flag.BoolVar(&config.NodeExpansionRequired, "node-expand-required", false, "Enables NodeServiceCapability_RPC_EXPAND_VOLUME capacity.")
flag.BoolVar(&config.DisableControllerExpansion, "disable-controller-expansion", false, "Disables ControllerServiceCapability_RPC_EXPAND_VOLUME capability.")
flag.BoolVar(&config.DisableOnlineExpansion, "disable-online-expansion", false, "Disables online volume expansion capability.")
flag.Parse()

endpoint := os.Getenv("CSI_ENDPOINT")
Expand Down
4 changes: 4 additions & 0 deletions mock/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ func (s *service) ControllerExpandVolume(
return nil, status.Error(codes.NotFound, req.VolumeId)
}

if s.config.DisableOnlineExpansion && MockVolumes[v.GetVolumeId()].ISPublished {
return nil, status.Error(codes.Aborted, "volume is published and online volume expansion is not supported")
}

requestBytes := req.CapacityRange.RequiredBytes

if v.CapacityBytes > requestBytes {
Expand Down
13 changes: 13 additions & 0 deletions mock/service/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func (s *service) GetPluginCapabilities(
req *csi.GetPluginCapabilitiesRequest) (
*csi.GetPluginCapabilitiesResponse, error) {

volExpType := csi.PluginCapability_VolumeExpansion_ONLINE

if s.config.DisableOnlineExpansion {
volExpType = csi.PluginCapability_VolumeExpansion_OFFLINE
}

return &csi.GetPluginCapabilitiesResponse{
Capabilities: []*csi.PluginCapability{
{
Expand All @@ -43,6 +49,13 @@ func (s *service) GetPluginCapabilities(
},
},
},
{
Type: &csi.PluginCapability_VolumeExpansion_{
VolumeExpansion: &csi.PluginCapability_VolumeExpansion{
Type: volExpType,
},
},
},
},
}, nil
}
1 change: 1 addition & 0 deletions mock/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Config struct {
AttachLimit int64
NodeExpansionRequired bool
DisableControllerExpansion bool
DisableOnlineExpansion bool
}

// Service is the CSI Mock service provider.
Expand Down
20 changes: 16 additions & 4 deletions pkg/sanity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,23 @@ var _ = DescribeSanity("Identity Service", func(sc *SanityContext) {
By("checking successful response")
Expect(res.GetCapabilities()).NotTo(BeNil())
for _, cap := range res.GetCapabilities() {
switch cap.GetService().GetType() {
case csi.PluginCapability_Service_CONTROLLER_SERVICE:
case csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS:
switch cap.GetType().(type) {
case *csi.PluginCapability_Service_:
switch cap.GetService().GetType() {
case csi.PluginCapability_Service_CONTROLLER_SERVICE:
case csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS:
default:
Fail(fmt.Sprintf("Unknown service: %v\n", cap.GetService().GetType()))
}
case *csi.PluginCapability_VolumeExpansion_:
switch cap.GetVolumeExpansion().GetType() {
case csi.PluginCapability_VolumeExpansion_ONLINE:
case csi.PluginCapability_VolumeExpansion_OFFLINE:
default:
Fail(fmt.Sprintf("Unknown volume expansion mode: %v\n", cap.GetVolumeExpansion().GetType()))
}
default:
Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetService().GetType()))
Fail(fmt.Sprintf("Unknown capability: %v\n", cap.GetType()))
}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/sanity/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ func isPluginCapabilitySupported(c csi.IdentityClient,
Expect(caps.GetCapabilities()).NotTo(BeNil())

for _, cap := range caps.GetCapabilities() {
Expect(cap.GetService()).NotTo(BeNil())
if cap.GetService().GetType() == capType {
if cap.GetService() != nil && cap.GetService().GetType() == capType {
return true
}
}
Expand Down

0 comments on commit 4087ca9

Please sign in to comment.