Skip to content

Commit 1ba7175

Browse files
committed
cinder-csi-plugin: Tweak behavior of --with-topology flag
This is currently backwards from what you'd expect, with the topology information always being ignored for the Cinder requests but never ignored for the k8s CSI requests. Modify the former so that we respect the 'availability' parameter when set, and correct the latter so that we never set topology requirements on the CSI Volume. Signed-off-by: Stephen Finucane <[email protected]>
1 parent b0dbe91 commit 1ba7175

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

pkg/csi/cinder/controllerserver.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
9393
// First check if volAvailability is already specified, if not get preferred from Topology
9494
// Required, in case vol AZ is different from node AZ
9595
var volAvailability string
96-
if cs.Driver.withTopology {
97-
if volParams["availability"] != "" {
98-
volAvailability = volParams["availability"]
99-
} else if accessibleTopologyReq != nil {
100-
volAvailability = sharedcsi.GetAZFromTopology(topologyKey, accessibleTopologyReq)
101-
}
96+
if volParams["availability"] != "" {
97+
volAvailability = volParams["availability"]
98+
} else if cs.Driver.withTopology && accessibleTopologyReq != nil {
99+
volAvailability = sharedcsi.GetAZFromTopology(topologyKey, accessibleTopologyReq)
102100
}
103101

104102
// get the PVC annotation
@@ -119,7 +117,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
119117
return nil, status.Error(codes.AlreadyExists, "Volume Already exists with same name and different capacity")
120118
}
121119
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-
accessibleTopology := getTopology(&vols[0], accessibleTopologyReq, ignoreVolumeAZ)
120+
accessibleTopology := getTopology(&vols[0], accessibleTopologyReq, cs.Driver.withTopology, ignoreVolumeAZ)
123121
return getCreateVolumeResponse(&vols[0], nil, accessibleTopology), nil
124122
}
125123

@@ -246,7 +244,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
246244

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

249-
accessibleTopology := getTopology(vol, accessibleTopologyReq, ignoreVolumeAZ)
247+
accessibleTopology := getTopology(vol, accessibleTopologyReq, cs.Driver.withTopology, ignoreVolumeAZ)
250248

251249
return getCreateVolumeResponse(vol, volCtx, accessibleTopology), nil
252250
}
@@ -1038,18 +1036,20 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
10381036
}, nil
10391037
}
10401038

1041-
func getTopology(vol *volumes.Volume, topologyReq *csi.TopologyRequirement, ignoreVolumeAZ bool) []*csi.Topology {
1039+
func getTopology(vol *volumes.Volume, topologyReq *csi.TopologyRequirement, withTopology bool, ignoreVolumeAZ bool) []*csi.Topology {
10421040
var accessibleTopology []*csi.Topology
1043-
if ignoreVolumeAZ {
1044-
if topologyReq != nil {
1045-
accessibleTopology = topologyReq.GetPreferred()
1046-
}
1047-
} else {
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}},
1041+
if withTopology {
1042+
if ignoreVolumeAZ {
1043+
if topologyReq != nil {
1044+
accessibleTopology = topologyReq.GetPreferred()
1045+
}
1046+
} else {
1047+
// NOTE(stephenfin): We retrieve the AZ from the created volume rather than
1048+
// using the value we provided in our request since these can differ due to
1049+
// Cinder's '[DEFAULT] allow_availability_zone_fallback' option.
1050+
accessibleTopology = []*csi.Topology{
1051+
{Segments: map[string]string{topologyKey: vol.AvailabilityZone}},
1052+
}
10531053
}
10541054
}
10551055
return accessibleTopology

pkg/csi/cinder/controllerserver_test.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -213,27 +213,21 @@ func TestCreateVolumeWithTopologyDisabled(t *testing.T) {
213213
assert := assert.New(t)
214214

215215
tests := []struct {
216-
name string
217-
volumeParams map[string]string
218-
expectedVolumeAZ string
219-
expectedCSITopology string
216+
name string
217+
volumeParams map[string]string
218+
expectedVolumeAZ string
220219
}{
221220
{
222221
name: "empty paramters",
223222
volumeParams: nil,
224223
expectedVolumeAZ: "",
225-
// FIXME(stephenfin): This should be unset
226-
expectedCSITopology: "nova",
227224
},
228225
{
229226
name: "availability parameter",
230227
volumeParams: map[string]string{
231228
"availability": "cinder",
232229
},
233-
// FIXME(stephenfin): This should be "cinder" per the parameter
234-
expectedVolumeAZ: "",
235-
// ...and this should be unset
236-
expectedCSITopology: "nova",
230+
expectedVolumeAZ: "cinder",
237231
},
238232
}
239233
for _, tt := range tests {
@@ -272,12 +266,8 @@ func TestCreateVolumeWithTopologyDisabled(t *testing.T) {
272266
assert.NotNil(actualRes.Volume)
273267
assert.NotNil(actualRes.Volume.CapacityBytes)
274268
assert.NotEqual(0, len(actualRes.Volume.VolumeId), "Volume Id is nil")
275-
if tt.expectedCSITopology == "" {
276-
assert.Nil(actualRes.Volume.AccessibleTopology)
277-
} else {
278-
assert.NotNil(actualRes.Volume.AccessibleTopology)
279-
assert.Equal(tt.expectedCSITopology, actualRes.Volume.AccessibleTopology[0].GetSegments()[topologyKey])
280-
}
269+
// This should always be nil if --with-topology=false
270+
assert.Nil(actualRes.Volume.AccessibleTopology)
281271
})
282272
}
283273
}

0 commit comments

Comments
 (0)