jupyterhub / kubespawner

Kubernetes spawner for JupyterHub
https://jupyterhub-kubespawner.readthedocs.io
BSD 3-Clause "New" or "Revised" License
536 stars 301 forks source link

Public method `stop` should not be called from private method `_start` #764

Open mbelak-dtml opened 11 months ago

mbelak-dtml commented 11 months ago

Proposed change

Reasoning

TL;DR: The stop method is assumed to only delete the JupyterLab server pod, although the inheritance contract should be that the method deletes any resources associated with the server.

The current implemenation makes extending KubeSpawner with additional resources very difficult. It assumes that the stop method just stops the JupyterLab server pod. This is, however, problematic in case additional Kubernetes resources are being cleared in an override of the method stop.

The stop method is called for example here: https://github.com/jupyterhub/kubespawner/blob/0e5bb4610be13865a09e16a6b4833835bce4c45a/kubespawner/spawner.py#L2525-L2533 This is problematic since it's called from the start method. However, the overridden start and stop method might look something like this:

def start(self):
    self._deploy_my_custom_resources()
    return super().start()  
async def stop(self):
    self._destroy_my_custom_resources()
    super().stop()

In that case the call to stop also destroys the custom resources, although it should really just delete the pod.

Alternative options

Who would use this feature?

Anyone creating a custom subclass of KubeSpawner which deploys additional Kubernetes resources in the start method.

(Optional): Suggest a solution

Add a private _stop method and make the public stop method just a thin wrapper around the private method, similar to what's already done with start and _start. Only call the _stop method in the implementation.

welcome[bot] commented 11 months ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada: