Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user specific quotas #26

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions systemdspawner/systemdspawner.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import pwd
import time
import subprocess
import shlex
from traitlets import Bool, Int, Unicode, List
from traitlets import Bool, Unicode, List, Dict, Set
from tornado import gen

from jupyterhub.spawner import Spawner
Expand Down Expand Up @@ -70,6 +69,21 @@ class SystemdSpawner(Spawner):
"""
).tag(config=True)

users_without_quotas = Set(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi and thanks for the PR :-)

Perhaps this would be better as a Bool similar to https://github.com/jupyterhub/jupyterhub/blob/master/jupyterhub/app.py#L453

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, in that case, we would enable this 'no quotas mode' for all user in the admin group ? So you want to check that the user is in Authenticator.admin_users and that users_without_quotas is True ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @RobinFrcd. I didn't mean to confuse. The overarching point that I'm trying to make (though not eloquently) is that any time a user (admin or otherwise) has the ability to use all the resources that should be an opt-in action instead of the default.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if a user is in users_without_quotas he has the ability to use all the resources. If he's not in, he can't. So the default is that a user can't use all the resources. I think I don't get the point here ! :)

None,
allow_none=True,
help='''
Set of users that will have unlimited mem_limit and cpu_limit, it will overwrite special_user_quotas even if
it's set for the user.
'''
).tag(config=True)

special_user_quotas = Dict(
None,
allow_none=True,
help='Dict with users as key and cpu_limit/mem_limit as value. It will overwrite mem_limit/cpu_limit.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put the help in triple quotes. help="""Dict with...

).tag(config=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# All traitlets configurables are configured by now
Expand All @@ -83,7 +97,6 @@ def __init__(self, *args, **kwargs):

self.log.debug('user:%s Initialized spawner with unit %s', self.user.name, self.unit_name)


def _expand_user_vars(self, string):
"""
Expand user related variables in a given string
Expand Down Expand Up @@ -180,6 +193,17 @@ def start(self):

cmd.append('--setenv=SHELL={shell}'.format(shell=self.default_shell))

if self.users_without_quotas and self.user.name in self.users_without_quotas:
# If users_without_quotas is set for the user, it will overwrite mem_limit and cpu_limit
self.mem_limit = None
self.cpu_limit = None
elif self.special_user_quotas and self.user.name in self.special_user_quotas:
# If the user has a specific value for mem_limit or cpu_limit, it will overwrite the default value
if 'mem_limit' in self.special_user_quotas[self.user.name]:
self.mem_limit = self.special_user_quotas[self.user.name]['mem_limit']
if 'cpu_limit' in self.special_user_quotas[self.user.name]:
self.cpu_limit = self.special_user_quotas[self.user.name]['cpu_limit']

if self.mem_limit is not None:
# FIXME: Detect & use proper properties for v1 vs v2 cgroups
cmd.extend([
Expand Down