Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: better registry handling ✨ #712

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"python.testing.pytestArgs": [
"operator"
"client"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
Expand Down
15 changes: 13 additions & 2 deletions client/gefyra/api/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
def add_clients(
client_id: str,
quantity: int = 1,
registry: Optional[str] = None,
kubeconfig: Optional[Path] = None,
kubecontext: Optional[str] = None,
) -> Iterable[GefyraClient]:
"""
Add a new client to the connection provider
"""
config = ClientConfiguration(
kube_config_file=kubeconfig, kube_context=kubecontext, ignore_connection=True
kube_config_file=kubeconfig,
kube_context=kubecontext,
ignore_connection=True,
registry=registry,
)
if quantity > 1 and client_id:
raise RuntimeError("Cannot specify both quantity > 1 and client_id")
Expand Down Expand Up @@ -94,11 +98,18 @@ def write_client_file(
kube_api: Optional[str] = None,
kubeconfig: Optional[Path] = None,
kubecontext: Optional[str] = None,
registry: Optional[str] = None,
wireguard_mtu: Optional[int] = 1340,
) -> str:
"""
Write a client file
"""
config = ClientConfiguration(kube_config_file=kubeconfig, kube_context=kubecontext)
config = ClientConfiguration(
kube_config_file=kubeconfig,
kube_context=kubecontext,
registry=registry,
wireguard_mtu=wireguard_mtu,
)
client = get_client(
client_id, kubeconfig=config.KUBE_CONFIG_FILE, kubecontext=config.KUBE_CONTEXT
)
Expand Down
6 changes: 5 additions & 1 deletion client/gefyra/api/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def install(
from gefyra.configuration import ClientConfiguration

config = ClientConfiguration(
kube_config_file=kubeconfig, kube_context=kubecontext, ignore_docker=True
kube_config_file=kubeconfig,
kube_context=kubecontext,
ignore_docker=True,
registry=kwargs.get("registry", ""),
wireguard_mtu=kwargs.get("mtu", 1340),
)
if preset:
presetoptions = LB_PRESETS.get(preset) # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion client/gefyra/api/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def update(
"containers": [
{
"name": "gefyra",
"image": f"quay.io/gefyra/operator:{version}",
"image": config.OPERATOR_IMAGE,
}
]
}
Expand Down
4 changes: 3 additions & 1 deletion client/gefyra/api/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ def status(connection_name: str = "") -> GefyraStatus:
client = _get_client_status(config)
except urllib3.exceptions.MaxRetryError as e:
raise ClientConfigurationError(
f"Cannot reach cluster on {e.pool.host}:{e.pool.port}"
f"Cannot reach cluster on {e.pool.host}:{e.pool.port}\n"
f"Used kubeconfig: {config.KUBE_CONFIG_FILE} from Gefyra connection {connection_name}\n"
f"Please delete the connection and create a new one. Use: gefyra connection remove {connection_name}"
)

if client.connection:
Expand Down
10 changes: 8 additions & 2 deletions client/gefyra/cli/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ def clients(ctx):
type=int,
default=1,
)
@click.option("--registry", help="The registry URL for the images", type=str)
@click.pass_context
@standard_error_handler
def create_clients(ctx, client_id, quantity):
def create_clients(ctx, client_id, quantity, registry):
from gefyra import api

api.add_clients(
client_id,
quantity,
registry=registry,
kubeconfig=ctx.obj["kubeconfig"],
kubecontext=ctx.obj["context"],
)
Expand Down Expand Up @@ -114,9 +116,11 @@ def inspect_client(ctx, client_id):
help="The output file to write the config to",
type=click.File("wb"),
)
@click.option("--registry", help="The registry URL for the images", type=str)
@click.option("--mtu", help="The MTU for the Wireguard interface", type=int)
@click.pass_context
@standard_error_handler
def get_config(ctx, client_id, host, port, kube_api, output):
def get_config(ctx, client_id, host, port, kube_api, output, registry, mtu):
from gefyra import api

