Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbd: remove topologyConstrainedPools parameter #4499

Merged
Merged
Show file tree
Hide file tree
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
64 changes: 27 additions & 37 deletions internal/cephfs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,31 @@ func checkValidCreateVolumeRequest(
return nil
}

func buildCreateVolumeResponse(
req *csi.CreateVolumeRequest,
volOptions *store.VolumeOptions,
vID *store.VolumeIdentifier,
) *csi.CreateVolumeResponse {
volumeContext := util.GetVolumeContext(req.GetParameters())
volumeContext["subvolumeName"] = vID.FsSubvolName
volumeContext["subvolumePath"] = volOptions.RootPath
volume := &csi.Volume{
VolumeId: vID.VolumeID,
CapacityBytes: volOptions.Size,
ContentSource: req.GetVolumeContentSource(),
VolumeContext: volumeContext,
}
if volOptions.Topology != nil {
volume.AccessibleTopology = []*csi.Topology{
{
Segments: volOptions.Topology,
},
}
}

return &csi.CreateVolumeResponse{Volume: volume}
}

// CreateVolume creates a reservation and the volume in backend, if it is not already present.
//
//nolint:gocognit,gocyclo,nestif,cyclop // TODO: reduce complexity
Expand Down Expand Up @@ -376,25 +401,7 @@ func (cs *ControllerServer) CreateVolume(
}
}

// remove kubernetes csi prefixed parameters.
volumeContext := k8s.RemoveCSIPrefixedParameters(req.GetParameters())
volumeContext["subvolumeName"] = vID.FsSubvolName
volumeContext["subvolumePath"] = volOptions.RootPath
volume := &csi.Volume{
VolumeId: vID.VolumeID,
CapacityBytes: volOptions.Size,
ContentSource: req.GetVolumeContentSource(),
VolumeContext: volumeContext,
}
if volOptions.Topology != nil {
volume.AccessibleTopology = []*csi.Topology{
{
Segments: volOptions.Topology,
},
}
}

return &csi.CreateVolumeResponse{Volume: volume}, nil
return buildCreateVolumeResponse(req, volOptions, vID), nil
}

// Reservation
Expand Down Expand Up @@ -467,25 +474,8 @@ func (cs *ControllerServer) CreateVolume(

log.DebugLog(ctx, "cephfs: successfully created backing volume named %s for request name %s",
vID.FsSubvolName, requestName)
// remove kubernetes csi prefixed parameters.
volumeContext := k8s.RemoveCSIPrefixedParameters(req.GetParameters())
volumeContext["subvolumeName"] = vID.FsSubvolName
volumeContext["subvolumePath"] = volOptions.RootPath
volume := &csi.Volume{
VolumeId: vID.VolumeID,
CapacityBytes: volOptions.Size,
ContentSource: req.GetVolumeContentSource(),
VolumeContext: volumeContext,
}
if volOptions.Topology != nil {
volume.AccessibleTopology = []*csi.Topology{
{
Segments: volOptions.Topology,
},
}
}

return &csi.CreateVolumeResponse{Volume: volume}, nil
return buildCreateVolumeResponse(req, volOptions, vID), nil
}

// DeleteVolume deletes the volume in backend and its reservation.
Expand Down
3 changes: 1 addition & 2 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ func (cs *ControllerServer) parseVolCreateRequest(
}

func buildCreateVolumeResponse(req *csi.CreateVolumeRequest, rbdVol *rbdVolume) *csi.CreateVolumeResponse {
// remove kubernetes csi prefixed parameters.
volumeContext := k8s.RemoveCSIPrefixedParameters(req.GetParameters())
volumeContext := util.GetVolumeContext(req.GetParameters())
volumeContext["pool"] = rbdVol.Pool
volumeContext["journalPool"] = rbdVol.JournalPool
volumeContext["imageName"] = rbdVol.RbdImageName
Expand Down
4 changes: 2 additions & 2 deletions internal/rbd/rbd_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"os"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -353,7 +354,6 @@ func attachRBDImage(ctx context.Context, volOptions *rbdVolume, device string, c
}

err = waitForrbdImage(ctx, backoff, volOptions)

if err != nil {
return "", err
}
Expand All @@ -364,7 +364,7 @@ func attachRBDImage(ctx context.Context, volOptions *rbdVolume, device string, c
}

func appendNbdDeviceTypeAndOptions(cmdArgs []string, userOptions, cookie string) []string {
isUnmap := CheckSliceContains(cmdArgs, "unmap")
isUnmap := slices.Contains(cmdArgs, "unmap")
if !isUnmap {
if !strings.Contains(userOptions, useNbdNetlink) {
cmdArgs = append(cmdArgs, "--"+useNbdNetlink)
Expand Down
11 changes: 0 additions & 11 deletions internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2071,17 +2071,6 @@ func getCephClientLogFileName(id, logDir, prefix string) string {
return fmt.Sprintf("%s/%s-%s.log", logDir, prefix, id)
}

// CheckSliceContains checks the slice for string.
func CheckSliceContains(options []string, opt string) bool {
for _, o := range options {
if o == opt {
return true
}
}

return false
}

// strategicActionOnLogFile act on log file based on cephLogStrategy.
func strategicActionOnLogFile(ctx context.Context, logStrategy, logFile string) {
var err error
Expand Down
5 changes: 4 additions & 1 deletion internal/util/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
const (
keySeparator rune = '/'
labelSeparator string = ","

// topologyPoolsParam is the parameter name used to pass topology constrained pools.
topologyPoolsParam = "topologyConstrainedPools"
)

// GetTopologyFromDomainLabels returns the CSI topology map, determined from
Expand Down Expand Up @@ -129,7 +132,7 @@ func GetTopologyFromRequest(
var topologyPools []TopologyConstrainedPool

// check if parameters have pool configuration pertaining to topology
topologyPoolsStr := req.GetParameters()["topologyConstrainedPools"]
topologyPoolsStr := req.GetParameters()[topologyPoolsParam]
if topologyPoolsStr == "" {
return nil, nil, nil
}
Expand Down
21 changes: 21 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strings"
"time"

"github.com/ceph/ceph-csi/internal/util/k8s"
"github.com/ceph/ceph-csi/internal/util/log"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -381,3 +382,23 @@ func CallStack() string {

return string(stack)
}

// GetVolumeContext filters out parameters that are not required in volume context.
func GetVolumeContext(parameters map[string]string) map[string]string {
volumeContext := map[string]string{}

// parameters that are not required in the volume context
notRequiredParams := []string{
topologyPoolsParam,
}
for k, v := range parameters {
if !slices.Contains(notRequiredParams, k) {
volumeContext[k] = v
}
}

// remove kubernetes csi prefixed parameters.
volumeContext = k8s.RemoveCSIPrefixedParameters(volumeContext)

return volumeContext
}