kubernetes-csi / csi-driver-nfs

This driver allows Kubernetes to access NFS server on Linux node.
Apache License 2.0
872 stars 252 forks source link

Clean up empty parents on deletion when using subDir #763

Closed jsalatiel closed 2 months ago

jsalatiel commented 2 months ago

What happened: The subDir parameter provides great flexibility allowing the user to set the subDir to something one considers helpful. The problem is that when subDir is set to some nested directory tree like for example:

subDir=${pvc.metadata.namespace}/${pvc.metadata.name}/ when all the volumes from namespace are deleted, you will still see in the storage the empty $namespace directory.

The problem is even bigger if the depth of the subdir is bigger, for example: subDir=${pvc.metadata.namespace}/${pvc.metadata.name}/${pv.metadata.name} If I delete all the volumes of that namespace I will have at least 2 empty directories inside the $namespace directory on the nfs share.

What you expected to happen: When deleting a volume, the driver should check if its parent is empty ( and it is inside a level of subDir ) and if so delete it too.

How to reproduce it: Use subDir=${pvc.metadata.namespace}/${pvc.metadata.name}/${pv.metadata.name} Use this values.yaml

replicaCount: 1
persistence:
  enabled: true
  accessModes:
    - ReadWriteMany
  size: 1Gi
mariadb:
  primary:
    persistence:
      size: 2Gi

and install wordpress to test it. helm install wp oci://registry-1.docker.io/bitnamicharts/wordpress --namespace wp --create-namespace -f values.yml

Delete the wp namespace and check the remove NFS server, there will be several emptydirs under the wp folder.

Anything else we need to know?:

Environment:

andyzhangx commented 2 months ago

/kind bug