diff --git a/getdeck/configuration.py b/getdeck/configuration.py index 8fc2900..dcc095b 100644 --- a/getdeck/configuration.py +++ b/getdeck/configuration.py @@ -65,8 +65,6 @@ def __init__( self.kubeconfig = None self.K8S_OBJECT_RETRY = 30 self.K8S_OBJECT_RETRY_TIMEOUT = 2 # in s - self.BEIBOOT_CLUSTER_CREATION_TIMEOUT = 180 # in s - self.BEIBOOT_API_READY_TIMEOUT = 20 # in s def _init_docker(self): import docker diff --git a/getdeck/provider/beiboot/__init__.py b/getdeck/provider/beiboot/__init__.py index b49a873..1f5a332 100644 --- a/getdeck/provider/beiboot/__init__.py +++ b/getdeck/provider/beiboot/__init__.py @@ -1,6 +1,5 @@ import logging from pathlib import Path -from time import sleep from typing import List, Optional import kubernetes.config @@ -22,6 +21,11 @@ DOCKER_IMAGE = "quay.io/getdeck/tooler:latest" +class TimeoutNativeConfig(BaseModel): + api: int = 30 # in s + cluster: int = 180 # in s + + class PortNativeConfig(BaseModel): port: str @@ -29,6 +33,7 @@ class PortNativeConfig(BaseModel): class NativeConfigBeiboot(BaseModel): context: str ports: Optional[List[PortNativeConfig]] = None + timeouts: Optional[TimeoutNativeConfig] = TimeoutNativeConfig() class Beiboot(AbstractProvider): @@ -68,13 +73,25 @@ def __init__( _kubeconf = str( Path(kubernetes.config.KUBE_CONFIG_DEFAULT_LOCATION).expanduser() ) + self._bbt_conf = BeibootConfiguration( kube_config_file=self.config.kubeconfig or _kubeconf, docker_client=self.config.DOCKER, - cluster_timeout=self.config.BEIBOOT_CLUSTER_CREATION_TIMEOUT, + cluster_timeout=self.native_config.timeouts.cluster, + api_connection_timeout=self.native_config.timeouts.api, kube_context=context_name, tooler_image=self.config.TOOLER_BASE_IMAGE, ) + logger.debug( + "Beiboot config:" + + str( + [ + f"{k}={getattr(self._bbt_conf, k)}" + for k in vars(self._bbt_conf) + if not k.startswith("_") + ] + ) + ) except kubernetes.config.ConfigException as e: logger.debug(e) raise RuntimeError( @@ -97,19 +114,17 @@ def create(self) -> bool: logger.info( f"Now creating Beiboot '{self.cluster_name}'. This is going to take a while..." ) - api.create_cluster( - cluster_name=self.cluster_name, - ports=ports, - connect=True, - configuration=self._bbt_conf, - ) - _i = 0 - while _i < self.config.BEIBOOT_API_READY_TIMEOUT: - if self._check_api_proxy_running(): - break - else: - _i = _i + 1 - sleep(1) + try: + api.create_cluster( + cluster_name=self.cluster_name, + ports=ports, + connect=True, + configuration=self._bbt_conf, + ) + except TimeoutError as timeout: + # this happens when either the cluster was not ready in time, or the api connection + self.delete() + raise timeout kubeconfig_location = self.get_kubeconfig() logger.info( @@ -125,14 +140,6 @@ def start(self) -> bool: cluster_name=self.cluster_name, configuration=self._bbt_conf ) - _i = 0 - while _i < self.config.BEIBOOT_API_READY_TIMEOUT: - if self._check_api_proxy_running(): - break - else: - _i = _i + 1 - sleep(1) - kubeconfig_location = self.get_kubeconfig() logger.info( f"You can now set 'export KUBECONFIG={kubeconfig_location}' and work with the cluster." diff --git a/pyproject.toml b/pyproject.toml index 45d8861..315f61e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ semantic-version = "^2.9.0" GitPython = "^3.1.27" PyYAML = "^6.0" python-hosts = "^1.0.3" -beiboot = "^0.10.0" +beiboot = "^0.11" [tool.poetry.dev-dependencies]