Skip to content

Commit

Permalink
Use already-extant spawner's api object and its api_client attr
Browse files Browse the repository at this point in the history
  • Loading branch information
athornton committed Apr 1, 2022
1 parent 34df669 commit 0d88dc9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/nublado2/resourcemgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ async def _create_lab_environment_configmap(
async def _create_kubernetes_resources(
self, spawner: KubeSpawner, options: SelectedOptions
) -> None:
api_client = shared_client("ApiClient")
# This works around an infelicity in upstream Kubespawner's
# shared client implementation
api_client.api_client = api_client
custom_api = shared_client("CustomObjectsApi")
template_values = await self._build_template_values(spawner, options)

Expand Down Expand Up @@ -154,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 @@ -185,10 +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")
# This works around an infelicity in upstream Kubespawner's
# shared client implementation
api_client.api_client = api_client
dask_template = await spawner.get_pod_manifest()

# Here we make a few mangles to the jupyter pod manifest
Expand All @@ -210,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
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 0d88dc9

Please sign in to comment.