Hi there,
I’m able to make a basic jupyterhub with the collaboration server working following Real-time collaboration without impersonation
I’m looking for a potential way to spawn this collaborative user’s pod by using the existing profile_list that I have already defined:
For example:
# Is there a function like below can simplify the above configs
# since I need the collaborative pod to have the same configs as user's personal pod that is configured from the profile list:
spawner.override_from_profile(profile_map["<a group_name from group_names>"])
More details:
profile_map = {
'oauth_group_name': {
'display_name': display_name,
'description': description,
'default': is_default,
'kubespawner_override': {
'image': image,
'default_url': '/lab',
'cpu_limit': cpu_limit,
'cpu_guarantee': cpu_guarantee,
'mem_limit': mem_limit,
'mem_guarantee': mem_guarantee,
'environment': environment,
}
)
}
# Show profiles based on groups
async def custom_options_form(spawner):
## filter profile_list by auth_state["oauth_user"]["groups"]
spawner.profile_list = list(profile_map.values())
return spawner._options_form_default()
# Set profile options
c.KubeSpawner.options_form = custom_options_form
## Create collaboration users
c.JupyterHub.load_roles = []
c.JupyterHub.load_groups = {
# collaborative accounts get added to this group
# so it's easy to see which accounts are collaboration accounts
"collaborative": [],
}
for profile_key in profile_map.keys():
# define a new user for the collaboration
collab_user = f"{profile_key}_collab"
# add the collab user to the 'collaborative' group
# so we can identify it as a collab account
c.JupyterHub.load_groups["collaborative"].append(collab_user)
# finally, grant members of the project collaboration group
# access to the collab user's server,
# and the admin UI so they can start/stop the server
c.JupyterHub.load_roles.append(
{
"name": f"collab-access-{profile_key}",
"scopes": [
f"access:servers!user={collab_user}",
f"admin:servers!user={collab_user}",
"admin-ui",
f"list:users!user={collab_user}",
],
"groups": [profile_key],
}
)
def pre_spawn_hook(spawner):
group_names = {group.name for group in spawner.user.groups}
if "collaborative" in group_names:
############################
spawner.image = "<customized image>"
spawner.default_url = "/lab"
#.....................other configs.....................
## Is there a function like below can simplify the above configs
## since I need the collaborative pod to have the same configs as user's personal pod that is configured from the profile list:
## spawner.override_from_profile(profile_map["<a group_name from group_names>"])
############################
spawner.log.info(f"Enabling RTC for user {spawner.user.name}")
spawner.args.append("--LabApp.collaborative=True")
c.KubeSpawner.pre_spawn_hook = pre_spawn_hook