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
16 changes: 10 additions & 6 deletions getdeck/api/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def run_deck( # noqa: C901

if progress_callback:
progress_callback(20)

# change api for beiboot
if k8s_provider.kubernetes_cluster_type == ProviderType.BEIBOOT:
_old_kubeconfig = config.kubeconfig
config.kubeconfig = k8s_provider.get_kubeconfig()
config._init_kubeapi(context="default")

#
# 2. generate the Deck's workload
#
Expand All @@ -60,6 +67,9 @@ def run_deck( # noqa: C901
except Exception as e:
if cluster_created:
# remove this just created cluster as it probably is in an inconsistent state from the beginning
if k8s_provider.kubernetes_cluster_type == ProviderType.BEIBOOT:
config.kubeconfig = _old_kubeconfig
config._init_kubeapi()
remove.remove_cluster(deckfile_location, config)
raise e

Expand All @@ -71,12 +81,6 @@ def run_deck( # noqa: C901
#
logger.info("Installing the workload to the cluster")

# change api for beiboot
if k8s_provider.kubernetes_cluster_type == ProviderType.BEIBOOT:
_old_kubeconfig = config.kubeconfig
config.kubeconfig = k8s_provider.get_kubeconfig()
config._init_kubeapi()

if generated_deck.namespace != "default":
create_namespace(config, generated_deck.namespace)

Expand Down
2 changes: 2 additions & 0 deletions getdeck/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ 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
12 changes: 0 additions & 12 deletions getdeck/docker.py

This file was deleted.

2 changes: 1 addition & 1 deletion getdeck/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def k8s_create_or_patch(
_call_and_log(config, api, "create", obj, namespace, **kwargs)
break
except ApiException as e:
if e.reason == "Internal Server Error":
if e.reason in ["Internal Server Error", "Unprocessable Entity"]:
continue
if e.reason == "Not Found":
logger.debug(e)
Expand Down
37 changes: 30 additions & 7 deletions getdeck/provider/beiboot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging
from pathlib import Path
from time import sleep
from typing import List, Optional

import kubernetes.config

from getdeck.configuration import ClientConfiguration
from beiboot.configuration import ClientConfiguration as BeibootConfiguration
from getdeck.docker import Docker
from getdeck.provider.abstract import AbstractProvider
from getdeck.provider.errors import NotSupportedError
from getdeck.provider.types import ProviderType
Expand Down Expand Up @@ -71,6 +71,7 @@ def __init__(
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,
kube_context=context_name,
)
except kubernetes.config.ConfigException as e:
Expand Down Expand Up @@ -101,9 +102,13 @@ def create(self) -> bool:
connect=True,
configuration=self._bbt_conf,
)

while not Docker().check_running(DOCKER_IMAGE):
continue
_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(
Expand All @@ -113,13 +118,19 @@ def create(self) -> bool:
return True

def start(self) -> bool:
if not Docker().check_running(DOCKER_IMAGE):

if not self._check_api_proxy_running():
api.establish_connection(
cluster_name=self.cluster_name, configuration=self._bbt_conf
)

while not Docker().check_running(DOCKER_IMAGE):
continue
_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(
Expand Down Expand Up @@ -167,6 +178,18 @@ def get_ports(self) -> List[str]:
except KeyError:
return []

def _check_api_proxy_running(self) -> bool:
for container in self.config.DOCKER.containers.list():
if container.name == f"getdeck-proxy-{self.cluster_name}-6443":
# this is the api proxy; check it is running
if container.status == "running":
if "Forwarding" in container.logs().decode():
return True
else:
return False
else:
return False


class BeibootBuilder:
def __init__(self):
Expand Down
6 changes: 5 additions & 1 deletion getdeck/sources/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ def collect_workload_files(self):

@cached_property
def k8s_api_version(self) -> str:
import re

req = self.config.K8S_CORE_API.api_client.request(
"GET", f"{self.config.K8S_CORE_API.api_client.configuration.host}/version"
)
logger.debug(self.config.K8S_CORE_API.api_client.configuration.host)
data = json.loads(req.data)
return f"{data['major']}.{data['minor']}"
logger.debug("Kube API version: " + str(data))
return f"{re.sub(r'[^0-9]+', '', data['major'])}.{re.sub(r'[^0-9]+', '', data['minor'])}"

def _helm_prep(self) -> List[str]:
if self.type in ["git", "local"]:
Expand Down
Loading