Skip to content

Commit 9c52213

Browse files
authored
[cinder-csi-plugin] Use context (#2864)
* cinder-csi-plugin: Use generated VolumeContext Looks like an oversight in commit 7bfb2eb. Signed-off-by: Stephen Finucane <[email protected]> * trivial: Explain overloaded context term This confused me. It might confuse others. Signed-off-by: Stephen Finucane <[email protected]> * trivial: camelCase variable name Signed-off-by: Stephen Finucane <[email protected]> * cinder-csi-plugin: Handle potentially unset volCtx arg Signed-off-by: Stephen Finucane <[email protected]> --------- Signed-off-by: Stephen Finucane <[email protected]>
1 parent db35cbd commit 9c52213

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

pkg/csi/cinder/controllerserver.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
206206

207207
// Set scheduler hints if affinity or anti-affinity is set in PVC annotations
208208
var schedulerHints volumes.SchedulerHintOptsBuilder
209-
var volCtx map[string]string
209+
volCtx := map[string]string{}
210210
affinity := pvcAnnotations[affinityKey]
211211
antiAffinity := pvcAnnotations[antiAffinityKey]
212212
if affinity != "" || antiAffinity != "" {
213213
klog.V(4).Infof("CreateVolume: Getting scheduler hints: affinity=%s, anti-affinity=%s", affinity, antiAffinity)
214214

215-
// resolve volume names to UUIDs
215+
// Resolve volume names to UUIDs
216216
affinity, err = cloud.ResolveVolumeListToUUIDs(ctx, affinity)
217217
if err != nil {
218218
return nil, status.Errorf(codes.InvalidArgument, "failed to resolve affinity volume UUIDs: %v", err)
@@ -222,6 +222,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
222222
return nil, status.Errorf(codes.InvalidArgument, "failed to resolve anti-affinity volume UUIDs: %v", err)
223223
}
224224

225+
// Note that this is context for the k8s CSI volume, not the Cinder volume
225226
volCtx = util.SetMapIfNotEmpty(volCtx, "affinity", affinity)
226227
volCtx = util.SetMapIfNotEmpty(volCtx, "anti-affinity", antiAffinity)
227228
schedulerHints = &volumes.SchedulerHintOpts{
@@ -1060,13 +1061,16 @@ func getTopology(vol *volumes.Volume, topologyReq *csi.TopologyRequirement, with
10601061
}
10611062

10621063
func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, accessibleTopology []*csi.Topology) *csi.CreateVolumeResponse {
1063-
var volsrc *csi.VolumeContentSource
1064-
volCnx := map[string]string{}
1064+
var volSrc *csi.VolumeContentSource
1065+
1066+
if volCtx == nil {
1067+
volCtx = map[string]string{}
1068+
}
10651069

10661070
if vol.SnapshotID != "" {
1067-
volCnx[ResizeRequired] = "true"
1071+
volCtx[ResizeRequired] = "true"
10681072

1069-
volsrc = &csi.VolumeContentSource{
1073+
volSrc = &csi.VolumeContentSource{
10701074
Type: &csi.VolumeContentSource_Snapshot{
10711075
Snapshot: &csi.VolumeContentSource_SnapshotSource{
10721076
SnapshotId: vol.SnapshotID,
@@ -1076,9 +1080,9 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, acce
10761080
}
10771081

10781082
if vol.SourceVolID != "" {
1079-
volCnx[ResizeRequired] = "true"
1083+
volCtx[ResizeRequired] = "true"
10801084

1081-
volsrc = &csi.VolumeContentSource{
1085+
volSrc = &csi.VolumeContentSource{
10821086
Type: &csi.VolumeContentSource_Volume{
10831087
Volume: &csi.VolumeContentSource_VolumeSource{
10841088
VolumeId: vol.SourceVolID,
@@ -1088,9 +1092,9 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, acce
10881092
}
10891093

10901094
if vol.BackupID != nil && *vol.BackupID != "" {
1091-
volCnx[ResizeRequired] = "true"
1095+
volCtx[ResizeRequired] = "true"
10921096

1093-
volsrc = &csi.VolumeContentSource{
1097+
volSrc = &csi.VolumeContentSource{
10941098
Type: &csi.VolumeContentSource_Snapshot{
10951099
Snapshot: &csi.VolumeContentSource_SnapshotSource{
10961100
SnapshotId: *vol.BackupID,
@@ -1104,8 +1108,8 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, acce
11041108
VolumeId: vol.ID,
11051109
CapacityBytes: int64(vol.Size * 1024 * 1024 * 1024),
11061110
AccessibleTopology: accessibleTopology,
1107-
ContentSource: volsrc,
1108-
VolumeContext: volCnx,
1111+
ContentSource: volSrc,
1112+
VolumeContext: volCtx,
11091113
},
11101114
}
11111115

0 commit comments

Comments
 (0)