-
Notifications
You must be signed in to change notification settings - Fork 45
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
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -70,6 +69,21 @@ class SystemdSpawner(Spawner): | |
""" | ||
).tag(config=True) | ||
|
||
users_without_quotas = Set( | ||
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.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's put the help in triple quotes. |
||
).tag(config=True) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
# All traitlets configurables are configured by now | ||
|
@@ -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 | ||
|
@@ -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([ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 thatusers_without_quotas
isTrue
?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ! :)