{"action":"created","comment":{"url":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/comments/144370163","pull_request_review_id":68912359,"id":144370163,"diff_hunk":"@@ -0,0 +1,244 @@\n+import os\n+import string\n+import escapism\n+import json\n+from kubernetes import client\n+\n+from jupyterhub.proxy import Proxy\n+from jupyterhub.utils import exponential_backoff\n+\n+from kubespawner.objects import make_ingress\n+from kubespawner.utils import generate_hashed_slug\n+from kubespawner.reflector import NamespacedResourceReflector\n+from concurrent.futures import ThreadPoolExecutor\n+from traitlets import Unicode\n+from tornado import gen\n+from tornado.concurrent import run_on_executor\n+\n+\n+class IngressReflector(NamespacedResourceReflector):\n+    kind = 'ingresses'\n+    labels = {\n+        'heritage': 'jupyterhub',\n+        'component': 'singleuser-server',\n+        'hub.jupyter.org/proxy-route': 'true'\n+    }\n+\n+    list_method_name = 'list_namespaced_ingress'\n+    api_group_name = 'ExtensionsV1beta1Api'\n+\n+    @property\n+    def ingresses(self):\n+        return self.resources\n+\n+class ServiceReflector(NamespacedResourceReflector):\n+    kind = 'services'\n+    labels = {\n+        'heritage': 'jupyterhub',\n+        'component': 'singleuser-server',\n+        'hub.jupyter.org/proxy-route': 'true'\n+    }\n+\n+    list_method_name = 'list_namespaced_service'\n+\n+    @property\n+    def services(self):\n+        return self.resources\n+\n+class EndpointsReflector(NamespacedResourceReflector):\n+    kind = 'endpoints'\n+    labels = {\n+        'heritage': 'jupyterhub',\n+        'component': 'singleuser-server',\n+        'hub.jupyter.org/proxy-route': 'true'\n+    }\n+\n+    list_method_name = 'list_namespaced_endpoints'\n+\n+    @property\n+    def endpoints(self):\n+        return self.resources\n+\n+class KubeIngressProxy(Proxy):\n+    namespace = Unicode(\n+        config=True,\n+        help=\"\"\"\n+        Kubernetes namespace to spawn ingresses for single-user servers in.\n+\n+        If running inside a kubernetes cluster with service accounts enabled,\n+        defaults to the current namespace. If not, defaults to 'default'\n+        \"\"\"\n+    )\n+\n+    def _namespace_default(self):\n+        \"\"\"\n+        Set namespace default to current namespace if running in a k8s cluster\n+\n+        If not in a k8s cluster with service accounts enabled, default to\n+        'default'\n+        \"\"\"\n+        ns_path = '/var/run/secrets/kubernetes.io/serviceaccount/namespace'\n+        if os.path.exists(ns_path):\n+            with open(ns_path) as f:\n+                return f.read().strip()\n+        return 'default'\n+\n+    def __init__(self, *args, **kwargs):\n+        super().__init__(*args, **kwargs)\n+\n+        # We want 3x concurrent spawn limit as our threadpool. This means that if","path":"kubespawner/proxy.py","position":89,"original_position":89,"commit_id":"e1dd7418c0ba5a6c85f925c1789f6a33a3a20209","original_commit_id":"e1dd7418c0ba5a6c85f925c1789f6a33a3a20209","user":{"login":"minrk","id":151929,"avatar_url":"https://avatars1.githubusercontent.com/u/151929?v=4","gravatar_id":"","url":"https://api.github.com/users/minrk","html_url":"https://github.com/minrk","followers_url":"https://api.github.com/users/minrk/followers","following_url":"https://api.github.com/users/minrk/following{/other_user}","gists_url":"https://api.github.com/users/minrk/gists{/gist_id}","starred_url":"https://api.github.com/users/minrk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minrk/subscriptions","organizations_url":"https://api.github.com/users/minrk/orgs","repos_url":"https://api.github.com/users/minrk/repos","events_url":"https://api.github.com/users/minrk/events{/privacy}","received_events_url":"https://api.github.com/users/minrk/received_events","type":"User","site_admin":false},"body":"Maybe use 1x instead of 3x? It seems okay when hitting capacity to allow a single spawn's requests to serialize. It doesn't seem important that all possible requests are in flight at once.","created_at":"2017-10-12T18:19:40Z","updated_at":"2017-10-12T18:22:47Z","html_url":"https://github.com/jupyterhub/kubespawner/pull/64#discussion_r144370163","pull_request_url":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/64","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/comments/144370163"},"html":{"href":"https://github.com/jupyterhub/kubespawner/pull/64#discussion_r144370163"},"pull_request":{"href":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/64"}},"in_reply_to_id":143347137},"pull_request":{"url":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/64","id":131726123,"html_url":"https://github.com/jupyterhub/kubespawner/pull/64","diff_url":"https://github.com/jupyterhub/kubespawner/pull/64.diff","patch_url":"https://github.com/jupyterhub/kubespawner/pull/64.patch","issue_url":"https://api.github.com/repos/jupyterhub/kubespawner/issues/64","number":64,"state":"open","locked":false,"title":"Add a Kubernetes Ingress based Proxy implementation","user":{"login":"yuvipanda","id":30430,"avatar_url":"https://avatars2.githubusercontent.com/u/30430?v=4","gravatar_id":"","url":"https://api.github.com/users/yuvipanda","html_url":"https://github.com/yuvipanda","followers_url":"https://api.github.com/users/yuvipanda/followers","following_url":"https://api.github.com/users/yuvipanda/following{/other_user}","gists_url":"https://api.github.com/users/yuvipanda/gists{/gist_id}","starred_url":"https://api.github.com/users/yuvipanda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuvipanda/subscriptions","organizations_url":"https://api.github.com/users/yuvipanda/orgs","repos_url":"https://api.github.com/users/yuvipanda/repos","events_url":"https://api.github.com/users/yuvipanda/events{/privacy}","received_events_url":"https://api.github.com/users/yuvipanda/received_events","type":"User","site_admin":false},"body":"You need an ingress controller set up to be able to use it. Simplest is the traefik one, which you can install with:\r\n\r\n```\r\nhelm install stable/traefik --namespace=kube-system --name=ingress\r\n```","created_at":"2017-07-21T08:48:27Z","updated_at":"2017-10-12T18:22:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6f5172ff40079410f6e1842934df79b116ab2596","assignee":null,"assignees":[],"requested_reviewers":[{"login":"willingc","id":2680980,"avatar_url":"https://avatars3.githubusercontent.com/u/2680980?v=4","gravatar_id":"","url":"https://api.github.com/users/willingc","html_url":"https://github.com/willingc","followers_url":"https://api.github.com/users/willingc/followers","following_url":"https://api.github.com/users/willingc/following{/other_user}","gists_url":"https://api.github.com/users/willingc/gists{/gist_id}","starred_url":"https://api.github.com/users/willingc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willingc/subscriptions","organizations_url":"https://api.github.com/users/willingc/orgs","repos_url":"https://api.github.com/users/willingc/repos","events_url":"https://api.github.com/users/willingc/events{/privacy}","received_events_url":"https://api.github.com/users/willingc/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/64/commits","review_comments_url":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/64/comments","review_comment_url":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jupyterhub/kubespawner/issues/64/comments","statuses_url":"https://api.github.com/repos/jupyterhub/kubespawner/statuses/e1dd7418c0ba5a6c85f925c1789f6a33a3a20209","head":{"label":"jupyterhub:kubeproxy","ref":"kubeproxy","sha":"e1dd7418c0ba5a6c85f925c1789f6a33a3a20209","user":{"login":"jupyterhub","id":17927519,"avatar_url":"https://avatars2.githubusercontent.com/u/17927519?v=4","gravatar_id":"","url":"https://api.github.com/users/jupyterhub","html_url":"https://github.com/jupyterhub","followers_url":"https://api.github.com/users/jupyterhub/followers","following_url":"https://api.github.com/users/jupyterhub/following{/other_user}","gists_url":"https://api.github.com/users/jupyterhub/gists{/gist_id}","starred_url":"https://api.github.com/users/jupyterhub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jupyterhub/subscriptions","organizations_url":"https://api.github.com/users/jupyterhub/orgs","repos_url":"https://api.github.com/users/jupyterhub/repos","events_url":"https://api.github.com/users/jupyterhub/events{/privacy}","received_events_url":"https://api.github.com/users/jupyterhub/received_events","type":"Organization","site_admin":false},"repo":{"id":46604988,"name":"kubespawner","full_name":"jupyterhub/kubespawner","owner":{"login":"jupyterhub","id":17927519,"avatar_url":"https://avatars2.githubusercontent.com/u/17927519?v=4","gravatar_id":"","url":"https://api.github.com/users/jupyterhub","html_url":"https://github.com/jupyterhub","followers_url":"https://api.github.com/users/jupyterhub/followers","following_url":"https://api.github.com/users/jupyterhub/following{/other_user}","gists_url":"https://api.github.com/users/jupyterhub/gists{/gist_id}","starred_url":"https://api.github.com/users/jupyterhub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jupyterhub/subscriptions","organizations_url":"https://api.github.com/users/jupyterhub/orgs","repos_url":"https://api.github.com/users/jupyterhub/repos","events_url":"https://api.github.com/users/jupyterhub/events{/privacy}","received_events_url":"https://api.github.com/users/jupyterhub/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jupyterhub/kubespawner","description":"Kubernetes spawner for JupyterHub","fork":false,"url":"https://api.github.com/repos/jupyterhub/kubespawner","forks_url":"https://api.github.com/repos/jupyterhub/kubespawner/forks","keys_url":"https://api.github.com/repos/jupyterhub/kubespawner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jupyterhub/kubespawner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jupyterhub/kubespawner/teams","hooks_url":"https://api.github.com/repos/jupyterhub/kubespawner/hooks","issue_events_url":"https://api.github.com/repos/jupyterhub/kubespawner/issues/events{/number}","events_url":"https://api.github.com/repos/jupyterhub/kubespawner/events","assignees_url":"https://api.github.com/repos/jupyterhub/kubespawner/assignees{/user}","branches_url":"https://api.github.com/repos/jupyterhub/kubespawner/branches{/branch}","tags_url":"https://api.github.com/repos/jupyterhub/kubespawner/tags","blobs_url":"https://api.github.com/repos/jupyterhub/kubespawner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jupyterhub/kubespawner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jupyterhub/kubespawner/git/refs{/sha}","trees_url":"https://api.github.com/repos/jupyterhub/kubespawner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jupyterhub/kubespawner/statuses/{sha}","languages_url":"https://api.github.com/repos/jupyterhub/kubespawner/languages","stargazers_url":"https://api.github.com/repos/jupyterhub/kubespawner/stargazers","contributors_url":"https://api.github.com/repos/jupyterhub/kubespawner/contributors","subscribers_url":"https://api.github.com/repos/jupyterhub/kubespawner/subscribers","subscription_url":"https://api.github.com/repos/jupyterhub/kubespawner/subscription","commits_url":"https://api.github.com/repos/jupyterhub/kubespawner/commits{/sha}","git_commits_url":"https://api.github.com/repos/jupyterhub/kubespawner/git/commits{/sha}","comments_url":"https://api.github.com/repos/jupyterhub/kubespawner/comments{/number}","issue_comment_url":"https://api.github.com/repos/jupyterhub/kubespawner/issues/comments{/number}","contents_url":"https://api.github.com/repos/jupyterhub/kubespawner/contents/{+path}","compare_url":"https://api.github.com/repos/jupyterhub/kubespawner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jupyterhub/kubespawner/merges","archive_url":"https://api.github.com/repos/jupyterhub/kubespawner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jupyterhub/kubespawner/downloads","issues_url":"https://api.github.com/repos/jupyterhub/kubespawner/issues{/number}","pulls_url":"https://api.github.com/repos/jupyterhub/kubespawner/pulls{/number}","milestones_url":"https://api.github.com/repos/jupyterhub/kubespawner/milestones{/number}","notifications_url":"https://api.github.com/repos/jupyterhub/kubespawner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jupyterhub/kubespawner/labels{/name}","releases_url":"https://api.github.com/repos/jupyterhub/kubespawner/releases{/id}","deployments_url":"https://api.github.com/repos/jupyterhub/kubespawner/deployments","created_at":"2015-11-21T07:02:52Z","updated_at":"2017-10-12T05:07:17Z","pushed_at":"2017-10-08T05:10:16Z","git_url":"git://github.com/jupyterhub/kubespawner.git","ssh_url":"git@github.com:jupyterhub/kubespawner.git","clone_url":"https://github.com/jupyterhub/kubespawner.git","svn_url":"https://github.com/jupyterhub/kubespawner","homepage":null,"size":258,"stargazers_count":70,"watchers_count":70,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":20,"forks":44,"open_issues":20,"watchers":70,"default_branch":"master"}},"base":{"label":"jupyterhub:master","ref":"master","sha":"5ed86f1a0e9d13865718e1632fe40f447b6d4c2c","user":{"login":"jupyterhub","id":17927519,"avatar_url":"https://avatars2.githubusercontent.com/u/17927519?v=4","gravatar_id":"","url":"https://api.github.com/users/jupyterhub","html_url":"https://github.com/jupyterhub","followers_url":"https://api.github.com/users/jupyterhub/followers","following_url":"https://api.github.com/users/jupyterhub/following{/other_user}","gists_url":"https://api.github.com/users/jupyterhub/gists{/gist_id}","starred_url":"https://api.github.com/users/jupyterhub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jupyterhub/subscriptions","organizations_url":"https://api.github.com/users/jupyterhub/orgs","repos_url":"https://api.github.com/users/jupyterhub/repos","events_url":"https://api.github.com/users/jupyterhub/events{/privacy}","received_events_url":"https://api.github.com/users/jupyterhub/received_events","type":"Organization","site_admin":false},"repo":{"id":46604988,"name":"kubespawner","full_name":"jupyterhub/kubespawner","owner":{"login":"jupyterhub","id":17927519,"avatar_url":"https://avatars2.githubusercontent.com/u/17927519?v=4","gravatar_id":"","url":"https://api.github.com/users/jupyterhub","html_url":"https://github.com/jupyterhub","followers_url":"https://api.github.com/users/jupyterhub/followers","following_url":"https://api.github.com/users/jupyterhub/following{/other_user}","gists_url":"https://api.github.com/users/jupyterhub/gists{/gist_id}","starred_url":"https://api.github.com/users/jupyterhub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jupyterhub/subscriptions","organizations_url":"https://api.github.com/users/jupyterhub/orgs","repos_url":"https://api.github.com/users/jupyterhub/repos","events_url":"https://api.github.com/users/jupyterhub/events{/privacy}","received_events_url":"https://api.github.com/users/jupyterhub/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jupyterhub/kubespawner","description":"Kubernetes spawner for JupyterHub","fork":false,"url":"https://api.github.com/repos/jupyterhub/kubespawner","forks_url":"https://api.github.com/repos/jupyterhub/kubespawner/forks","keys_url":"https://api.github.com/repos/jupyterhub/kubespawner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jupyterhub/kubespawner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jupyterhub/kubespawner/teams","hooks_url":"https://api.github.com/repos/jupyterhub/kubespawner/hooks","issue_events_url":"https://api.github.com/repos/jupyterhub/kubespawner/issues/events{/number}","events_url":"https://api.github.com/repos/jupyterhub/kubespawner/events","assignees_url":"https://api.github.com/repos/jupyterhub/kubespawner/assignees{/user}","branches_url":"https://api.github.com/repos/jupyterhub/kubespawner/branches{/branch}","tags_url":"https://api.github.com/repos/jupyterhub/kubespawner/tags","blobs_url":"https://api.github.com/repos/jupyterhub/kubespawner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jupyterhub/kubespawner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jupyterhub/kubespawner/git/refs{/sha}","trees_url":"https://api.github.com/repos/jupyterhub/kubespawner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jupyterhub/kubespawner/statuses/{sha}","languages_url":"https://api.github.com/repos/jupyterhub/kubespawner/languages","stargazers_url":"https://api.github.com/repos/jupyterhub/kubespawner/stargazers","contributors_url":"https://api.github.com/repos/jupyterhub/kubespawner/contributors","subscribers_url":"https://api.github.com/repos/jupyterhub/kubespawner/subscribers","subscription_url":"https://api.github.com/repos/jupyterhub/kubespawner/subscription","commits_url":"https://api.github.com/repos/jupyterhub/kubespawner/commits{/sha}","git_commits_url":"https://api.github.com/repos/jupyterhub/kubespawner/git/commits{/sha}","comments_url":"https://api.github.com/repos/jupyterhub/kubespawner/comments{/number}","issue_comment_url":"https://api.github.com/repos/jupyterhub/kubespawner/issues/comments{/number}","contents_url":"https://api.github.com/repos/jupyterhub/kubespawner/contents/{+path}","compare_url":"https://api.github.com/repos/jupyterhub/kubespawner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jupyterhub/kubespawner/merges","archive_url":"https://api.github.com/repos/jupyterhub/kubespawner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jupyterhub/kubespawner/downloads","issues_url":"https://api.github.com/repos/jupyterhub/kubespawner/issues{/number}","pulls_url":"https://api.github.com/repos/jupyterhub/kubespawner/pulls{/number}","milestones_url":"https://api.github.com/repos/jupyterhub/kubespawner/milestones{/number}","notifications_url":"https://api.github.com/repos/jupyterhub/kubespawner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jupyterhub/kubespawner/labels{/name}","releases_url":"https://api.github.com/repos/jupyterhub/kubespawner/releases{/id}","deployments_url":"https://api.github.com/repos/jupyterhub/kubespawner/deployments","created_at":"2015-11-21T07:02:52Z","updated_at":"2017-10-12T05:07:17Z","pushed_at":"2017-10-08T05:10:16Z","git_url":"git://github.com/jupyterhub/kubespawner.git","ssh_url":"git@github.com:jupyterhub/kubespawner.git","clone_url":"https://github.com/jupyterhub/kubespawner.git","svn_url":"https://github.com/jupyterhub/kubespawner","homepage":null,"size":258,"stargazers_count":70,"watchers_count":70,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":20,"forks":44,"open_issues":20,"watchers":70,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/64"},"html":{"href":"https://github.com/jupyterhub/kubespawner/pull/64"},"issue":{"href":"https://api.github.com/repos/jupyterhub/kubespawner/issues/64"},"comments":{"href":"https://api.github.com/repos/jupyterhub/kubespawner/issues/64/comments"},"review_comments":{"href":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/64/comments"},"review_comment":{"href":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jupyterhub/kubespawner/pulls/64/commits"},"statuses":{"href":"https://api.github.com/repos/jupyterhub/kubespawner/statuses/e1dd7418c0ba5a6c85f925c1789f6a33a3a20209"}},"author_association":"OWNER"}}
{"actor":{"display_login":"minrk"}}