Skip to content

Commit 196d60a

Browse files
iPraveenPariharceph-csi-bot
authored andcommitted
cephfs: add SetSubVolCSIMetadata to set CSI metadata on subvolumes
Add support for setting CSI metadata (PV/PVC info) on CephFS subvolumes. The PV controller now distinguishes between CephFS and RBD PVs and dispatches accordingly. Signed-off-by: Praveen M <m.praveen@ibm.com>
1 parent 2bf52db commit 196d60a

File tree

5 files changed

+148
-17
lines changed

5 files changed

+148
-17
lines changed

charts/ceph-csi-cephfs/templates/provisioner-deployment.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,36 @@ spec:
283283
resources:
284284
{{ toYaml .Values.provisioner.resizer.resources | indent 12 }}
285285
{{- end }}
286+
{{- if .Values.provisioner.deployController }}
287+
- name: csi-cephfsplugin-controller
288+
image: "{{ .Values.nodeplugin.plugin.image.repository }}:{{ .Values.nodeplugin.plugin.image.tag }}"
289+
imagePullPolicy: {{ .Values.nodeplugin.plugin.image.pullPolicy }}
290+
args:
291+
- "--type=controller"
292+
- "--v={{ .Values.logLevel }}"
293+
- "--drivername=$(DRIVER_NAME)"
294+
- "--drivernamespace=$(DRIVER_NAMESPACE)"
295+
{{- if .Values.provisioner.clustername }}
296+
- "--clustername={{ .Values.provisioner.clustername }}"
297+
{{- end }}
298+
- "--setmetadata={{ .Values.provisioner.setmetadata }}"
299+
env:
300+
- name: DRIVER_NAMESPACE
301+
valueFrom:
302+
fieldRef:
303+
fieldPath: metadata.namespace
304+
- name: DRIVER_NAME
305+
value: {{ .Values.driverName }}
306+
volumeMounts:
307+
- name: ceph-csi-config
308+
mountPath: /etc/ceph-csi-config/
309+
- name: keys-tmp-dir
310+
mountPath: /tmp/csi/keys
311+
- name: ceph-config
312+
mountPath: /etc/ceph/
313+
resources:
314+
{{ toYaml .Values.nodeplugin.plugin.resources | indent 12 }}
315+
{{- end }}
286316
{{- if .Values.provisioner.httpMetrics.enabled }}
287317
- name: liveness-prometheus
288318
image: "{{ .Values.nodeplugin.plugin.image.repository }}:{{ .Values.nodeplugin.plugin.image.tag }}"

charts/ceph-csi-cephfs/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ provisioner:
247247
# set metadata on volume
248248
setmetadata: true
249249

250+
# deployController to enable or disable the deployment of controller which
251+
# sets the CSI metadata on CephFS subvolumes.
252+
deployController: true
253+
250254
# enable fencing
251255
fencing: false
252256

deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,27 @@ spec:
192192
volumeMounts:
193193
- name: socket-dir
194194
mountPath: /csi
195+
- name: csi-cephfsplugin-controller
196+
image: quay.io/cephcsi/cephcsi:canary
197+
args:
198+
- "--type=controller"
199+
- "--v=5"
200+
- "--drivername=cephfs.csi.ceph.com"
201+
- "--drivernamespace=$(DRIVER_NAMESPACE)"
202+
- "--setmetadata=true"
203+
env:
204+
- name: DRIVER_NAMESPACE
205+
valueFrom:
206+
fieldRef:
207+
fieldPath: metadata.namespace
208+
imagePullPolicy: "IfNotPresent"
209+
volumeMounts:
210+
- name: ceph-csi-config
211+
mountPath: /etc/ceph-csi-config/
212+
- name: keys-tmp-dir
213+
mountPath: /tmp/csi/keys
214+
- name: ceph-config
215+
mountPath: /etc/ceph/
195216
- name: liveness-prometheus
196217
image: quay.io/cephcsi/cephcsi:canary
197218
args:

