Skip to content

Commit

Permalink
Merge pull request #133 from lsst-sqre/tickets/DM-34218
Browse files Browse the repository at this point in the history
tickets/DM-34218: expand user reset env beyond .local
  • Loading branch information
athornton authored Apr 1, 2022
2 parents be3bd3c + 0d88dc9 commit 9bf2e6b
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- toml

- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- id: black

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM jupyterhub/jupyterhub:2.1.1 as base-image
FROM jupyterhub/jupyterhub:2.2.0 as base-image

# Update system packages
COPY scripts/install-base-packages.sh .
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: update-deps
update-deps:
pip install --upgrade pip-tools 'pip<22' setuptools
pip install --upgrade pip-tools pip setuptools
pip-compile --upgrade --build-isolation --generate-hashes --output-file requirements/main.txt requirements/main.in
pip-compile --upgrade --build-isolation --generate-hashes --output-file requirements/dev.txt requirements/dev.in

Expand Down
3 changes: 2 additions & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with python 3.10
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
#
# pip-compile --generate-hashes --output-file=requirements/dev.txt requirements/dev.in
Expand Down Expand Up @@ -374,6 +374,7 @@ pytest==7.1.1 \
# -r requirements/dev.in
# pytest-asyncio
pytest-asyncio==0.18.3 \
--hash=sha256:16cf40bdf2b4fb7fc8e4b82bd05ce3fbcd454cbf7b92afc445fe299dabb88213 \
--hash=sha256:7659bdb0a9eb9c6e3ef992eef11a2b3e69697800ad02fb06374a210d85b29f91 \
--hash=sha256:8fafa6c52161addfd41ee7ab35f11836c5a16ec208f93ee388f752bea3493a84
# via -r requirements/dev.in
Expand Down
12 changes: 4 additions & 8 deletions requirements/main.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ jupyterhub-idle-culler
psycopg2
ruamel.yaml
tornado

kubernetes-asyncio

# Until changes are accepted upstream and a new kubespawner release happens:
rubin-kubespawner
# Until z2jh adopts kubespawner-asyncio:
kubernetes
jupyterhub-kubespawner

# Always pin jupyterhub to a specific version. We don't want it to be
# upgraded without our explicit approval, and it should be upgraded in
# lockstep with the base image in Dockerfile.
jupyterhub==2.1.1
# lockstep with the base image in Dockerfile and with the app version
# in the JupyterHub helm chart (https://jupyterhub.github.io/helm-chart/)
jupyterhub==2.2.0

# Required by alembic for Python 3.8, so install it unconditionally until
# Python 3.8 support is dropped so that we have consistent dependencies.
Expand Down
162 changes: 59 additions & 103 deletions requirements/main.txt

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/nublado2/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
name="enable_debug" value="true">
<label for="enable_debug">Enable debug logs</label><br />
<input type="checkbox" id="clear_dotlocal"
name="clear_dotlocal" value="true">
<label for="clear_dotlocal">
Clear <tt>.local</tt> directory (caution!)
<input type="checkbox" id="reset_user_env"
name="reset_user_env" value="true">
<label for="reset_user_env">
Reset user environment: relocate .cache, .jupyter, and .local
</label><br />
</div>
</td>
Expand Down
13 changes: 2 additions & 11 deletions src/nublado2/resourcemgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,11 @@ def __init__(self) -> None:
self.provisioner = Provisioner()
self.yaml = YAML()
self.yaml.indent(mapping=2, sequence=4, offset=2)
# You can't create the shared_clients here; they fail to
# serialize and the Hub won't start.

async def create_user_resources(
self, spawner: KubeSpawner, options: SelectedOptions
) -> None:
"""Create the user resources for this spawning session."""
# This actually gets called in a pre-spawn hook, which means no one
# has yet called start() or poll() on the spawner, which means
# we need to initialize its resources (particularly its API
# client) ourselves.
await spawner.initialize_reflectors_and_clients()
await self.provisioner.provision_homedir(spawner)
try:
await exponential_backoff(
Expand Down Expand Up @@ -118,7 +111,6 @@ async def _create_lab_environment_configmap(
async def _create_kubernetes_resources(
self, spawner: KubeSpawner, options: SelectedOptions
) -> None:
api_client = shared_client("ApiClient")
custom_api = shared_client("CustomObjectsApi")
template_values = await self._build_template_values(spawner, options)

Expand Down Expand Up @@ -158,7 +150,7 @@ async def _create_kubernetes_resources(
)
else:
await asyncio.wait_for(
create_from_dict(api_client, resource),
create_from_dict(spawner.api.api_client, resource),
spawner.k8s_api_request_timeout,
)

Expand Down Expand Up @@ -189,7 +181,6 @@ async def _create_kubernetes_resources(

async def _build_dask_template(self, spawner: KubeSpawner) -> str:
"""Build a template for dask workers from the jupyter pod manifest."""
api_client = shared_client("ApiClient")
dask_template = await spawner.get_pod_manifest()

# Here we make a few mangles to the jupyter pod manifest
Expand All @@ -211,7 +202,7 @@ async def _build_dask_template(self, spawner: KubeSpawner) -> str:
# alone doesn't.
dask_yaml_stream = StringIO()
self.yaml.dump(
api_client.sanitize_for_serialization(dask_template),
spawner.api.api_client.sanitize_for_serialization(dask_template),
dask_yaml_stream,
)
return dask_yaml_stream.getvalue()
Expand Down
13 changes: 7 additions & 6 deletions src/nublado2/selectedoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, options: Dict[str, Any]) -> None:
self._size = nc.sizes[size_name]

self._debug = "TRUE" if "enable_debug" in options else ""
self._clear_dotlocal = "TRUE" if "clear_dotlocal" in options else ""
self._reset_user_env = "TRUE" if "reset_user_env" in options else ""

@property
def debug(self) -> str:
Expand All @@ -43,12 +43,13 @@ def debug(self) -> str:
return self._debug

@property
def clear_dotlocal(self) -> str:
"""String to pass in for CLEAR_DOTLOCAL variable in the lab.
def reset_user_env(self) -> str:
"""String to pass in for RESET_USER_ENV variable in the lab.
This gets rid of the user's .local directory which may
cause issues during startup."""
return self._clear_dotlocal
This moves the user's .local, .cache, and .jupyter environments
aside. That in turn allows getting out of the common case where
local package installation conflicts with the RSP machinery."""
return self._reset_user_env

@property
def image_info(self) -> ImageInfo:
Expand Down
1 change: 1 addition & 0 deletions tests/resourcemgr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ async def test_create_kubernetes_resources(
spawner.hub.base_url = "/nb/hub/"
spawner.user = Mock(spec=User)
spawner.user.name = "someuser"
spawner.api = kubernetes_api_mock
auth_state = {
"token": "user-token",
"uid": 1234,
Expand Down

0 comments on commit 9bf2e6b

Please sign in to comment.