将配置文件分配给白名单用户



我一直在探索kubespawner的配置文件列表功能,登录时会看到一个可用笔记本的列表。一切都很好。现在我有一个用例,用户A登录并看到笔记本1和2,用户B看到笔记本2和3。

是否可以将某些配置文件分配给特定用户?

我不认为Jupyterhub能够基于此实现https://zero-to-jupyterhub.readthedocs.io/en/latest/user-environment.html

我认为实现这一点的一种方法是使用不同的笔记本图像列表配置多个jupythub实例。基于类似AD组的东西,您可以将用户重定向到所需的实例,以便他们获得特定的图像选项。

您可以动态配置profile_list,为用户提供不同的图像配置文件。

这里有一个快速的例子:

@gen.coroutine
def get_profile_list(spawner):
"""get_profile_list is a hook function that is called before the spawner is started.
Args:
spawner (_type_): jupyterhub.spawner.Spawner instance
Yields:
list: list of profiles
"""
# gets the user's name from the auth_state
auth_state = yield spawner.user.get_auth_state()
if spawner.user.name:
# gets the user's profile list from the API
api_url = # Make a request
data_json = requests.get(url=api_url, verify=False).json()
data_json_str = str(data_json)
data_json_str = data_json_str.replace("'", '"')
data_json_str = data_json_str.replace("True", "true")
data_python = json.loads(data_json_str)
return data_python
return [] # return default profile
c.KubeSpawner.profile_list = get_profile_list

你可以让你的API返回一些类似的配置:

[
{
"display_name": "Google Cloud in us-central1",
"description": "Compute paid for by funder A, closest to dataset X",
"spawner_override": {
"kubernetes_context": "<kubernetes-context-name-for-this-cluster">,
"ingress_public_url": "http://<ingress-public-ip-for-this-cluster>"
}
},
{
"display_name": "AWS on us-east-1",
"description": "Compute paid for by funder B, closest to dataset Y",
"spawner_override": {
"kubernetes_context": "<kubernetes-context-name-for-this-cluster">,
"ingress_public_url": "http://<ingress-public-ip-for-this-cluster>",
"patches": {
"01-memory": """
kind: Pod
metadata:
name: {{key}}
spec:
containers:
- name: notebook
resources:
requests:
memory: 16Mi
""",
}
}
},
]

使用不同的图像,您可以分别为每个用户添加到笔记本中。

信用:https://multicluster-kubespawner.readthedocs.io/en/latest/profiles.html

最新更新