Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#171 from jarrpa/expand-cli
Browse files Browse the repository at this point in the history
 Add volume expansion online/offline toggle to mock driver
  • Loading branch information
k8s-ci-robot authored Mar 5, 2019
2 parents 58669a9 + 2072242 commit 48b8eaa
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 293 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
578 changes: 293 additions & 285 deletions vendor/github.com/container-storage-interface/spec/lib/go/csi/csi.pb.go

Large diffs are not rendered by default.

0 comments on commit 48b8eaa

Please sign in to comment.