Skip to content

Commit 3aa7b32

Browse files
authored
cinder-csi-plugin: Tweak behavior of --with-topology flag (#2998)
This is currently backwards from what you'd expect when the value is false, 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 - regardless of the value of --with-topology - and ensure that we never set topology requirements on the CSI Volume when --with-topology=false. Signed-off-by: Stephen Finucane <[email protected]>
1 parent a401807 commit 3aa7b32

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

pkg/csi/cinder/controllerserver.go

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

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

@@ -250,7 +248,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
250248

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

253-
accessibleTopology := getTopology(vol, accessibleTopologyReq, ignoreVolumeAZ)
251+
accessibleTopology := getTopology(vol, accessibleTopologyReq, cs.Driver.withTopology, ignoreVolumeAZ)
254252

255253
return getCreateVolumeResponse(vol, volCtx, accessibleTopology), nil
256254
}
@@ -1040,8 +1038,12 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
10401038
}, nil
10411039
}
10421040

1043-
func getTopology(vol *volumes.Volume, topologyReq *csi.TopologyRequirement, ignoreVolumeAZ bool) []*csi.Topology {
1041+
func getTopology(vol *volumes.Volume, topologyReq *csi.TopologyRequirement, withTopology bool, ignoreVolumeAZ bool) []*csi.Topology {
10441042
var accessibleTopology []*csi.Topology
1043+
if !withTopology {
1044+
return accessibleTopology
1045+
}
1046+
10451047
if ignoreVolumeAZ {
10461048
if topologyReq != nil {
10471049
accessibleTopology = topologyReq.GetPreferred()

pkg/csi/cinder/controllerserver_test.go

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

267267
tests := []struct {
268-
name string
269-
volumeParams map[string]string
270-
expectedVolumeAZ string
271-
expectedCSITopology string
268+
name string
269+
volumeParams map[string]string
270+
expectedVolumeAZ string
272271
}{
273272
{
274273
name: "empty paramters",
275274
volumeParams: nil,
276275
expectedVolumeAZ: "",
277-
// FIXME(stephenfin): This should be unset
278-
expectedCSITopology: "nova",
279276
},
280277
{
281278
name: "availability parameter",
282279
volumeParams: map[string]string{
283280
"availability": "cinder",
284281
},
285-
// FIXME(stephenfin): This should be "cinder" per the parameter
286-
expectedVolumeAZ: "",
287-
// ...and this should be unset
288-
expectedCSITopology: "nova",
282+
expectedVolumeAZ: "cinder",
289283
},
290284
}
291285
for _, tt := range tests {
@@ -324,12 +318,8 @@ func TestCreateVolumeWithTopologyDisabled(t *testing.T) {
324318
assert.NotNil(actualRes.Volume)
325319
assert.NotNil(actualRes.Volume.CapacityBytes)
326320
assert.NotEqual(0, len(actualRes.Volume.VolumeId), "Volume Id is nil")
327-
if tt.expectedCSITopology == "" {
328-
assert.Nil(actualRes.Volume.AccessibleTopology)
329-
} else {
330-
assert.GreaterOrEqual(len(actualRes.Volume.AccessibleTopology), 1)
331-
assert.Equal(tt.expectedCSITopology, actualRes.Volume.AccessibleTopology[0].GetSegments()[topologyKey])
332-
}
321+
// This should always be nil if --with-topology=false
322+
assert.Nil(actualRes.Volume.AccessibleTopology)
333323
})
334324
}
335325
}

0 commit comments

Comments
 (0)