json_str = api.write_client_file(
Expand All @@ -126,6 +130,8 @@ def get_config(ctx, client_id, host, port, kube_api, output):
kube_api=kube_api,
kubeconfig=ctx.obj["kubeconfig"],
kubecontext=ctx.obj["context"],
registry=registry,
wireguard_mtu=mtu,
)
if output:
output.write(json_str.encode("utf-8"))
Expand Down
5 changes: 3 additions & 2 deletions client/gefyra/cli/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def install(ctx, component, preset, apply, wait, **kwargs):
from alive_progress import alive_bar
from gefyra import api

if not all(kwargs.values()):
kwargs = {}
# filter out empty kwargs
kwargs = {k: v for k, v in kwargs.items() if v}

if wait and not apply:
raise click.BadOptionUsage(
option_name="wait", message="Cannot wait without '--apply'"
Expand Down
7 changes: 4 additions & 3 deletions client/gefyra/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
from gefyra.cli.utils import AliasedGroup


@click.group(
cls=AliasedGroup,
)
@click.group(cls=AliasedGroup)
@click.option(
"--kubeconfig",
help="Path to the kubeconfig file to use instead of loading the default",
Expand All @@ -32,6 +30,7 @@ def cli(ctx: click.Context, kubeconfig, context, debug):
import logging
from gefyra.cli.telemetry import CliTelemetry

# Set up logging based on the debug flag
if debug:
logger = logging.getLogger()
handler = logging.StreamHandler()
Expand All @@ -43,12 +42,14 @@ def cli(ctx: click.Context, kubeconfig, context, debug):
logging.getLogger("gefyra").setLevel(logging.DEBUG)
else:
logging.getLogger("gefyra").setLevel(logging.ERROR)

ctx.ensure_object(dict)

try:
ctx.obj["telemetry"] = CliTelemetry()
except Exception: # pragma: no cover
ctx.obj["telemetry"] = False
ctx.obj["debug"] = debug
ctx.obj["kubeconfig"] = kubeconfig
ctx.obj["context"] = context

Expand Down
5 changes: 5 additions & 0 deletions client/gefyra/cli/operator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
from gefyra.cli import console
from gefyra.cli.utils import AliasedGroup, standard_error_handler


Expand All @@ -22,6 +23,10 @@ def operator(ctx):
def update(version):
from gefyra import api

console.info("Updating the Gefyra operator")

api.operator.update(
version=version,
)

console.success("Gefyra operator updated successfully")
38 changes: 35 additions & 3 deletions client/gefyra/cli/updown.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def _check_and_install(
connection_name: str = "",
preset: Optional[str] = None,
bar=None,
registry: Optional[str] = None,
mtu: Optional[int] = None,
) -> bool:
status = api.status(connection_name=connection_name)

Expand All @@ -38,6 +40,8 @@ def _check_and_install(
apply=True,
wait=True,
preset=preset,
registry=registry,
mtu=mtu,
)
return True

Expand All @@ -56,9 +60,27 @@ def _check_and_install(
help=f"Set configs from a preset (available: {','.join(api.LB_PRESETS.keys())})",
type=str,
)
@click.option(
"--registry",
help="Set the registry to use for the Gefyra components",
type=str,
required=False,
)
@click.option(
"--mtu",
help="Set the MTU for the Gefyra network",
type=int,
required=False,
)
@pass_context
@standard_error_handler
def cluster_up(ctx, minikube: Optional[str] = None, preset: Optional[str] = None):
def cluster_up(
ctx,
minikube: Optional[str] = None,
preset: Optional[str] = None,
registry: Optional[str] = None,
mtu: Optional[int] = None,
):
from alive_progress import alive_bar
from gefyra.exceptions import GefyraClientAlreadyExists, ClientConfigurationError
from time import sleep
Expand All @@ -75,7 +97,12 @@ def cluster_up(ctx, minikube: Optional[str] = None, preset: Optional[str] = None
kubeconfig = ctx.obj["kubeconfig"]
kubecontext = ctx.obj["context"]

config = ClientConfiguration(kube_config_file=kubeconfig, kube_context=kubecontext)
config = ClientConfiguration(
kube_config_file=kubeconfig,
kube_context=kubecontext,
registry=registry,
wireguard_mtu=mtu,
)
with alive_bar(
4,
title="Installing Gefyra to the cluster",
Expand All @@ -86,7 +113,12 @@ def cluster_up(ctx, minikube: Optional[str] = None, preset: Optional[str] = None
) as bar:
# run a default install
install_success = _check_and_install(
config=config, connection_name=connection_name, preset=preset, bar=bar
config=config,
connection_name=connection_name,
preset=preset,
bar=bar,
registry=config.REGISTRY,
mtu=config.WIREGUARD_MTU,
)
if install_success:
bar()
Expand Down
4 changes: 2 additions & 2 deletions client/gefyra/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def parser_process(value, state):

def multi_options(options):
map_to_types = dict(
array=str,
array=list,
number=float,
string=str,
)
Expand All @@ -161,7 +161,7 @@ def decorator(f):
"--" + opt_params["long"],
opt_params["name"],
)
if "short" in opt_params and not opt_params["short"] is None:
if "short" in opt_params and opt_params["short"] is not None:
param_decls = ("-" + opt_params["short"], *param_decls)

attrs = dict(
Expand Down
24 changes: 9 additions & 15 deletions client/gefyra/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(
cargo_endpoint_host: str = "",
cargo_endpoint_port: str = "31820",
cargo_container_name: str = "",
registry_url: str = "",
registry: str = "",
operator_image_url: str = "",
stowaway_image_url: str = "",
carrier_image_url: str = "",
Expand All @@ -80,42 +80,36 @@ def __init__(
self.NAMESPACE = "gefyra" # another namespace is currently not supported
self._kube_config_path = None
self._kube_context = None
self.REGISTRY_URL = (
registry_url.rstrip("/") if registry_url else "quay.io/gefyra"
)
if registry_url:
logger.debug(
f"Using registry prefix (other than default): {self.REGISTRY_URL}"
)
self.REGISTRY = registry.rstrip("/") if registry else "quay.io/gefyra"
if registry:
logger.debug(f"Using registry prefix (other than default): {self.REGISTRY}")
self.OPERATOR_IMAGE = (
operator_image_url or f"{self.REGISTRY_URL}/operator:{__VERSION__}"
operator_image_url or f"{self.REGISTRY}/operator:{__VERSION__}"
)
if operator_image_url:
logger.debug(
f"Using Operator image (other than default): {operator_image_url}"
)
self.STOWAWAY_IMAGE = (
stowaway_image_url or f"{self.REGISTRY_URL}/stowaway:{__VERSION__}"
stowaway_image_url or f"{self.REGISTRY}/stowaway:{__VERSION__}"
)
if stowaway_image_url:
logger.debug(
f"Using Stowaway image (other than default): {stowaway_image_url}"
)
self.CARRIER_IMAGE = (
carrier_image_url or f"{self.REGISTRY_URL}/carrier:{__VERSION__}"
carrier_image_url or f"{self.REGISTRY}/carrier:{__VERSION__}"
)
if carrier_image_url:
logger.debug(
f"Using Carrier image (other than default): {carrier_image_url}"
)
if sys.platform == "win32" or "microsoft" in platform.release().lower():
self.CARGO_IMAGE = (
cargo_image_url or f"{self.REGISTRY_URL}/cargo-win:{__VERSION__}"
cargo_image_url or f"{self.REGISTRY}/cargo-win:{__VERSION__}"
)
else:
self.CARGO_IMAGE = (
cargo_image_url or f"{self.REGISTRY_URL}/cargo:{__VERSION__}"
)
self.CARGO_IMAGE = cargo_image_url or f"{self.REGISTRY}/cargo:{__VERSION__}"
if cargo_image_url:
logger.debug(f"Using Cargo image (other than default): {cargo_image_url}")
if docker_client:
Expand Down
Loading
Loading