Skip to content

Commit

Permalink
Handle https-enabled JupyterHub deployments (#100)
Browse files Browse the repository at this point in the history
* Handle https-enabled JupyterHub deployments

As discovered in
pangeo-data/pangeo-cloud-federation#697, the
current use of `proxy-public` doesn't work when https is enabled. We
detect this and use the appropriate service now.
  • Loading branch information
TomAugspurger authored Aug 27, 2020
1 parent 212a802 commit 350b124
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion daskhub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ The following table lists the configurable parameters of the Daskhub chart and t
| Parameter | Description | Default |
| ------------------------ | ----------------------- | -------------- |
| `rbac.enabled` | Create and use roles and service accounts on an rbac-enabled cluster. | `true` |
| `jupyterhub.hub.extraConfig.00-add-dask-gateway-values` | | `"# 1. Sets `DASK_GATEWAY__PROXY_ADDRESS` in the singleuser environment.\n# 2. Adds the URL for the Dask Gateway JupyterHub service.\nimport os\n\n# These are set by jupyterhub.\nrelease_name = os.environ[\"HELM_RELEASE_NAME\"]\nrelease_namespace = os.environ[\"POD_NAMESPACE\"]\n\n# Internal address to connect to the Dask Gateway.\nc.KubeSpawner.environment.setdefault(\"DASK_GATEWAY__ADDRESS\", \"http://proxy-public/services/dask-gateway\")\n# Internal address for the Dask Gateway proxy.\nc.KubeSpawner.environment.setdefault(\"DASK_GATEWAY__PROXY_ADDRESS\", \"gateway://traefik-{}-dask-gateway.{}:80\".format(release_name, release_namespace))\n# Relative address for the dashboard link.\nc.KubeSpawner.environment.setdefault(\"DASK_GATEWAY__PUBLIC_ADDRESS\", \"/services/dask-gateway/\")\n# Use JupyterHub to authenticate with Dask Gateway.\nc.KubeSpawner.environment.setdefault(\"DASK_GATEWAY__AUTH__TYPE\", \"jupyterhub\")\n\n# Adds Dask Gateway as a JupyterHub service to make the gateway available at\n# {HUB_URL}/services/dask-gateway\nservice_url = \"http://traefik-{}-dask-gateway.{}\".format(release_name, release_namespace)\nfor service in c.JupyterHub.services:\n if service[\"name\"] == \"dask-gateway\":\n if not service.get(\"url\", None):\n print(\"Adding dask-gateway service URL\")\n service.setdefault(\"url\", service_url)\n break\nelse:\n print(\"dask-gateway service not found. Did you set jupyterhub.hub.services.dask-gateway.apiToken?\")\n"` |
| `jupyterhub.hub.extraConfig.00-add-dask-gateway-values` | | `"# 1. Sets `DASK_GATEWAY__PROXY_ADDRESS` in the singleuser environment.\n# 2. Adds the URL for the Dask Gateway JupyterHub service.\nimport os\n\n# These are set by jupyterhub.\nrelease_name = os.environ[\"HELM_RELEASE_NAME\"]\nrelease_namespace = os.environ[\"POD_NAMESPACE\"]\n\nif \"PROXY_HTTP_SERVICE_HOST\" in os.environ:\n # https is enabled, we want to use the internal http service.\n gateway_address = \"http://{}:{}/services/dask-gateway/\".format(\n os.environ[\"PROXY_HTTP_SERVICE_HOST\"],\n os.environ[\"PROXY_HTTP_SERVICE_PORT\"],\n )\n print(\"Setting DASK_GATEWAY__ADDRESS {} from HTTP service\".format(gateway_address))\nelse:\n gateway_address = \"http://proxy-public/services/dask-gateway\"\n print(\"Setting DASK_GATEWAY__ADDRESS {}\".format(gateway_address))\n\n# Internal address to connect to the Dask Gateway.\nc.KubeSpawner.environment.setdefault(\"DASK_GATEWAY__ADDRESS\", gateway_address)\n# Internal address for the Dask Gateway proxy.\nc.KubeSpawner.environment.setdefault(\"DASK_GATEWAY__PROXY_ADDRESS\", \"gateway://traefik-{}-dask-gateway.{}:80\".format(release_name, release_namespace))\n# Relative address for the dashboard link.\nc.KubeSpawner.environment.setdefault(\"DASK_GATEWAY__PUBLIC_ADDRESS\", \"/services/dask-gateway/\")\n# Use JupyterHub to authenticate with Dask Gateway.\nc.KubeSpawner.environment.setdefault(\"DASK_GATEWAY__AUTH__TYPE\", \"jupyterhub\")\n\n# Adds Dask Gateway as a JupyterHub service to make the gateway available at\n# {HUB_URL}/services/dask-gateway\nservice_url = \"http://traefik-{}-dask-gateway.{}\".format(release_name, release_namespace)\nfor service in c.JupyterHub.services:\n if service[\"name\"] == \"dask-gateway\":\n if not service.get(\"url\", None):\n print(\"Adding dask-gateway service URL\")\n service.setdefault(\"url\", service_url)\n break\nelse:\n print(\"dask-gateway service not found. Did you set jupyterhub.hub.services.dask-gateway.apiToken?\")\n"` |
| `jupyterhub.singleuser.image.name` | Image to use for singleuser environment. must include dask-gateyway. | `"pangeo/base-notebook"` |
| `jupyterhub.singleuser.image.tag` | | `"2020.07.28"` |
| `jupyterhub.singleuser.defaultUrl` | Use jupyterlab by defualt. | `"/lab"` |
Expand Down
13 changes: 12 additions & 1 deletion daskhub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,19 @@ jupyterhub:
release_name = os.environ["HELM_RELEASE_NAME"]
release_namespace = os.environ["POD_NAMESPACE"]
if "PROXY_HTTP_SERVICE_HOST" in os.environ:
# https is enabled, we want to use the internal http service.
gateway_address = "http://{}:{}/services/dask-gateway/".format(
os.environ["PROXY_HTTP_SERVICE_HOST"],
os.environ["PROXY_HTTP_SERVICE_PORT"],
)
print("Setting DASK_GATEWAY__ADDRESS {} from HTTP service".format(gateway_address))
else:
gateway_address = "http://proxy-public/services/dask-gateway"
print("Setting DASK_GATEWAY__ADDRESS {}".format(gateway_address))
# Internal address to connect to the Dask Gateway.
c.KubeSpawner.environment.setdefault("DASK_GATEWAY__ADDRESS", "http://proxy-public/services/dask-gateway")
c.KubeSpawner.environment.setdefault("DASK_GATEWAY__ADDRESS", gateway_address)
# Internal address for the Dask Gateway proxy.
c.KubeSpawner.environment.setdefault("DASK_GATEWAY__PROXY_ADDRESS", "gateway://traefik-{}-dask-gateway.{}:80".format(release_name, release_namespace))
# Relative address for the dashboard link.
Expand Down

0 comments on commit 350b124

Please sign in to comment.