Skip to content

Commit

Permalink
fix: kubeconfig needed for connect (#589)
Browse files Browse the repository at this point in the history
* fix: kubeconfig needed for connect
  • Loading branch information
SteinRobert committed Apr 20, 2024
1 parent 2c7d264 commit 47f2ead
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions client/gefyra/api/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import IO, List, Optional, TYPE_CHECKING
from gefyra.api.clients import get_client
from gefyra.exceptions import GefyraConnectionError
from gefyra.local.clients import handle_get_gefyraclient
from gefyra.local.minikube import detect_minikube_config
from .utils import stopwatch

Expand All @@ -26,7 +27,12 @@
compose_kubeconfig_for_serviceaccount,
handle_docker_get_or_create_container,
)
from gefyra.types import GefyraClientConfig, GefyraClientState, GefyraConnectionItem
from gefyra.types import (
GefyraClient,
GefyraClientConfig,
GefyraClientState,
GefyraConnectionItem,
)


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -59,18 +65,18 @@ def connect( # noqa: C901
file_str = client_config.read()
client_config.close()
gclient_conf = GefyraClientConfig.from_json_str(file_str)
client = get_client(gclient_conf.client_id, connection_name=connection_name)
loc = os.path.join(
get_gefyra_config_location(),
f"{connection_name}.yaml",
)

# this kubeconfig is being used by the client to operate in the cluster
kubeconfig_str = compose_kubeconfig_for_serviceaccount(
gclient_conf.kubernetes_server,
gclient_conf.ca_crt,
"gefyra",
base64.b64decode(gclient_conf.token).decode("utf-8"),
)
loc = os.path.join(
get_gefyra_config_location(),
f"{connection_name}.yaml",
)
with open(loc, "w") as f:
f.write(kubeconfig_str)
logger.info(f"Client kubeconfig saved to {loc}")
Expand All @@ -91,6 +97,10 @@ def connect( # noqa: C901
cargo_endpoint_port=gclient_conf.gefyra_server.split(":")[1],
cargo_container_name=f"gefyra-cargo-{connection_name}",
)

gclient = handle_get_gefyraclient(config, gclient_conf.client_id)
client = GefyraClient(gclient, config)

config.CARGO_PROBE_TIMEOUT = probe_timeout

_retry = 0
Expand Down

0 comments on commit 47f2ead

Please sign in to comment.