Skip to content

Commit

Permalink
[cinder-csi-plugin] support ignore-volume-az
Browse files Browse the repository at this point in the history
  • Loading branch information
ramineni committed Nov 5, 2020
1 parent e4326dd commit 4575be7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
2 changes: 2 additions & 0 deletions docs/cinder-csi-plugin/using-cinder-csi-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ These configuration options pertain to block storage and should appear in the `[
Optional. To configure maximum volumes that can be attached to the node. Its default value is `256`.
* `rescan-on-resize`
Optional. Set to `true`, to rescan block device and verify its size before expanding the filesystem. Not all hypervizors have a /sys/class/block/XXX/device/rescan location, therefore if you enable this option and your hypervizor doesn't support this, you'll get a warning log on resize event. It is recommended to disable this option in this case. Defaults to `false`
* `ignore-volume-az`
Optional. Set to `true`, incase volume AZ is different from node AZ and to avoid populating accessible topologies to volume AZ.

### Metadata
These configuration options pertain to metadata and should appear in the `[Metadata]` section of the `$CLOUD_CONFIG` file.
Expand Down
48 changes: 31 additions & 17 deletions pkg/csi/cinder/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,20 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
volType := req.GetParameters()["type"]

var volAvailability string
if req.GetAccessibilityRequirements() != nil {
volAvailability = getAZFromTopology(req.GetAccessibilityRequirements())
}

// First check if volAvailability is already specified, if not get preferred from Topology
// Required, incase vol AZ is different from node AZ
volAvailability = req.GetParameters()["availability"]

if len(volAvailability) == 0 {
// Volume Availability - Default is nova
volAvailability = req.GetParameters()["availability"]
// Check from Topology
if req.GetAccessibilityRequirements() != nil {
volAvailability = getAZFromTopology(req.GetAccessibilityRequirements())
}
}

cloud := cs.Cloud
ignoreVolumeAZ := cloud.GetBlockStorageOpts().IgnoreVolumeAZ

// Verify a volume with the provided name doesn't already exist for this tenant
volumes, err := cloud.GetVolumesByName(volName)
Expand All @@ -87,9 +91,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
if volSizeGB != volumes[0].Size {
return nil, status.Error(codes.AlreadyExists, "Volume Already exists with same name and different capacity")
}

klog.V(4).Infof("Volume %s already exists in Availability Zone: %s of size %d GiB", volumes[0].ID, volumes[0].AvailabilityZone, volumes[0].Size)
return getCreateVolumeResponse(&volumes[0]), nil
return getCreateVolumeResponse(&volumes[0], ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil
} else if len(volumes) > 1 {
klog.V(3).Infof("found multiple existing volumes with selected name (%s) during create", volName)
return nil, status.Error(codes.Internal, "Multiple volumes reported by Cinder with same name")
Expand Down Expand Up @@ -134,7 +137,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol

klog.V(4).Infof("CreateVolume: Successfully created volume %s in Availability Zone: %s of size %d GiB", vol.ID, vol.AvailabilityZone, vol.Size)

return getCreateVolumeResponse(vol), nil
return getCreateVolumeResponse(vol, ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil
}

func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
Expand Down Expand Up @@ -594,7 +597,7 @@ func getAZFromTopology(requirement *csi.TopologyRequirement) string {
return ""
}

func getCreateVolumeResponse(vol *volumes.Volume) *csi.CreateVolumeResponse {
func getCreateVolumeResponse(vol *volumes.Volume, ignoreVolumeAZ bool, accessibleTopologyReq *csi.TopologyRequirement) *csi.CreateVolumeResponse {

var volsrc *csi.VolumeContentSource

Expand All @@ -618,16 +621,27 @@ func getCreateVolumeResponse(vol *volumes.Volume) *csi.CreateVolumeResponse {
}
}

var accessibleTopology []*csi.Topology
// If ignore-volume-az is true , dont set the accessible topology to volume az,
// use from preferred topologies instead.
if ignoreVolumeAZ {
if accessibleTopologyReq != nil {
accessibleTopology = accessibleTopologyReq.GetPreferred()
}
} else {
accessibleTopology = []*csi.Topology{
{
Segments: map[string]string{topologyKey: vol.AvailabilityZone},
},
}
}

resp := &csi.CreateVolumeResponse{
Volume: &csi.Volume{
VolumeId: vol.ID,
CapacityBytes: int64(vol.Size * 1024 * 1024 * 1024),
AccessibleTopology: []*csi.Topology{
{
Segments: map[string]string{topologyKey: vol.AvailabilityZone},
},
},
ContentSource: volsrc,
VolumeId: vol.ID,
CapacityBytes: int64(vol.Size * 1024 * 1024 * 1024),
AccessibleTopology: accessibleTopology,
ContentSource: volsrc,
},
}

Expand Down
1 change: 1 addition & 0 deletions pkg/csi/cinder/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type OpenStack struct {
type BlockStorageOpts struct {
NodeVolumeAttachLimit int64 `gcfg:"node-volume-attach-limit"`
RescanOnResize bool `gcfg:"rescan-on-resize"`
IgnoreVolumeAZ bool `gcfg:"ignore-volume-az"`
}

type Config struct {
Expand Down

0 comments on commit 4575be7

Please sign in to comment.