Skip to content

Commit

Permalink
Initial attempt to prove functions work
Browse files Browse the repository at this point in the history
  • Loading branch information
costrouc committed Jul 6, 2022
1 parent 8246d35 commit a457df7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
pythonPackages.bcrypt
pythonPackages.kubernetes
pythonPackages.packaging
pythonPackages.rich
keycloak

# cloud packages
Expand All @@ -40,6 +41,7 @@
pythonPackages.dask-gateway
pythonPackages.paramiko
pythonPackages.escapism
pythonPackages.isort

# additional
pkgs.minikube
Expand Down
2 changes: 1 addition & 1 deletion qhub/template/image/jupyterhub/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- jupyterhub-kubespawner==1.1.0
- oauthenticator==14.1.0
- escapism==1.0.1
- cdsdashboards==0.6.1
- cdsdashboards==0.6.2
- jupyterhub-idle-culler==1.0
- pip:
- qhub-jupyterhub-theme==0.3.5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# remove after next kubespawner release past 1/20/2022
# /~https://github.com/jupyterhub/kubespawner/pull/558
import json
import os

import kubernetes.client.models
from tornado import gen

kubernetes.client.models.V1EndpointPort = kubernetes.client.models.CoreV1EndpointPort

import z2jh # noqa: E402
from kubespawner import KubeSpawner # noqa: E402
from tornado import gen

cdsdashboards = z2jh.get_config("custom.cdsdashboards")
conda_store_environments = z2jh.get_config("custom.environments")


@gen.coroutine
Expand Down Expand Up @@ -49,9 +43,46 @@ def get_username_hook(spawner):
# Force dashboard creator to select an instance size
c.CDSDashboardsConfig.spawn_default_options = False

c.CDSDashboardsConfig.conda_envs = [
environment["name"] for _, environment in conda_store_environments.items()
]
def get_packages(conda_prefix):
try:
packages = set()
for filename in os.listdir(os.path.join(conda_prefix, "conda-meta")):
if filename.endswith(".json"):
with open(os.path.join(conda_prefix, "conda-meta", filename)) as f:
packages.add(json.load(f).get("name"))
return packages
except OSError as e:
import logging

logger = logging.getLogger()
logger.error(f"An issue with a conda environment was encountered.\n{e}")

def get_conda_prefixes(conda_store_mount):
for namespace in os.listdir(conda_store_mount):
if os.path.isdir(os.path.join(conda_store_mount, namespace, "envs")):
for name in os.listdir(
os.path.join(conda_store_mount, namespace, "envs")
):
yield namespace, name, os.path.join(
conda_store_mount, namespace, "envs", name
)

def list_dashboard_environments(conda_store_mount):
for namespace, name, conda_prefix in get_conda_prefixes(conda_store_mount):
packages = get_packages(conda_prefix)
if packages and {"cdsdashboards-singleuser"} <= packages:
yield namespace, name, conda_prefix

def conda_environments():
conda_store_mount = z2jh.get_config("custom.conda-store-mount")
return [
name
for namespace, name, conda_prefix in list_dashboard_environments(
conda_store_mount
)
]

c.CDSDashboardsConfig.conda_envs = conda_environments

# TODO: make timeouts configurable
c.VariableMixin.proxy_ready_timeout = 600
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ resource "helm_release" "jupyterhub" {
"${var.general-node-group.key}" = var.general-node-group.value
}

extraVolumes = [{
name = "conda-store-shared"
persistentVolumeClaim = {
claimName = var.conda-store-pvc
}
}]

extraVolumeMounts = [{
mountPath = var.conda-store-mount
name = "conda-store-shared"
}]

extraConfig = {
"01-theme.py" = file("${path.module}/files/jupyterhub/01-theme.py")
"02-spawner.py" = file("${path.module}/files/jupyterhub/02-spawner.py")
Expand Down

0 comments on commit a457df7

Please sign in to comment.