Skip to content

Commit

Permalink
rbd: make pool optional in rbd sc if topologyconstraints are present
Browse files Browse the repository at this point in the history
if rbd storage class is created with topologyconstraintspools
replicated pool was still mandatory, making the pool optional if the
topologyconstraintspools is requested

Closes: #4380

Signed-off-by: parth-gr <[email protected]>
Signed-off-by: parth-gr <[email protected]>
  • Loading branch information
parth-gr committed Mar 18, 2024
1 parent 83ec709 commit 7a2be75
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion charts/ceph-csi-rbd/templates/storageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/ceph-csi-rbd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions examples/rbd/storageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ parameters:
# dataPool: <ec-data-pool>

# (required) Ceph pool into which the RBD image shall be created
# (optional) If the topologyConstrainedPools is provided
# eg: pool: rbdpool
pool: <rbd-pool-name>

Expand Down
15 changes: 11 additions & 4 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,19 @@ func (cs *ControllerServer) validateVolumeReq(ctx context.Context, req *csi.Crea
}
options := req.GetParameters()
if value, ok := options["clusterID"]; !ok || value == "" {
return status.Error(codes.InvalidArgument, "missing or empty cluster ID to provision volume from")
return status.Error(codes.InvalidArgument, "empty cluster ID to provision volume from")
}
if value, ok := options["pool"]; !ok || value == "" {
poolValue, poolOK := options["pool"]
topologyConstrainedPoolsValue, topologyOK := options["topologyConstrainedPools"]
if !poolOK {
if topologyOK && topologyConstrainedPoolsValue == "" {
return status.Error(codes.InvalidArgument, "empty pool name or topologyConstrainedPools to provision volume")
} else if !topologyOK {
return status.Error(codes.InvalidArgument, "missing or empty pool name to provision volume from")
}
} else if poolValue == "" {
return status.Error(codes.InvalidArgument, "missing or empty pool name to provision volume from")
}

if value, ok := options["dataPool"]; ok && value == "" {
return status.Error(codes.InvalidArgument, "empty datapool name to provision volume from")
}
Expand Down Expand Up @@ -244,14 +251,14 @@ func buildCreateVolumeResponse(req *csi.CreateVolumeRequest, rbdVol *rbdVolume)
VolumeContext: volumeContext,
ContentSource: req.GetVolumeContentSource(),
}

if rbdVol.Topology != nil {
volume.AccessibleTopology = []*csi.Topology{
{
Segments: rbdVol.Topology,
},
}
}

return &csi.CreateVolumeResponse{Volume: volume}
}

Expand Down
10 changes: 6 additions & 4 deletions internal/rbd/rbd_journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ func validateRbdVol(rbdVol *rbdVolume) error {
return err
}

if err = validateNonEmptyField(rbdVol.Pool, "Pool", "rbdVolume"); err != nil {
return err
}

if err = validateNonEmptyField(rbdVol.ClusterID, "ClusterID", "rbdVolume"); err != nil {
return err
}
Expand Down Expand Up @@ -287,6 +283,10 @@ func (rv *rbdVolume) Exists(ctx context.Context, parentVol *rbdVolume) (bool, er
if rv.Topology != nil {
rv.Pool = imageData.ImagePool
}
// validate rbdvolume pool only after looking to the topology pools
if err = validateNonEmptyField(rv.Pool, "Pool", "rbdVolume"); err != nil {
return false, err
}

// NOTE: Return volsize should be on-disk volsize, not request vol size, so
// save it for size checks before fetching image data
Expand Down Expand Up @@ -433,6 +433,7 @@ func updateTopologyConstraints(rbdVol *rbdVolume, rbdSnap *rbdSnapshot) error {
if rbdVol.Topology != nil {
rbdVol.Pool = poolName
rbdVol.DataPool = dataPoolName
rbdVol.JournalPool = poolName
}

return nil
Expand All @@ -446,6 +447,7 @@ func updateTopologyConstraints(rbdVol *rbdVolume, rbdSnap *rbdSnapshot) error {
rbdVol.Pool = poolName
rbdVol.DataPool = dataPoolName
rbdVol.Topology = topology
rbdVol.JournalPool = poolName
}

return nil
Expand Down

0 comments on commit 7a2be75

Please sign in to comment.