ceph / ceph-csi

CSI driver for Ceph
Apache License 2.0
1.27k stars 539 forks source link

Race condition when mounting RBD static PVs with the same image name in different pools #4526

Open AsPulse opened 6 months ago

AsPulse commented 6 months ago

Describe the bug

When two RBD Images with the same name in different pools are attempted to be mounted as staticVolume following this procedure, only the one attempted to be mounted first will succeed.

The later one succeeds in creating the PV/PVC and associating the pod with the PVC, but the pod remains in the Pending state with the following error displayed in the events in the pod:

Multi-Attach error for volume "foo-pv" Volume is already used by 1 pod(s) in different namespaces

Environment details

Steps to reproduce

Steps to reproduce the behavior:

  1. Setup details:
    • Setup Rook-ceph Cluster
    • Create pools named foo and bar, enabled application rbd
    • Create RBD Image test under each 2 pools
  2. Deploy below 2 PVs
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: foo-pv
    spec:
      accessModes:
      - ReadWriteOnce
      capacity:
        storage: 1Gi
      csi:
        driver: rook-ceph.rbd.csi.ceph.com
        fsType: ext4
        nodeStageSecretRef:
          name: rook-csi-rbd-node
          namespace: rook-ceph
        volumeAttributes:
          clusterID: "rook-ceph"
          pool: "foo"
          staticVolume: "true"
          imageFeatures: "layering,fast-diff,object-map,deep-flatten,exclusive-lock"
        volumeHandle: test
      persistentVolumeReclaimPolicy: Retain
      volumeMode: Filesystem
    ---
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: bar-pv
    spec:
      accessModes:
      - ReadWriteOnce
      capacity:
        storage: 1Gi
      csi:
        driver: rook-ceph.rbd.csi.ceph.com
        fsType: ext4
        nodeStageSecretRef:
          name: rook-csi-rbd-node
          namespace: rook-ceph
        volumeAttributes:
          clusterID: "rook-ceph"
          pool: "bar"
          staticVolume: "true"
          imageFeatures: "layering,fast-diff,object-map,deep-flatten,exclusive-lock"
        volumeHandle: test
      persistentVolumeReclaimPolicy: Retain
      volumeMode: Filesystem
  3. Claim above 2 PVs from some pods placed in different namespaces.
  4. See error
    Multi-Attach error for volume "foo-pv" Volume is already used by 1 pod(s) in different namespaces

    or

    Multi-Attach error for volume "bar-pv" Volume is already used by 1 pod(s) in different namespaces

Actual results

Later mounted pods will stack at Pending due to an error.

Expected behavior

Both pods successfully mount the RBD.

Logs

If the issue is in PVC mounting please attach complete logs of below containers.

Additional context

I used Rook ceph, but I don't think the problem is related to Rook.

Madhu-1 commented 6 months ago

@AsPulse i believe the error is coming from the kubernetes please check kubelet logs. is it possible to use different names in volumeHandle in the PV?