Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaningup empty parents resulted in all data being deleted #855

Open
adelmoradian opened this issue Feb 3, 2025 · 7 comments · May be fixed by #876
Open

Cleaningup empty parents resulted in all data being deleted #855

adelmoradian opened this issue Feb 3, 2025 · 7 comments · May be fixed by #876

Comments

@adelmoradian
Copy link

What happened: if subDir is set to something like foo/${pvc.metadata.namespace}/${pvc.metadata.name}/ and if there are no more PVCs left in a given namespace, all data under /foo will be deleted.

What you expected to happen: This is arguably caused by bad config since something like subDir=${pvc.metadata.namespace}/${pvc.metadata.name}/ would prevent the issue. But still, would be nice to have this highlighted in the docs at least.

I think the issue is caused here specifically by getRootDir.

How to reproduce it:

  • Create a default storage class with subDir=foo/${pvc.metadata.namespace}/${pvc.metadata.name}
  • Create something with a PVC (a database for example) in two different namespaces
  • Deleting PVCs in one namespace should delete all data

Anything else we need to know?:

Environment:

  • CSI Driver version: 4.10
  • Kubernetes version (use kubectl version): v1.31.2+rke2r1
  • OS (e.g. from /etc/os-release): Ubuntu 24.04 LTS
  • Kernel (e.g. uname -a): 6.8.0-31-generic
@UnknownAtoms
Copy link

Hello,
we have the same behavior.

What happened:
All data of the PVCs of a namespace are deleted with the configuration
subdir=${pvc.metadata.namespace}/${pvc.metadata.name} when deleting a PVC from the namespace.

What you expected to happen:
the deleted PVC is deleted without deleting all data of the other PVCs in the namespace

How to reproduce it:
Create a default storage class with subDir=${pvc.metadata.namespace}/${pvc.metadata.name}
Create 2 PVCs in the namespace
Delete one of the two PVCs and the entire folder of the namespace will be deleted.

Environment:
CSI Driver version: 4.10
Kubernetes version: v1.31.4
OS (e.g. from /etc/os-release): Red Hat Enterprise Linux 9.3 (Plow)
Kernel (e.g. uname -a): 5.14.0-362.8.1.el9_3.x86_64

@san3Xian
Copy link

san3Xian commented Mar 9, 2025

Same of this.
Deleting a pvc under a namespace causes the namespace folder to be deleted.
It's a very horrible phenomenon.

(base) root@g-controller:~/sanXian/yamls# helm get values -n storage-system csi-driver-nfs
USER-SUPPLIED VALUES:
controller:
  replicas: 1
  runOnControlPlane: true
externalSnapshotter:
  customResourceDefinitions:
    enabled: false
  enabled: true
image:
  csiProvisioner:
    repository: 100.64.254.1/sig-storage/csi-provisioner
  csiResizer:
    repository: 100.64.254.1/sig-storage/csi-resizer
  csiSnapshotter:
    repository: 100.64.254.1/sig-storage/csi-snapshotter
  externalSnapshotter:
    repository: 100.64.254.1/sig-storage/snapshot-controller
  livenessProbe:
    repository: 100.64.254.1/sig-storage/livenessprobe
  nfs:
    repository: 100.64.254.1/sig-storage/nfsplugin
  nodeDriverRegistrar:
    repository: 100.64.254.1/sig-storage/csi-node-driver-registrar
storageClass:
  annotations:
    storageclass.kubernetes.io/is-default-class: "false"
  create: "true"
  name: nfs-k8s-storage-system
  parameters:
    server: 10.233.34.184
    share: /exports
    subDir: ${pvc.metadata.namespace}/${pv.metadata.name}--${pvc.metadata.name}
  reclaimPolicy: Delete
(base) root@g-controller:~/sanXian/yamls# helm list -n storage-system
NAME          	NAMESPACE     	REVISION	UPDATED                                	STATUS  	CHART                 	APP VERSION
csi-driver-nfs	storage-system	1       	2025-02-20 21:02:20.589728127 +0800 CST	deployed	csi-driver-nfs-v4.10.0	v4.10.0

@san3Xian
Copy link

san3Xian commented Mar 9, 2025

Similar Issues: #763

@andyzhangx
Copy link
Member

andyzhangx commented Mar 9, 2025

this is for solving this issue: #763, quite opposite requirement to cleanup empty parents when deleting PV

@andyzhangx
Copy link
Member

working on a PR to only delete root folder of subDir when OnDelete: DeleteRootSubDir since there is data loss concern: #876

@jsalatiel
Copy link

jsalatiel commented Mar 10, 2025

I am trying to understand what happened.

According to @adelmoradian:
What you expected to happen: This is arguably caused by bad config since something like subDir=${pvc.metadata.namespace}/${pvc.metadata.name}/ would prevent the issue. But still, would be nice to have this highlighted in the docs at least.
which seems that delete a pvc under ${pvc.metadata.namespace}/${pvc.metadata.name} would not delete the parent if there are other pvcs.

but according to @UnknownAtoms and @san3Xian , delete one pvc inside a multi pvc namespace would delete all PVCs. ( directory ${pvc.metadata.namespace}/)

@andyzhangx Was this a bug in the implementation? The parent should only be deleted if all children directories are empty.

@jsalatiel
Copy link

@andyzhangx concerning #876 , wouldn ´t be safer to traverse the parent's tree checking for files before using removeAll() or use Remove() that only delete empty dirs afaik ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants