Skip to content

Commit

Permalink
fix: do not add storage mounts patches when a session has no reposito…
Browse files Browse the repository at this point in the history
…ry (#1892)
  • Loading branch information
leafty authored May 28, 2024
1 parent 08162e4 commit 77b1ecc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
29 changes: 15 additions & 14 deletions renku_notebooks/api/amalthea_patches/cloudstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ def main(server: "UserServer") -> list[dict[str, Any]]:
f"{server.server_name}-ds-{i}", server.k8s_client.preferred_namespace
)
)
cloud_storage_patches.append(
{
"type": "application/json-patch+json",
"patch": [
{
"op": "add",
"path": "/statefulset/spec/template/spec/initContainers/2/env/-",
"value": {
"name": f"GIT_CLONE_STORAGE_MOUNTS_{i}",
"value": cloud_storage_request.mount_folder,
if server.repositories:
cloud_storage_patches.append(
{
"type": "application/json-patch+json",
"patch": [
{
"op": "add",
"path": "/statefulset/spec/template/spec/initContainers/2/env/-",
"value": {
"name": f"GIT_CLONE_STORAGE_MOUNTS_{i}",
"value": cloud_storage_request.mount_folder,
},
},
},
],
},
)
],
},
)
return cloud_storage_patches
3 changes: 3 additions & 0 deletions renku_notebooks/api/amalthea_patches/git_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@


def main(server: "UserServer"):
if server.user.anonymous or not server.repositories:
return []

etc_cert_volume_mount = get_certificates_volume_mounts(
custom_certs=False,
etc_certs=True,
Expand Down
2 changes: 2 additions & 0 deletions renku_notebooks/api/amalthea_patches/git_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def main(server: "UserServer"):
# NOTE: Sessions can be persisted only for registered users
if not isinstance(server.user, RegisteredUser):
return []
if not server.repositories:
return []

gitlab_project = getattr(server, "gitlab_project", None)
gl_project_path = gitlab_project.path if gitlab_project else None
Expand Down
3 changes: 3 additions & 0 deletions renku_notebooks/api/amalthea_patches/init_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@


def git_clone(server: "UserServer"):
if not server.repositories:
return []

etc_cert_volume_mount = get_certificates_volume_mounts(
custom_certs=False,
etc_certs=True,
Expand Down
12 changes: 3 additions & 9 deletions renku_notebooks/api/classes/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ def _get_renku_annotation_prefix() -> str:
return config.session_get_endpoint_annotations.renku_annotation_prefix

def _get_patches(self) -> list[dict[str, Any]]:
has_repository = bool(self.repositories)

return list(
chain(
general_patches.test(self),
Expand All @@ -308,19 +306,15 @@ def _get_patches(self) -> list[dict[str, Any]]:
jupyter_server_patches.disable_service_links(),
jupyter_server_patches.rstudio_env_variables(self),
jupyter_server_patches.user_secrets(self),
(
git_proxy_patches.main(self)
if has_repository and not self.user.anonymous
else []
),
git_sidecar_patches.main(self) if has_repository else [],
git_proxy_patches.main(self),
git_sidecar_patches.main(self),
general_patches.oidc_unverified_email(self),
ssh_patches.main(),
# init container for certs must come before all other init containers
# so that it runs first before all other init containers
init_containers_patches.certificates(),
init_containers_patches.download_image(self),
init_containers_patches.git_clone(self) if has_repository else [],
init_containers_patches.git_clone(self),
inject_certificates_patches.proxy(self),
# Cloud Storage needs to patch the git clone sidecar spec and so should come after
# the sidecars
Expand Down

0 comments on commit 77b1ecc

Please sign in to comment.