Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pkg/csi/cinder/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,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)
Expand All @@ -221,6 +221,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{
Expand Down Expand Up @@ -1036,13 +1037,12 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
}

func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, ignoreVolumeAZ bool, accessibleTopologyReq *csi.TopologyRequirement) *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,
Expand All @@ -1052,9 +1052,9 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, igno
}

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,
Expand All @@ -1064,9 +1064,9 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, igno
}

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,
Expand Down Expand Up @@ -1095,8 +1095,8 @@ func getCreateVolumeResponse(vol *volumes.Volume, volCtx map[string]string, igno
VolumeId: vol.ID,
CapacityBytes: int64(vol.Size * 1024 * 1024 * 1024),
AccessibleTopology: accessibleTopology,
ContentSource: volsrc,
VolumeContext: volCnx,
ContentSource: volSrc,
VolumeContext: volCtx,
},
}

Expand Down