@@ -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
10621063func 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