From c0fc7b36e38d94a38500490a4c988beaa1179cdf Mon Sep 17 00:00:00 2001 From: parth-gr Date: Mon, 26 Feb 2024 19:29:58 +0530 Subject: [PATCH] rbd: make pool optional in rbd sc if topologyconstraints are present if rbd storage class is created with topologyconstraintspools replicated pool was still mandatory, making the pool optional if the topologyconstraintspools is requested Closes: https://github.com/ceph/ceph-csi/issues/4380 Signed-off-by: parth-gr --- .../ceph-csi-rbd/templates/storageclass.yaml | 4 ++- charts/ceph-csi-rbd/values.yaml | 1 + examples/rbd/storageclass.yaml | 1 + internal/rbd/controllerserver.go | 34 ++++++++++--------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/charts/ceph-csi-rbd/templates/storageclass.yaml b/charts/ceph-csi-rbd/templates/storageclass.yaml index 459a6ea312ac..188362fc0503 100644 --- a/charts/ceph-csi-rbd/templates/storageclass.yaml +++ b/charts/ceph-csi-rbd/templates/storageclass.yaml @@ -16,8 +16,10 @@ metadata: provisioner: {{ .Values.driverName }} parameters: clusterID: {{ .Values.storageClass.clusterID }} - pool: {{ .Values.storageClass.pool }} imageFeatures: {{ .Values.storageClass.imageFeatures }} +{{- if .Values.storageClass.pool }} + pool: {{ .Values.storageClass.pool }} +{{- end }} {{- if .Values.storageClass.tryOtherMounters }} tryOtherMounters: {{ .Values.storageClass.tryOtherMounters | quote}} {{- end }} diff --git a/charts/ceph-csi-rbd/values.yaml b/charts/ceph-csi-rbd/values.yaml index 7dc4d019ab17..1f071a20afec 100644 --- a/charts/ceph-csi-rbd/values.yaml +++ b/charts/ceph-csi-rbd/values.yaml @@ -321,6 +321,7 @@ storageClass: dataPool: "" # (required) Ceph pool into which the RBD image shall be created + # (optional) if topologyConstrainedPools is provided # eg: pool: replicapool pool: replicapool diff --git a/examples/rbd/storageclass.yaml b/examples/rbd/storageclass.yaml index ca7fc9a7247a..601a6696af4c 100644 --- a/examples/rbd/storageclass.yaml +++ b/examples/rbd/storageclass.yaml @@ -26,6 +26,7 @@ parameters: # dataPool: # (required) Ceph pool into which the RBD image shall be created + # (optional) If the topologyConstrainedPools is provided # eg: pool: rbdpool pool: diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index e3796b6611d2..2663781314ed 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -225,31 +225,33 @@ func (cs *ControllerServer) parseVolCreateRequest( } func buildCreateVolumeResponse(req *csi.CreateVolumeRequest, rbdVol *rbdVolume) *csi.CreateVolumeResponse { - // remove kubernetes csi prefixed parameters. - volumeContext := k8s.RemoveCSIPrefixedParameters(req.GetParameters()) - volumeContext["pool"] = rbdVol.Pool - volumeContext["journalPool"] = rbdVol.JournalPool - volumeContext["imageName"] = rbdVol.RbdImageName - if rbdVol.RadosNamespace != "" { - volumeContext["radosNamespace"] = rbdVol.RadosNamespace - } - - if rbdVol.DataPool != "" { - volumeContext["dataPool"] = rbdVol.DataPool - } - volume := &csi.Volume{ VolumeId: rbdVol.VolID, CapacityBytes: rbdVol.VolSize, - VolumeContext: volumeContext, ContentSource: req.GetVolumeContentSource(), } - if rbdVol.Topology != nil { - volume.AccessibleTopology = []*csi.Topology{ + + // remove kubernetes csi prefixed parameters. + volumeContext := k8s.RemoveCSIPrefixedParameters(req.GetParameters()) + if rbdVol.Topology == nil { + volumeContext["pool"] = rbdVol.Pool + volumeContext["journalPool"] = rbdVol.JournalPool + volumeContext["imageName"] = rbdVol.RbdImageName + if rbdVol.RadosNamespace != "" { + volumeContext["radosNamespace"] = rbdVol.RadosNamespace + } + + if rbdVol.DataPool != "" { + volumeContext["dataPool"] = rbdVol.DataPool + } + volume.VolumeContext = volumeContext + } else { + accessibleTopology := []*csi.Topology{ { Segments: rbdVol.Topology, }, } + volume.AccessibleTopology = accessibleTopology } return &csi.CreateVolumeResponse{Volume: volume}