internal/cephfs/store/fsjournal.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
cerrors "github.com/ceph/ceph-csi/internal/cephfs/errors"
2929
"github.com/ceph/ceph-csi/internal/journal"
3030
"github.com/ceph/ceph-csi/internal/util"
31+
"github.com/ceph/ceph-csi/internal/util/k8s"
3132
"github.com/ceph/ceph-csi/internal/util/log"
3233
"github.com/ceph/ceph-csi/pkg/util/crypto"
3334
)
@@ -471,3 +472,56 @@ func CheckSnapExists(
471472

472473
return sid, nil
473474
}
475+
476+
// SetSubVolCSIMetadata sets CSI metadata (PV/PVC info) on a CephFS subvolume.
477+
func SetSubVolCSIMetadata(
478+
ctx context.Context,
479+
volumeAttributes map[string]string,
480+
volumeID,
481+
pvName,
482+
pvcName,
483+
pvcNamespace,
484+
clusterName string,
485+
cr *util.Credentials,
486+
) error {
487+
var vi util.CSIIdentifier
488+
if err := vi.DecomposeCSIID(volumeID); err != nil {
489+
return fmt.Errorf("%w: error decoding volume ID (%w) (%s)",
490+
cerrors.ErrInvalidVolID, err, volumeID)
491+
}
492+
493+
monitors, err := util.Mons(util.CsiConfigFile, vi.ClusterID)
494+
if err != nil {
495+
return fmt.Errorf("failed to fetch monitor list using clusterID (%s): %w", vi.ClusterID, err)
496+
}
497+
498+
subvolumeGroup, err := util.CephFSSubvolumeGroup(util.CsiConfigFile, vi.ClusterID)
499+
if err != nil {
500+
return fmt.Errorf("failed to fetch subvolumegroup using clusterID (%s): %w", vi.ClusterID, err)
501+
}
502+
503+
conn := &util.ClusterConnection{}
504+
if err = conn.Connect(monitors, cr); err != nil {
505+
return fmt.Errorf("failed to connect to cluster: %w", err)
506+
}
507+
defer conn.Destroy()
508+
509+
fsName := volumeAttributes["fsName"]
510+
subvolName := volumeAttributes["subvolumeName"]
511+
512+
subVol := &core.SubVolume{
513+
VolID: subvolName,
514+
FsName: fsName,
515+
SubvolumeGroup: subvolumeGroup,
516+
}
517+
volClient := core.NewSubVolume(conn, subVol, vi.ClusterID, clusterName, true)
518+
parameters := k8s.PrepareVolumeMetadata(pvcName, pvcNamespace, pvName)
519+
if err = volClient.SetAllMetadata(parameters); err != nil {
520+
return fmt.Errorf("failed to set metadata on subvolume %s: %w", subvolName, err)
521+
}
522+
523+
log.DebugLog(ctx, "cephfs: successfully set metadata on subvolume %s for PV %s",
524+
subvolName, pvName)
525+
526+
return nil
527+
}

internal/controller/persistentvolume/persistentvolume.go

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"sigs.k8s.io/controller-runtime/pkg/predicate"
3434
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3535

36+
cephfsstore "github.com/ceph/ceph-csi/internal/cephfs/store"
3637
ctrl "github.com/ceph/ceph-csi/internal/controller"
3738
"github.com/ceph/ceph-csi/internal/rbd"
3839
"github.com/ceph/ceph-csi/internal/util"
@@ -137,23 +138,44 @@ func (r *ReconcilePersistentVolume) reconcilePV(ctx context.Context, obj runtime
137138
}
138139
defer cr.DeleteCredentials()
139140

140-
rbdVolID, err := rbd.RegenerateJournal(
141-
pv.Spec.CSI.VolumeAttributes,
142-
pv.Spec.ClaimRef.Name,
143-
volumeHandler,
144-
requestName,
145-
pvcNamespace,
146-
r.config.ClusterName,
147-
r.config.InstanceID,
148-
r.config.SetMetadata,
149-
cr)
150-
if err != nil {
151-
log.ErrorLogMsg("failed to regenerate journal %s", err)
152-
153-
return err
154-
}
155-
if rbdVolID != volumeHandler {
156-
log.DebugLog(ctx, "volumeHandler changed from %s to %s", volumeHandler, rbdVolID)
141+
// Determine PV type from volume attributes and dispatch accordingly.
142+
// CephFS PVs always have "fsName" in their volume attributes (required
143+
// StorageClass parameter), while RBD PVs do not.
144+
_, isCephFS := pv.Spec.CSI.VolumeAttributes["fsName"]
145+
if isCephFS {
146+
err = cephfsstore.SetSubVolCSIMetadata(
147+
ctx,
148+
pv.Spec.CSI.VolumeAttributes,
149+
volumeHandler,
150+
requestName,
151+
pv.Spec.ClaimRef.Name,
152+
pvcNamespace,
153+
r.config.ClusterName,
154+
cr)
155+
if err != nil {
156+
log.ErrorLogMsg("failed to set CephFS subvolume metadata %s", err)
157+
158+
return err
159+
}
160+
} else {
161+
rbdVolID, err := rbd.RegenerateJournal(
162+
pv.Spec.CSI.VolumeAttributes,
163+
pv.Spec.ClaimRef.Name,
164+
volumeHandler,
165+
requestName,
166+
pvcNamespace,
167+
r.config.ClusterName,
168+
r.config.InstanceID,
169+
r.config.SetMetadata,
170+
cr)
171+
if err != nil {
172+
log.ErrorLogMsg("failed to regenerate journal %s", err)
173+
174+
return err
175+
}
176+
if rbdVolID != volumeHandler {
177+
log.DebugLog(ctx, "volumeHandler changed from %s to %s", volumeHandler, rbdVolID)
178+
}
157179
}
158180

159181
return nil

0 commit comments

Comments
 (0)