Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cinder-csi-plugin] support ignore-volume-az #1307

Merged
merged 2 commits into from
Nov 19, 2020
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
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. When `Topology` feature enabled, by default, PV volume node affinity is populated with volume accessible topology, which is volume AZ. But, some of the openstack users do not have compute zones named exactly the same as volume zones. This might cause pods to go in pending state as no nodes available in volume AZ. Enabling `ignore-volume-az=true`, ignores volumeAZ and schedules on any of the available node AZ. Default `false`.

### 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