Skip to content

Commit 03149e5

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 558663f commit 03149e5

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
@@ -86,22 +86,22 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
8686
// Volume Type
8787
volType := volParams["type"]
8888

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

103-
ignoreVolumeAZ := cloud.GetBlockStorageOpts().IgnoreVolumeAZ
104-
105105
// get the PVC annotation
106106
pvcAnnotations := sharedcsi.GetPVCAnnotations(cs.Driver.pvcLister, volParams)
107107
for k, v := range pvcAnnotations {
@@ -120,8 +120,11 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
120120
return nil, status.Error(codes.AlreadyExists, "Volume Already exists with same name and different capacity")
121121
}
122122
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)
123-
return getCreateVolumeResponse(&vols[0], nil, ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil
124-
} else if len(vols) > 1 {
123+
accessibleTopology := getTopology(&vols[0], accessibleTopologyReq, ignoreVolumeAZ)
124+
return getCreateVolumeResponse(&vols[0], nil, accessibleTopology), nil
125+
}
126+
127+
if len(vols) > 1 {
125128
klog.V(3).Infof("found multiple existing volumes with selected name (%s) during create", volName)
126129
return nil, status.Error(codes.Internal, "Multiple volumes reported by Cinder with same name")
127130
}
@@ -247,7 +250,9 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
247250

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

250-
return getCreateVolumeResponse(vol, volCtx, ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil
253+
accessibleTopology := getTopology(vol, accessibleTopologyReq, ignoreVolumeAZ)
254+
255+
return getCreateVolumeResponse(vol, volCtx, accessibleTopology), nil
251256
}
252257

253258
func (d *controllerServer) ControllerModifyVolume(ctx context.Context, req *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error) {
@@ -1035,7 +1040,24 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
10351040
}, nil
10361041
}
10371042

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

@@ -1075,21 +1097,6 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, igno
10751097
}
10761098
}
10771099

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

0 commit comments

Comments
 (0)