Skip to content
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
2 changes: 0 additions & 2 deletions getdeck/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 30 additions & 23 deletions getdeck/provider/beiboot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from pathlib import Path
from time import sleep
from typing import List, Optional

import kubernetes.config
Expand All @@ -22,13 +21,19 @@
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


class NativeConfigBeiboot(BaseModel):
context: str
ports: Optional[List[PortNativeConfig]] = None
timeouts: Optional[TimeoutNativeConfig] = TimeoutNativeConfig()


class Beiboot(AbstractProvider):
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down