|
55 | 55 | ) |
56 | 56 | from renku_data_services.db_config import DBConfig |
57 | 57 | from renku_data_services.git.gitlab import DummyGitlabAPI, GitlabAPI |
58 | | -from renku_data_services.k8s.clients import DummyCoreClient, DummySchedulingClient, K8sCoreClient, K8sSchedulingClient |
| 58 | +from renku_data_services.k8s.clients import ( |
| 59 | + DummyCoreClient, |
| 60 | + DummySchedulingClient, |
| 61 | + K8sClusterClientsPool, |
| 62 | + K8sCoreClient, |
| 63 | + K8sSchedulingClient, |
| 64 | +) |
| 65 | +from renku_data_services.k8s.config import KubeConfigEnv |
59 | 66 | from renku_data_services.k8s.quota import QuotaRepository |
| 67 | +from renku_data_services.k8s_watcher.db import K8sDbCache |
60 | 68 | from renku_data_services.message_queue.config import RedisConfig |
61 | 69 | from renku_data_services.message_queue.db import EventRepository, ReprovisioningRepository |
62 | 70 | from renku_data_services.message_queue.interface import IMessageQueue |
63 | 71 | from renku_data_services.message_queue.redis_queue import RedisQueue |
64 | 72 | from renku_data_services.metrics.core import StagingMetricsService |
65 | 73 | from renku_data_services.metrics.db import MetricsRepository |
66 | 74 | from renku_data_services.namespace.db import GroupRepository |
67 | | -from renku_data_services.notebooks.config import NotebooksConfig |
| 75 | +from renku_data_services.notebooks.config import NotebooksConfig, get_clusters |
| 76 | +from renku_data_services.notebooks.constants import AMALTHEA_SESSION_KIND, JUPYTER_SESSION_KIND |
68 | 77 | from renku_data_services.platform.db import PlatformRepository |
69 | 78 | from renku_data_services.project.db import ( |
70 | 79 | ProjectMemberRepository, |
|
77 | 86 | from renku_data_services.search.reprovision import SearchReprovision |
78 | 87 | from renku_data_services.secrets.db import LowLevelUserSecretsRepo, UserSecretsRepo |
79 | 88 | from renku_data_services.session import crs as session_crs |
| 89 | +from renku_data_services.session.constants import BUILD_RUN_KIND, TASK_RUN_KIND |
80 | 90 | from renku_data_services.session.db import SessionRepository |
81 | 91 | from renku_data_services.session.k8s_client import ShipwrightClient |
82 | 92 | from renku_data_services.solr.solr_client import SolrClientConfig |
@@ -182,7 +192,7 @@ class BuildsConfig: |
182 | 192 | tolerations: list[session_crs.Toleration] | None = None |
183 | 193 |
|
184 | 194 | @classmethod |
185 | | - def from_env(cls, prefix: str = "", namespace: str = "") -> "BuildsConfig": |
| 195 | + def from_env(cls, db: DBConfig, prefix: str = "", namespace: str = "") -> "BuildsConfig": |
186 | 196 | """Create a config from environment variables.""" |
187 | 197 | enabled = os.environ.get(f"{prefix}IMAGE_BUILDERS_ENABLED", "false").lower() == "true" |
188 | 198 | build_output_image_prefix = os.environ.get(f"{prefix}BUILD_OUTPUT_IMAGE_PREFIX") |
@@ -216,11 +226,18 @@ def from_env(cls, prefix: str = "", namespace: str = "") -> "BuildsConfig": |
216 | 226 | elif not enabled: |
217 | 227 | shipwright_client = None |
218 | 228 | else: |
219 | | - # TODO: is there a reason to use a different cache URL here? |
220 | | - cache_url = os.environ["NB_AMALTHEA_V2__CACHE_URL"] |
| 229 | + # NOTE: we need to get an async client as a sync client can't be used in an async way |
| 230 | + # But all the config code is not async, so we need to drop into the running loop, if there is one |
| 231 | + kr8s_api = KubeConfigEnv().api() |
| 232 | + k8s_db_cache = K8sDbCache(db.async_session_maker) |
| 233 | + client = K8sClusterClientsPool( |
| 234 | + clusters=get_clusters("/secrets/kube_configs", namespace=namespace, api=kr8s_api), |
| 235 | + cache=k8s_db_cache, |
| 236 | + kinds_to_cache=[AMALTHEA_SESSION_KIND, JUPYTER_SESSION_KIND, BUILD_RUN_KIND, TASK_RUN_KIND], |
| 237 | + ) |
221 | 238 | shipwright_client = ShipwrightClient( |
| 239 | + client=client, |
222 | 240 | namespace=namespace, |
223 | | - cache_url=cache_url, |
224 | 241 | ) |
225 | 242 |
|
226 | 243 | node_selector: dict[str, str] | None = None |
@@ -730,7 +747,7 @@ def from_env(cls, prefix: str = "") -> "Config": |
730 | 747 | trusted_proxies = TrustedProxiesConfig.from_env(prefix) |
731 | 748 | message_queue = RedisQueue(redis) |
732 | 749 | nb_config = NotebooksConfig.from_env(db) |
733 | | - builds_config = BuildsConfig.from_env(prefix, k8s_namespace) |
| 750 | + builds_config = BuildsConfig.from_env(db, prefix, k8s_namespace) |
734 | 751 | posthog = PosthogConfig.from_env(prefix) |
735 | 752 |
|
736 | 753 | return cls( |
|
0 commit comments