Kubespawner deletes PVC even if the pvcNameTemplate doesn't include username
Bug description
If a shared dynamically created PVC is used and a JupyterHub user is deleted KubeSpawner will incorrectly delete the shared PVC.
How to reproduce
Use this Z2JH singleuser.storage config with the latest release 4.1.0
singleuser:
storage:
dynamic:
storageClass: nfs
pvcNameTemplate: claim-jupyter
subPath: "{user_server}"
This is not a typical configuration since Z2JH's PVC support is used purely for convenience to create just a single shared PVC. However it's possible to conceive of other semi-static pvcNameTemplate, for example you could use profileList with kubespawner_overrides to set pvcNameTemplate=<profilename> to have a shared volume across multiple users.
Expected behaviour
PVC should not be deleted
Actual behaviour
It's deleted- though in practice it may get stuck because of the subPaths
Your personal set up
- OS:
- Version(s):
Full environment
# paste output of `pip freeze` or `conda list` here
Configuration
# jupyterhub_config.py
Logs
As it happens overriding the PVC template in `kubespawner_overrides won't work at the moment:
- https://github.com/jupyterhub/kubespawner/issues/761
- https://github.com/jupyterhub/kubespawner/pull/820
so the only way to run into this bug is if KubeSpawner.pvc_name_template is set
https://github.com/jupyterhub/kubespawner/pull/744 stores the PVC name in the spawner state, so to know whether it's safe to delete a PVC we'd need to assert that the current PVC name matches the current pvc_name_template, and that pvc_name_template contains a username variable.