Skip to content

Commit

Permalink
squashme: use default step statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
olevski committed Oct 6, 2022
1 parent 043276b commit a9515a5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 45 deletions.
7 changes: 5 additions & 2 deletions renku_notebooks/api/amalthea_patches/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ def test(server: "UserServer"):
to fail if the test statements are not correct. This is used to ensure that the
order of containers in the amalthea manifests is what the notebook service expects."""
patches = []
# NOTE: Only the first 1 or 2 containers come "included" from Amalthea, the rest are patched in
# This tests checks whether the expected number and order is received from Amalthea and
# does not use all containers.
container_names = (
config.sessions.container_order_registered
config.sessions.containers.registered[:2]
if type(server._user) is RegisteredUser
else config.sessions.container_order_anonymous
else config.sessions.containers.anonymous[:1]
)
for container_ind, container_name in enumerate(container_names):
patches.append(
Expand Down
72 changes: 44 additions & 28 deletions renku_notebooks/api/schemas/servers_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ServerStatusDetail(Schema):
step = fields.String(required=True)
status = fields.String(
required=True,
validate=validate.OneOf(ServerStatusEnum.list()),
validate=validate.OneOf(StepStatusEnum.list()),
)


Expand Down Expand Up @@ -248,14 +248,14 @@ def get_failed_containers(container_statuses):
]
return failed_containers

def get_starting_message(container_statuses):
containers_not_ready = [
container_status.get("name", "Unknown")
for container_status in container_statuses
if not container_status.get("ready", False)
def get_starting_message(step_summary):
steps_not_ready = [
step["step"].lower()
for step in step_summary
if step["status"] != StepStatusEnum.ready.value
]
if len(containers_not_ready) > 0:
return f"Containers with non-ready statuses: {', '.join(containers_not_ready)}."
if len(steps_not_ready) > 0:
return f"Steps with non-ready statuses: {', '.join(steps_not_ready)}."
return None

def get_status_breakdown(js):
Expand All @@ -282,6 +282,36 @@ def get_status_breakdown(js):
("jupyter-server", "Starting session"),
]
)
current_state = js.get("status", {}).get("state")
if (
current_state is None
or current_state == ServerStatusEnum.Starting.value
):
# NOTE: This means that the server is starting and the statuses are not populated
# yet, therefore in this case we will use defaults and set all statuses to waiting
if len(init_container_summary) == 0:
init_container_summary = {
container_name: StepStatusEnum.waiting.value
for container_name in config.sessions.init_containers
}
if len(container_summary) == 0:
annotations = js.get("metadata", {}).get("annotations", {})
prefix = (
config.session_get_endpoint_annotations.renku_annotation_prefix
)
is_user_anonymous = (
annotations.get(f"{prefix}userId", "").startswith("anon-")
and annotations.get(f"{prefix}username", "").startswith("anon-")
and js.get("metadata", {}).get("name", "").startswith("anon-")
)
container_summary = {
container_name: StepStatusEnum.waiting.value
for container_name in (
config.sessions.containers.anonymous
if is_user_anonymous
else config.sessions.containers.registered
)
}
for (container, desc) in init_container_name_desc_xref.items():
if container in init_container_summary:
output.append(
Expand Down Expand Up @@ -316,31 +346,17 @@ def get_status(js):
output["message"] = unschedulable_msg
else:
output["message"] = get_failed_message(failed_container_statuses)
output["details"] = get_status_breakdown(js)
if state == ServerStatusEnum.Starting.value:
output["message"] = get_starting_message(container_statuses)
container_summary = (
js.get("status", {}).get("containerStates", {}).get("regular", {})
)
init_container_summary = (
js.get("status", {}).get("containerStates", {}).get("init", {})
)
output["totalNumContainers"] = len(container_summary) + len(
init_container_summary
)
output["message"] = get_starting_message(output["details"])
output["totalNumContainers"] = len(output["details"])
output["readyNumContainers"] = len(
[
iname
for (iname, istate) in container_summary.items()
if istate in ["ready"]
]
) + len(
[
iname
for (iname, istate) in init_container_summary.items()
if istate in ["ready"]
step
for step in output["details"]
if step["status"] in [StepStatusEnum.ready.value]
]
)
output["details"] = get_status_breakdown(js)
return output

def get_resource_requests(server):
Expand Down
20 changes: 13 additions & 7 deletions renku_notebooks/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,26 @@ def get_config(default_config: str) -> _NotebooksConfig:
storage {
pvs_enabled: true
}
containers {
anonymous = [
jupyter-server,
passthrough-proxy,
git-proxy,
]
registered = [
jupyter-server,
oauth2-proxy,
git-proxy,
git-sidecar,
]
}
enforce_cpu_limits: false
autosave_minimum_lfs_file_size_bytes: 1000000
termination_grace_period_seconds: 600
image_default_workdir: /home/jovyan
node_selector: "{}"
affinity: "{}"
tolerations: "[]"
container_order_anonymous = [
jupyter-server
]
container_order_registered = [
jupyter-server
oauth2-proxy
]
}
amalthea {
group = amalthea.dev
Expand Down
19 changes: 11 additions & 8 deletions renku_notebooks/config/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ class _SessionCullingConfig:
registered: _GenericCullingConfig


@dataclass
class _SessionContainers:
anonymous: List[Text]
registered: List[Text]


@dataclass
class _SessionConfig:
culling: _SessionCullingConfig
Expand All @@ -182,6 +188,7 @@ class _SessionConfig:
ca_certs: _CustomCaCertsConfig
oidc: _SessionOidcConfig
storage: _SessionStorageConfig
containers: _SessionContainers
default_image: Text = "renku/singleuser:latest"
enforce_cpu_limits: Union[Text, bool] = False
autosave_minimum_lfs_file_size_bytes: Union[int, Text] = 1000000
Expand All @@ -190,15 +197,11 @@ class _SessionConfig:
node_selector: Text = "{}"
affinity: Text = "{}"
tolerations: Text = "[]"
container_order_anonymous: List[Text] = field(
default_factory=lambda: [
"jupyter-server",
]
)
container_order_registered: List[Text] = field(
init_containers: List[Text] = field(
default_factory=lambda: [
"jupyter-server",
"oauth2-proxy",
"init-certificates",
"download-image",
"git-clone",
]
)

Expand Down

0 comments on commit a9515a5

Please sign in to comment.