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 @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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 {
Copy link
Contributor

@kayrus kayrus Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to cover the cases, when the volCtx argument is nil, e.g.

return getCreateVolumeResponse(&vols[0], nil, accessibleTopology), nil

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 @@ -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,
Expand All @@ -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,
Expand All @@ -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,
},
}

Expand Down