Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/mock-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func main() {
flag.StringVar(&config.DriverName, "name", service.Name, "CSI driver name.")
flag.Int64Var(&config.AttachLimit, "attach-limit", 2, "number of attachable volumes on a node")
flag.BoolVar(&config.NodeExpansionRequired, "node-expand-required", false, "Enables NodeServiceCapability_RPC_EXPAND_VOLUME capacity.")
flag.BoolVar(&config.EnableTopology, "enable-topology", false, "Enables PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS capability.")
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.BoolVar(&config.PermissiveTargetPath, "permissive-target-path", false, "Allows the CO to create PublishVolumeRequest.TargetPath, which violates the CSI spec.")
Expand Down
37 changes: 25 additions & 12 deletions mock/service/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,35 @@ func (s *service) GetPluginCapabilities(
volExpType = csi.PluginCapability_VolumeExpansion_OFFLINE
}

return &csi.GetPluginCapabilitiesResponse{
Capabilities: []*csi.PluginCapability{
{
Type: &csi.PluginCapability_Service_{
Service: &csi.PluginCapability_Service{
Type: csi.PluginCapability_Service_CONTROLLER_SERVICE,
},
capabilities := []*csi.PluginCapability{
{
Type: &csi.PluginCapability_Service_{
Service: &csi.PluginCapability_Service{
Type: csi.PluginCapability_Service_CONTROLLER_SERVICE,
},
},
{
Type: &csi.PluginCapability_VolumeExpansion_{
VolumeExpansion: &csi.PluginCapability_VolumeExpansion{
Type: volExpType,
},
},
{
Type: &csi.PluginCapability_VolumeExpansion_{
VolumeExpansion: &csi.PluginCapability_VolumeExpansion{
Type: volExpType,
},
},
},
}

if s.config.EnableTopology {
capabilities = append(capabilities,
&csi.PluginCapability{
Type: &csi.PluginCapability_Service_{
Service: &csi.PluginCapability_Service{
Type: csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS,
},
},
})
}

return &csi.GetPluginCapabilitiesResponse{
Capabilities: capabilities,
}, nil
}
7 changes: 7 additions & 0 deletions mock/service/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ func (s *service) NodeGetInfo(ctx context.Context,
if s.config.AttachLimit > 0 {
csiNodeResponse.MaxVolumesPerNode = s.config.AttachLimit
}
if s.config.EnableTopology {
csiNodeResponse.AccessibleTopology = &csi.Topology{
Segments: map[string]string{
TopologyKey: TopologyValue,
},
}
}
return csiNodeResponse, nil
}

Expand Down
25 changes: 24 additions & 1 deletion mock/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const (

// VendorVersion is the version returned by GetPluginInfo.
VendorVersion = "0.3.0"

// TopologyKey simulates a per-node topology.
TopologyKey = Name + "/node"

// TopologyValue is the one, fixed node on which the driver runs.
TopologyValue = "some-mock-node"
)

// Manifest is the SP's manifest.
Expand Down Expand Up @@ -79,6 +85,7 @@ type Config struct {
DisableControllerExpansion bool
DisableOnlineExpansion bool
PermissiveTargetPath bool
EnableTopology bool
ExecHooks *Hooks
}

Expand Down Expand Up @@ -154,11 +161,13 @@ const (
)

func (s *service) newVolume(name string, capcity int64) csi.Volume {
return csi.Volume{
vol := csi.Volume{
VolumeId: fmt.Sprintf("%d", atomic.AddUint64(&s.volsNID, 1)),
VolumeContext: map[string]string{"name": name},
CapacityBytes: capcity,
}
s.setTopology(&vol)
return vol
}

func (s *service) newVolumeFromSnapshot(name string, capacity int64, snapshotID int) csi.Volume {
Expand All @@ -170,6 +179,7 @@ func (s *service) newVolumeFromSnapshot(name string, capacity int64, snapshotID
},
},
}
s.setTopology(&vol)
return vol
}

Expand All @@ -182,9 +192,22 @@ func (s *service) newVolumeFromVolume(name string, capacity int64, volumeID int)
},
},
}
s.setTopology(&vol)
return vol
}

func (s *service) setTopology(vol *csi.Volume) {
if s.config.EnableTopology {
vol.AccessibleTopology = []*csi.Topology{
&csi.Topology{
Segments: map[string]string{
TopologyKey: TopologyValue,
},
},
}
}
}

func (s *service) findVol(k, v string) (volIdx int, volInfo csi.Volume) {
s.volsRWL.RLock()
defer s.volsRWL.RUnlock()
Expand Down