Skip to content

Commit a5d3216

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 78de34d commit a5d3216

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

pkg/csi/cinder/controllerserver.go

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,30 @@ 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+
92+
// First check if volAvailability is already specified, if not get preferred from Topology
93+
// Required, in case vol AZ is different from node AZ
8894
var volAvailability string
89-
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
95+
if volParams["availability"] != "" {
9296
volAvailability = volParams["availability"]
93-
if volAvailability == "" {
94-
accessibleTopologyReq := req.GetAccessibilityRequirements()
95-
// Check from Topology
96-
if accessibleTopologyReq != nil {
97-
volAvailability = sharedcsi.GetAZFromTopology(topologyKey, accessibleTopologyReq)
97+
} else if accessibleTopologyReq != nil && cs.Driver.withTopology {
98+
volAvailability = sharedcsi.GetAZFromTopology(topologyKey, accessibleTopologyReq)
99+
}
100+
101+
var accessibleTopology []*csi.Topology
102+
if accessibleTopologyReq != nil && cs.Driver.withTopology {
103+
if cloud.GetBlockStorageOpts().IgnoreVolumeAZ {
104+
accessibleTopology = accessibleTopologyReq.GetPreferred()
105+
} else {
106+
accessibleTopology = []*csi.Topology{
107+
{Segments: map[string]string{topologyKey: volAvailability}},
98108
}
99109
}
100110
}
101111

102-
ignoreVolumeAZ := cloud.GetBlockStorageOpts().IgnoreVolumeAZ
103-
104112
// get the PVC annotation
105113
pvcAnnotations := sharedcsi.GetPVCAnnotations(cs.Driver.pvcLister, volParams)
106114
for k, v := range pvcAnnotations {
@@ -119,8 +127,10 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
119127
return nil, status.Error(codes.AlreadyExists, "Volume Already exists with same name and different capacity")
120128
}
121129
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 {
130+
return getCreateVolumeResponse(&vols[0], nil, accessibleTopology), nil
131+
}
132+
133+
if len(vols) > 1 {
124134
klog.V(3).Infof("found multiple existing volumes with selected name (%s) during create", volName)
125135
return nil, status.Error(codes.Internal, "Multiple volumes reported by Cinder with same name")
126136
}
@@ -243,7 +253,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
243253

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

246-
return getCreateVolumeResponse(vol, volCtx, ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil
256+
return getCreateVolumeResponse(vol, volCtx, accessibleTopology), nil
247257
}
248258

249259
func (d *controllerServer) ControllerModifyVolume(ctx context.Context, req *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error) {
@@ -1033,7 +1043,7 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
10331043
}, nil
10341044
}
10351045

1036-
func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, ignoreVolumeAZ bool, accessibleTopologyReq *csi.TopologyRequirement) *csi.CreateVolumeResponse {
1046+
func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, accessibleTopology []*csi.Topology) *csi.CreateVolumeResponse {
10371047
var volsrc *csi.VolumeContentSource
10381048
volCnx := map[string]string{}
10391049

@@ -1073,21 +1083,6 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, igno
10731083
}
10741084
}
10751085

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-
10911086
resp := &csi.CreateVolumeResponse{
10921087
Volume: &csi.Volume{
10931088
VolumeId: vol.ID,

0 commit comments

Comments
 (0)