Skip to content

Commit 9bc4857

Browse files
committed
cinder-csi-plugin: Group topology generation
Group everything together rather than having it spread out as it is currently. A decoder of the logic, to ensure nothing has changed: 1. Determine what the OpenStack Cinder volume's AZ will be: a. If the `availability` parameter is set on the Storage Class, the cinder volume will use this as the AZ. b. Otherwise, the cinder volume will use: an AZ extracted from one of the preferred CSI Topologies; an AZ extracted from one of the requisite (available) Topologies; or no AZ. 2. Determine what the Kubernetes CSI Volume's topology will be: a. If the `ignore-volume-az` option is set, the CSI Volume will use the preferred CSI Volume Topologies, if any, else None. [*] b. Otherwise, the CSI Volume will generate a Volume Topology from the Cinder Volume's AZ. [*] This practically means that `ignore-volume-az` is only useful when the availability parameter is set on the Storage Class. This in turn means the CSI Volume Topology is junk as it has no bearing on the "real" topology constraint on the volume. Signed-off-by: Stephen Finucane <[email protected]>
1 parent 1564735 commit 9bc4857

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

pkg/csi/cinder/controllerserver.go

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,22 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
8585
// Volume Type
8686
volType := volParams["type"]
8787

88+
// Volume AZ
89+
90+
accessibleTopologyReq := req.GetAccessibilityRequirements()
91+
ignoreVolumeAZ := cloud.GetBlockStorageOpts().IgnoreVolumeAZ
92+
93+
// First check if volAvailability is already specified, if not get preferred from Topology
94+
// Required, in case vol AZ is different from node AZ
8895
var volAvailability string
8996
if cs.Driver.withTopology {
90-
// First check if volAvailability is already specified, if not get preferred from Topology
91-
// Required, incase vol AZ is different from node AZ
92-
volAvailability = volParams["availability"]
93-
if volAvailability == "" {
94-
accessibleTopologyReq := req.GetAccessibilityRequirements()
95-
// Check from Topology
96-
if accessibleTopologyReq != nil {
97-
volAvailability = sharedcsi.GetAZFromTopology(topologyKey, accessibleTopologyReq)
98-
}
97+
if volParams["availability"] != "" {
98+
volAvailability = volParams["availability"]
99+
} else if accessibleTopologyReq != nil {
100+
volAvailability = sharedcsi.GetAZFromTopology(topologyKey, accessibleTopologyReq)
99101
}
100102
}
101103

102-
ignoreVolumeAZ := cloud.GetBlockStorageOpts().IgnoreVolumeAZ
103-
104104
// get the PVC annotation
105105
pvcAnnotations := sharedcsi.GetPVCAnnotations(cs.Driver.pvcLister, volParams)
106106
for k, v := range pvcAnnotations {
@@ -119,8 +119,11 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
119119
return nil, status.Error(codes.AlreadyExists, "Volume Already exists with same name and different capacity")
120120
}
121121
klog.V(4).Infof("Volume %s already exists in Availability Zone: %s of size %d GiB", vols[0].ID, vols[0].AvailabilityZone, vols[0].Size)
122-
return getCreateVolumeResponse(&vols[0], nil, ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil
123-
} else if len(vols) > 1 {
122+
accessibleTopology := getTopology(&vols[0], accessibleTopologyReq, ignoreVolumeAZ)
123+
return getCreateVolumeResponse(&vols[0], nil, accessibleTopology), nil
124+
}
125+
126+
if len(vols) > 1 {
124127
klog.V(3).Infof("found multiple existing volumes with selected name (%s) during create", volName)
125128
return nil, status.Error(codes.Internal, "Multiple volumes reported by Cinder with same name")
126129
}
@@ -243,7 +246,9 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
243246

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

246-
return getCreateVolumeResponse(vol, volCtx, ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil
249+
accessibleTopology := getTopology(vol, accessibleTopologyReq, ignoreVolumeAZ)
250+
251+
return getCreateVolumeResponse(vol, volCtx, accessibleTopology), nil
247252
}
248253

249254
func (d *controllerServer) ControllerModifyVolume(ctx context.Context, req *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error) {
@@ -1033,7 +1038,24 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
10331038
}, nil
10341039
}
10351040

1036-
func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, ignoreVolumeAZ bool, accessibleTopologyReq *csi.TopologyRequirement) *csi.CreateVolumeResponse {
1041+
func getTopology(vol *volumes.Volume, topologyReq *csi.TopologyRequirement, ignoreVolumeAZ bool) []*csi.Topology {
1042+
var accessibleTopology []*csi.Topology
1043+
if ignoreVolumeAZ {
1044+
if topologyReq != nil {
1045+
accessibleTopology = topologyReq.GetPreferred()
1046+
}
1047+
} else if vol.AvailabilityZone != "" {
1048+
// NOTE(stephenfin): We retrieve the AZ from the created volume rather than
1049+
// using the value we provided in our request since these can differ due to
1050+
// Cinder's '[DEFAULT] allow_availability_zone_fallback' option.
1051+
accessibleTopology = []*csi.Topology{
1052+
{Segments: map[string]string{topologyKey: vol.AvailabilityZone}},
1053+
}
1054+
}
1055+
return accessibleTopology
1056+
}
1057+
1058+
func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, accessibleTopology []*csi.Topology) *csi.CreateVolumeResponse {
10371059
var volsrc *csi.VolumeContentSource
10381060
volCnx := map[string]string{}
10391061

@@ -1073,21 +1095,6 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, igno
10731095
}
10741096
}
10751097

1076-
var accessibleTopology []*csi.Topology
1077-
// If ignore-volume-az is true , dont set the accessible topology to volume az,
1078-
// use from preferred topologies instead.
1079-
if ignoreVolumeAZ {
1080-
if accessibleTopologyReq != nil {
1081-
accessibleTopology = accessibleTopologyReq.GetPreferred()
1082-
}
1083-
} else if vol.AvailabilityZone != "" {
1084-
accessibleTopology = []*csi.Topology{
1085-
{
1086-
Segments: map[string]string{topologyKey: vol.AvailabilityZone},
1087-
},
1088-
}
1089-
}
1090-
10911098
resp := &csi.CreateVolumeResponse{
10921099
Volume: &csi.Volume{
10931100
VolumeId: vol.ID,

0 commit comments

Comments
 (0)