Skip to content

Commit

Permalink
fix: properly use gevent and allow configuring k8s cache bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Oct 24, 2024
1 parent 60db1f3 commit 6ed927f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
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

0 comments on commit 6ed927f

Please sign in to comment.