Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly use gevent and allow configuring k8s cache bypass #1996

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ ignore = [

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["D"]
"renku_notebooks/__init__.py" = ["E402"]

[tool.ruff.lint.pydocstyle]
convention = "google"
Expand Down
4 changes: 4 additions & 0 deletions renku_notebooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
# limitations under the License.
"""Notebooks service flask app."""

from gevent import monkey

monkey.patch_all()

import os

from apispec import APISpec
Expand Down
6 changes: 6 additions & 0 deletions renku_notebooks/api/classes/k8s_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,13 @@ def __init__(
renku_ns_client: NamespacedK8sClient,
username_label: str,
session_ns_client: Optional[NamespacedK8sClient] = None,
bypass_cache_on_failure: bool = True,
):
self.js_cache = js_cache
self.renku_ns_client = renku_ns_client
self.username_label = username_label
self.session_ns_client = session_ns_client
self.bypass_cache_on_failure = bypass_cache_on_failure
if not self.username_label:
raise ProgrammingError("username_label has to be provided to K8sClient")

Expand All @@ -421,6 +423,8 @@ def list_servers(self, safe_username: str) -> list[dict[str, Any]]:
try:
return self.js_cache.list_servers(safe_username)
except JSCacheError:
if not self.bypass_cache_on_failure:
raise
logging.warning(f"Skipping the cache to list servers for user: {safe_username}")
label_selector = f"{self.username_label}={safe_username}"
return self.renku_ns_client.list_servers(label_selector) + (
Expand All @@ -436,6 +440,8 @@ def get_server(self, name: str, safe_username: str) -> Optional[dict[str, Any]]:
try:
server = self.js_cache.get_server(name)
except JSCacheError:
if not self.bypass_cache_on_failure:
raise
output = []
res = None
if self.session_ns_client is not None:
Expand Down
5 changes: 2 additions & 3 deletions renku_notebooks/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def __post_init__(self):
renku_ns_client=renku_ns_client,
session_ns_client=session_ns_client,
username_label=username_label,
bypass_cache_on_failure=self.k8s.bypass_cache_on_failure,
)
self._crc_validator = None
self._storage_validator = None
Expand Down Expand Up @@ -160,9 +161,7 @@ def get_config(default_config: str) -> _NotebooksConfig:
config = dataconf.multi.string(default_config)
if config_file:
config = config.file(config_file)
notebooks_config: _NotebooksConfig = config.env("NB_", ignore_unexpected=True).on(
_NotebooksConfig
)
notebooks_config: _NotebooksConfig = config.env("NB_", ignore_unexpected=True).on(_NotebooksConfig)
return notebooks_config


Expand Down
2 changes: 2 additions & 0 deletions renku_notebooks/config/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ class _K8sConfig:
renku_namespace: str
sessions_namespace: Optional[str] = None
enabled: Union[str, bool] = True
bypass_cache_on_failure: Union[str, bool] = True

def __post_init__(self):
self.enabled = _parse_str_as_bool(self.enabled)
self.bypass_cache_on_failure = _parse_str_as_bool(self.bypass_cache_on_failure)


@dataclass
Expand Down
Loading