From beefc2a23a30282bcda44f7ea1776155487b938e Mon Sep 17 00:00:00 2001 From: Michael Schilonka Date: Mon, 17 Oct 2022 10:59:02 +0200 Subject: [PATCH 1/2] feat: integrate beiboot 0.11 --- getdeck/configuration.py | 2 -- getdeck/provider/beiboot/__init__.py | 43 ++++++++++++++-------------- pyproject.toml | 2 +- 3 files changed, 22 insertions(+), 25 deletions(-) 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..59e99ff 100644 --- a/getdeck/provider/beiboot/__init__.py +++ b/getdeck/provider/beiboot/__init__.py @@ -22,6 +22,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 +34,7 @@ class PortNativeConfig(BaseModel): class NativeConfigBeiboot(BaseModel): context: str ports: Optional[List[PortNativeConfig]] = None + timeouts: Optional[TimeoutNativeConfig] = TimeoutNativeConfig() class Beiboot(AbstractProvider): @@ -68,13 +74,16 @@ 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 +106,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 +132,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] From 100b9a31a0ecb1daed5b6d9b000819ba86f2d401 Mon Sep 17 00:00:00 2001 From: Michael Schilonka Date: Mon, 17 Oct 2022 11:00:21 +0200 Subject: [PATCH 2/2] fix: code styling and flake8 --- getdeck/provider/beiboot/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/getdeck/provider/beiboot/__init__.py b/getdeck/provider/beiboot/__init__.py index 59e99ff..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 @@ -83,7 +82,16 @@ def __init__( 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("_")])) + 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(