Create singleuser with custom resource

Hi Community,

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

  1. profile list
  2. form option
    which doesnt fit my use case
    However i can also find below api

which takes dictionary as input for user_options. How to use this api to provide cpu and memory configs? I can’t find any example for such

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

which would allow you to:'{hub_url}/hub/api/users/servers/', data=json.dumps{"mem_guarantee": "1G"})

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")

in all places in zero-to-jupyterhub-k8s/jupyterhub/files/hub/ at 53ff33b286b35852dca3aea628f0fe976276e1a5 · jupyterhub/zero-to-jupyterhub-k8s · GitHub file?

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.

how do you work directly with api?

i am only spawning jupyterlab using api with custom configuration as json