I am using jupyterhub on kubernetes using this.
In the helm chart, we can provide resource guarantee and limit for singleuser image to spawn. However, i want it dynamic means user can select resource such as cpu and memory on demand and using that singe user pod will spawn.
I can see 2 ways to do that
profile list
form option
which doesnt fit my use case
However i can also find below api
Passing user_options via the API is the same as sending it via a form, but you specify the user_options dict directly in the request body, instead of it going through Spawner.options_from_form (A form is not required to support user_options, it is just fine for some or all user_options to be api-only, if that makes sense for your deployment).
user_options is available in self.user_options in Spawner.start, so you can extend that to handle whatever user_options you want to define in your Spawner subclass. For example:
from kubespawner import KubeSpawner
class MySpawner(KubeSpawner):
async def start(self):
# process any user_options
if "mem_guarantee" in self.user_options:
self.mem_guarantee = self.user_options["mem_guarantee"]
# continue with start
return await super().start()
c.JupyterHub.spawner_class = MySpawner
so with above additional changes . I also have to call my spawner instead of kubespawner. Ex - c.MySpawner.namespace = os.environ.get("POD_NAMESPACE", "default")
instead of c.KubeSpawner.namespace = os.environ.get("POD_NAMESPACE", "default")
You don’t need to change anything in your config to use a custom subclass. Config loading follows class inheritance, so you can set base Spawner config on c.Spawner, KubeSpawner-specific config on c.KubeSpawner, etc. and MySpawner will load it all since it inherits from those classes.
You would only need to rename KubeSpawner fields to MySpawner if you decided to inherit from the base Spawner class instead of KubeSpawner, so that KubeSpawner was no longer a parent class.