-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use auto-port choosing on singleuser side
... if the kubespawner/port: auto annotation is set Signed-off-by: Thorsten Klein <[email protected]>
- Loading branch information
1 parent
9cb56d0
commit a1c22d4
Showing
10 changed files
with
159 additions
and
63 deletions.
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 |
---|---|---|
|
@@ -75,3 +75,6 @@ docs/source/build/ | |
|
||
# PyBuilder | ||
target/ | ||
|
||
# Pipenv | ||
Pipfile* |
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
from tornado import web | ||
from jupyterhub.apihandlers import APIHandler, default_handlers | ||
|
||
class KubeSpawnerAPIHandler(APIHandler): | ||
@web.authenticated | ||
def post(self): | ||
"""POST set user spawner data""" | ||
if hasattr(self, 'current_user'): | ||
# Jupyterhub compatability, (september 2018, d79a99323ef1d) | ||
user = self.current_user | ||
else: | ||
# Previous jupyterhub, 0.9.4 and before. | ||
user = self.get_current_user() | ||
token = self.get_auth_token() | ||
spawner = None | ||
for s in user.spawners.values(): | ||
if s.api_token == token: | ||
spawner = s | ||
break | ||
data = self.get_json_body() | ||
for key, value in data.items(): | ||
if hasattr(spawner, key): | ||
setattr(spawner, key, value) | ||
self.finish(json.dumps({"message": "KubeSpawner data configured"})) | ||
self.set_status(201) | ||
|
||
default_handlers.append((r"/api/kubespawner", KubeSpawnerAPIHandler)) |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
import sys | ||
|
||
from runpy import run_path | ||
from shutil import which | ||
|
||
from jupyterhub.utils import random_port, url_path_join | ||
from jupyterhub.services.auth import HubAuth | ||
|
||
def main(argv=None): | ||
port = random_port() | ||
hub_auth = HubAuth() | ||
hub_auth.client_ca = os.environ.get('JUPYTERHUB_SSL_CLIENT_CA', '') | ||
hub_auth.certfile = os.environ.get('JUPYTERHUB_SSL_CERTFILE', '') | ||
hub_auth.keyfile = os.environ.get('JUPYTERHUB_SSL_KEYFILE', '') | ||
hub_auth._api_request(method='POST', | ||
url=url_path_join(hub_auth.api_url, 'kubespawner'), | ||
json={'port' : port}) | ||
cmd_path = which(sys.argv[1]) | ||
sys.argv = sys.argv[1:] + ['--port={}'.format(port)] | ||
run_path(cmd_path, run_name="__main__") | ||
|
||
if __name__ == "__main__": | ||
main() |
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
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from kubespawner.autoport import main | ||
|
||
if __name__ == '__main__': | ||
main() |
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
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