Skip to content
Open
Show file tree
Hide file tree
Changes from 20 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
2 changes: 1 addition & 1 deletion charts/ceph-csi-rbd/templates/csidriver-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ metadata:
name: {{ .Values.driverName }}
spec:
attachRequired: true
podInfoOnMount: false
podInfoOnMount: true
2 changes: 1 addition & 1 deletion deploy/cephcsi/image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
/etc/yum.repos.d/CentOS-Stream-PowerTools.repo \
/etc/yum.repos.d/CentOS-Stream-RealTime.repo

RUN dnf config-manager --disable apache-arrow-centos || true
RUN dnf config-manager --disable apache-arrow-centos,tcmu-runner,tcmu-runner-source,tcmu-runner-noarch || true

RUN yum clean all && yum makecache

Expand Down
2 changes: 1 addition & 1 deletion deploy/rbd/kubernetes/csidriver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ metadata:
name: rbd.csi.ceph.com
spec:
attachRequired: true
podInfoOnMount: false
podInfoOnMount: true
7 changes: 5 additions & 2 deletions internal/rbd/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,8 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req
}

for _, capability := range req.VolumeCapabilities {
if capability.GetAccessMode().GetMode() != csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER {
if capability.GetAccessMode().GetMode() != csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER &&
capability.GetAccessMode().GetMode() != csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY {
return &csi.ValidateVolumeCapabilitiesResponse{Message: ""}, nil
}
}
Expand Down Expand Up @@ -1131,7 +1132,9 @@ func (cs *ControllerServer) ControllerPublishVolume(ctx context.Context, req *cs
ro = "true"
}

return &csi.ControllerPublishVolumeResponse{PublishContext: map[string]string{readonlyAttachmentKey: ro}}, nil
mode := req.GetVolumeCapability().GetAccessMode().GetMode()
am := csi.VolumeCapability_AccessMode_Mode_name[int32(mode)]
return &csi.ControllerPublishVolumeResponse{PublishContext: map[string]string{readonlyAttachmentKey: ro, "Capability": am}}, nil
}

// ControllerUnpublishVolume does nothing.
Expand Down
2 changes: 1 addition & 1 deletion internal/rbd/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (r *Driver) Run(conf *util.Config) {
// will work those as follow up features
r.cd.AddVolumeCapabilityAccessModes(
[]csi.VolumeCapability_AccessMode_Mode{csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER})
csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER, csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY})
}

// Create GRPC servers
Expand Down
29 changes: 29 additions & 0 deletions internal/rbd/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
return nil, err
}

// sync volcap with va's accessmode
if req.GetPublishContext()["Capability"] == csi.VolumeCapability_AccessMode_Mode_name[1] {
req.VolumeCapability.AccessMode.Mode = csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER
} else {
req.VolumeCapability.AccessMode.Mode = csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY
}

disableInUseChecks := req.GetPublishContext()[readonlyAttachmentKey] == "true"
isBlock := req.GetVolumeCapability().GetBlock() != nil
// disableInUseChecks := false
Expand Down Expand Up @@ -401,6 +408,26 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
volID := req.GetVolumeId()
stagingPath += "/" + volID

// set podInfoOnMount = true to get the actual pod info
podName := req.GetVolumeContext()["csi.storage.k8s.io/pod.name"]
podNamespace := req.GetVolumeContext()["csi.storage.k8s.io/pod.namespace"]

pod, err := util.GetPod(podName, podNamespace)
if err != nil {
return nil, err
}

ro, err := util.CheckIfReadonlyMount(pod)
if err != nil {
req.Readonly = ro
}

if req.GetPublishContext()[readonlyAttachmentKey] == "true" || req.GetPublishContext()[readonlyAttachmentKey] == "" {
Comment thread
houz42 marked this conversation as resolved.
Outdated
if !ro {
return nil, status.Errorf(codes.Aborted, "cannot mount readwrite pod for multi readonly capability", volID)
}
}

if acquired := ns.VolumeLocks.TryAcquire(volID); !acquired {
util.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volID)
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volID)
Expand Down Expand Up @@ -459,7 +486,9 @@ func (ns *NodeServer) mountVolumeToStagePath(ctx context.Context, req *csi.NodeS
}
}
if csicommon.MountOptionContains(opt, rOnly) {
// readOnly mount with noload option
readOnly = true
opt = append(opt, "noload")
}

if fsType == "xfs" {
Expand Down
46 changes: 46 additions & 0 deletions internal/util/readonly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package util

import (
"context"
"fmt"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
)

func CheckIfReadonlyMount(po *v1.Pod) (bool, error) {
for _, vol := range po.Spec.Volumes {
Comment thread
houz42 marked this conversation as resolved.
if vol.PersistentVolumeClaim != nil {

if !vol.PersistentVolumeClaim.ReadOnly {
for _, con := range po.Spec.Containers {
if con.VolumeMounts == nil {
continue
}
for _, vm := range con.VolumeMounts {
if vm.Name == vol.Name && vm.ReadOnly {
return true, nil
}
}
}
return false, nil
}
return true, nil

}
}
return false, fmt.Errorf("no matching conditions")
}

func GetPod(name string, namespace string) (*v1.Pod, error) {
c := NewK8sClient()
pod, err := c.CoreV1().Pods(namespace).Get(context.TODO(), name, metav1.GetOptions{})

if err != nil {
klog.V(6).Infof("Can't get pod %s namespace %s: %v", name, namespace, err)
return nil, err
}

return pod, nil
}