Merge pull request #289 from red-hat-storage/sync_us--devel

Syncing latest changes from upstream devel for ceph-csi
This commit is contained in:
openshift-merge-bot[bot] 2024-04-08 10:27:42 +00:00 committed by GitHub
commit 87d707adda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 59 additions and 57 deletions

View File

@ -256,6 +256,31 @@ func checkValidCreateVolumeRequest(
return nil 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. // CreateVolume creates a reservation and the volume in backend, if it is not already present.
// //
//nolint:gocognit,gocyclo,nestif,cyclop // TODO: reduce complexity //nolint:gocognit,gocyclo,nestif,cyclop // TODO: reduce complexity
@ -376,25 +401,7 @@ func (cs *ControllerServer) CreateVolume(
} }
} }
// remove kubernetes csi prefixed parameters. return buildCreateVolumeResponse(req, volOptions, vID), nil
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
} }
// Reservation // Reservation
@ -467,25 +474,8 @@ func (cs *ControllerServer) CreateVolume(
log.DebugLog(ctx, "cephfs: successfully created backing volume named %s for request name %s", log.DebugLog(ctx, "cephfs: successfully created backing volume named %s for request name %s",
vID.FsSubvolName, requestName) 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. // DeleteVolume deletes the volume in backend and its reservation.

View File

@ -240,8 +240,7 @@ func (cs *ControllerServer) parseVolCreateRequest(
} }
func buildCreateVolumeResponse(req *csi.CreateVolumeRequest, rbdVol *rbdVolume) *csi.CreateVolumeResponse { func buildCreateVolumeResponse(req *csi.CreateVolumeRequest, rbdVol *rbdVolume) *csi.CreateVolumeResponse {
// remove kubernetes csi prefixed parameters. volumeContext := util.GetVolumeContext(req.GetParameters())
volumeContext := k8s.RemoveCSIPrefixedParameters(req.GetParameters())
volumeContext["pool"] = rbdVol.Pool volumeContext["pool"] = rbdVol.Pool
volumeContext["journalPool"] = rbdVol.JournalPool volumeContext["journalPool"] = rbdVol.JournalPool
volumeContext["imageName"] = rbdVol.RbdImageName volumeContext["imageName"] = rbdVol.RbdImageName

View File

@ -21,6 +21,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"slices"
"strings" "strings"
"time" "time"
@ -353,7 +354,6 @@ func attachRBDImage(ctx context.Context, volOptions *rbdVolume, device string, c
} }
err = waitForrbdImage(ctx, backoff, volOptions) err = waitForrbdImage(ctx, backoff, volOptions)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -364,7 +364,7 @@ func attachRBDImage(ctx context.Context, volOptions *rbdVolume, device string, c
} }
func appendNbdDeviceTypeAndOptions(cmdArgs []string, userOptions, cookie string) []string { func appendNbdDeviceTypeAndOptions(cmdArgs []string, userOptions, cookie string) []string {
isUnmap := CheckSliceContains(cmdArgs, "unmap") isUnmap := slices.Contains(cmdArgs, "unmap")
if !isUnmap { if !isUnmap {
if !strings.Contains(userOptions, useNbdNetlink) { if !strings.Contains(userOptions, useNbdNetlink) {
cmdArgs = append(cmdArgs, "--"+useNbdNetlink) cmdArgs = append(cmdArgs, "--"+useNbdNetlink)

View File

@ -2071,17 +2071,6 @@ func getCephClientLogFileName(id, logDir, prefix string) string {
return fmt.Sprintf("%s/%s-%s.log", logDir, prefix, id) 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. // strategicActionOnLogFile act on log file based on cephLogStrategy.
func strategicActionOnLogFile(ctx context.Context, logStrategy, logFile string) { func strategicActionOnLogFile(ctx context.Context, logStrategy, logFile string) {
var err error var err error

View File

@ -30,6 +30,9 @@ import (
const ( const (
keySeparator rune = '/' keySeparator rune = '/'
labelSeparator string = "," labelSeparator string = ","
// topologyPoolsParam is the parameter name used to pass topology constrained pools.
topologyPoolsParam = "topologyConstrainedPools"
) )
// GetTopologyFromDomainLabels returns the CSI topology map, determined from // GetTopologyFromDomainLabels returns the CSI topology map, determined from
@ -129,7 +132,7 @@ func GetTopologyFromRequest(
var topologyPools []TopologyConstrainedPool var topologyPools []TopologyConstrainedPool
// check if parameters have pool configuration pertaining to topology // check if parameters have pool configuration pertaining to topology
topologyPoolsStr := req.GetParameters()["topologyConstrainedPools"] topologyPoolsStr := req.GetParameters()[topologyPoolsParam]
if topologyPoolsStr == "" { if topologyPoolsStr == "" {
return nil, nil, nil return nil, nil, nil
} }

View File

@ -27,6 +27,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/ceph/ceph-csi/internal/util/k8s"
"github.com/ceph/ceph-csi/internal/util/log" "github.com/ceph/ceph-csi/internal/util/log"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -381,3 +382,23 @@ func CallStack() string {
return string(stack) 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
}

View File

@ -6,7 +6,7 @@ StorageClass:
SnapshotClass: SnapshotClass:
# Must be set to enable snapshotting tests # Must be set to enable snapshotting tests
FromName: false FromExistingClassName: k8s-storage-e2e-cephfs
DriverInfo: DriverInfo:
# Internal name of the driver, display name in the test case and test objects # Internal name of the driver, display name in the test case and test objects
@ -46,7 +46,7 @@ DriverInfo:
volumeLimits: false volumeLimits: false
# Support for volume expansion in controllers # Support for volume expansion in controllers
controllerExpansion: false controllerExpansion: true
# Support for volume expansion in nodes # Support for volume expansion in nodes
nodeExpansion: false nodeExpansion: false
@ -61,7 +61,7 @@ DriverInfo:
topology: false topology: false
# Support populate data from snapshot # Support populate data from snapshot
snapshotDataSource: false snapshotDataSource: true
# Support populated data from PVC # Support populated data from PVC
pvcDataSource: false pvcDataSource: true