diff --git a/pkg/csi/cinder/controllerserver.go b/pkg/csi/cinder/controllerserver.go index 045cb7bcec..e01e2d31c2 100644 --- a/pkg/csi/cinder/controllerserver.go +++ b/pkg/csi/cinder/controllerserver.go @@ -208,13 +208,13 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol // Set scheduler hints if affinity or anti-affinity is set in PVC annotations var schedulerHints volumes.SchedulerHintOptsBuilder - var volCtx map[string]string + volCtx := map[string]string{} affinity := pvcAnnotations[affinityKey] antiAffinity := pvcAnnotations[antiAffinityKey] if affinity != "" || antiAffinity != "" { klog.V(4).Infof("CreateVolume: Getting scheduler hints: affinity=%s, anti-affinity=%s", affinity, antiAffinity) - // resolve volume names to UUIDs + // Resolve volume names to UUIDs affinity, err = cloud.ResolveVolumeListToUUIDs(ctx, affinity) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "failed to resolve affinity volume UUIDs: %v", err) @@ -224,6 +224,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol return nil, status.Errorf(codes.InvalidArgument, "failed to resolve anti-affinity volume UUIDs: %v", err) } + // Note that this is context for the k8s CSI volume, not the Cinder volume volCtx = util.SetMapIfNotEmpty(volCtx, "affinity", affinity) volCtx = util.SetMapIfNotEmpty(volCtx, "anti-affinity", antiAffinity) schedulerHints = &volumes.SchedulerHintOpts{ @@ -1058,13 +1059,12 @@ func getTopology(vol *volumes.Volume, topologyReq *csi.TopologyRequirement, igno } func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, accessibleTopology []*csi.Topology) *csi.CreateVolumeResponse { - var volsrc *csi.VolumeContentSource - volCnx := map[string]string{} + var volSrc *csi.VolumeContentSource if vol.SnapshotID != "" { - volCnx[ResizeRequired] = "true" + volCtx[ResizeRequired] = "true" - volsrc = &csi.VolumeContentSource{ + volSrc = &csi.VolumeContentSource{ Type: &csi.VolumeContentSource_Snapshot{ Snapshot: &csi.VolumeContentSource_SnapshotSource{ SnapshotId: vol.SnapshotID, @@ -1074,9 +1074,9 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, acce } if vol.SourceVolID != "" { - volCnx[ResizeRequired] = "true" + volCtx[ResizeRequired] = "true" - volsrc = &csi.VolumeContentSource{ + volSrc = &csi.VolumeContentSource{ Type: &csi.VolumeContentSource_Volume{ Volume: &csi.VolumeContentSource_VolumeSource{ VolumeId: vol.SourceVolID, @@ -1086,9 +1086,9 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, acce } if vol.BackupID != nil && *vol.BackupID != "" { - volCnx[ResizeRequired] = "true" + volCtx[ResizeRequired] = "true" - volsrc = &csi.VolumeContentSource{ + volSrc = &csi.VolumeContentSource{ Type: &csi.VolumeContentSource_Snapshot{ Snapshot: &csi.VolumeContentSource_SnapshotSource{ SnapshotId: *vol.BackupID, @@ -1102,8 +1102,8 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, acce VolumeId: vol.ID, CapacityBytes: int64(vol.Size * 1024 * 1024 * 1024), AccessibleTopology: accessibleTopology, - ContentSource: volsrc, - VolumeContext: volCnx, + ContentSource: volSrc, + VolumeContext: volCtx, }, }