Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
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
28 changes: 5 additions & 23 deletions packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from jumpstarter_cli_common.alias import AliasedGroup
from jumpstarter_cli_common.blocking import blocking
from jumpstarter_cli_common.opt import (
OutputMode,
OutputType,
confirm_insecure_tls,
opt_context,
Expand All @@ -15,7 +14,8 @@
opt_nointeractive,
opt_output_all,
)
from jumpstarter_kubernetes import ClientsV1Alpha1Api, ExportersV1Alpha1Api, V1Alpha1Client, V1Alpha1Exporter
from jumpstarter_cli_common.print import model_print
from jumpstarter_kubernetes import ClientsV1Alpha1Api, ExportersV1Alpha1Api
from kubernetes_asyncio.client.exceptions import ApiException
from kubernetes_asyncio.config.config_exception import ConfigException

Expand All @@ -35,15 +35,6 @@ def create():
"""Create Jumpstarter Kubernetes objects"""


def print_created_client(client: V1Alpha1Client, output: OutputType):
if output == OutputMode.JSON:
click.echo(client.dump_json())
elif output == OutputMode.YAML:
click.echo(client.dump_yaml())
elif output == OutputMode.NAME:
click.echo(f"client.jumpstarter.dev/{client.metadata.name}")


@create.command("client")
@click.argument("name", type=str, required=False, default=None)
@click.option(
Expand Down Expand Up @@ -116,28 +107,19 @@ async def create_client(
client_config.tls.insecure = insecure_tls_config
ClientConfigV1Alpha1.save(client_config, out)
# If this is the only client config, set it as default
if out is None and len(ClientConfigV1Alpha1.list()) == 1:
if out is None and len(ClientConfigV1Alpha1.list().items) == 1:
user_config = UserConfigV1Alpha1.load_or_create()
user_config.config.current_client = client_config
UserConfigV1Alpha1.save(user_config)
if output is None:
click.echo(f"Client configuration successfully saved to {client_config.path}")
print_created_client(created_client, output)
model_print(created_client, output, namespace=namespace)
except ApiException as e:
handle_k8s_api_exception(e)
except ConfigException as e:
handle_k8s_config_exception(e)


def print_created_exporter(exporter: V1Alpha1Exporter, output: OutputType):
if output == OutputMode.JSON:
click.echo(exporter.dump_json())
elif output == OutputMode.YAML:
click.echo(exporter.dump_yaml())
elif output == OutputMode.NAME:
click.echo(f"exporter.jumpstarter.dev/{exporter.metadata.name}")


@create.command("exporter")
@click.argument("name", type=str, required=False, default=None)
@click.option(
Expand Down Expand Up @@ -191,7 +173,7 @@ async def create_exporter(
ExporterConfigV1Alpha1.save(exporter_config, out)
if output is None:
click.echo(f"Exporter configuration successfully saved to {exporter_config.path}")
print_created_exporter(created_exporter, output)
model_print(created_exporter, output, namespace=namespace)
except ApiException as e:
handle_k8s_api_exception(e)
except ConfigException as e:
Expand Down
14 changes: 7 additions & 7 deletions packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
opt_namespace,
opt_output_all,
)
from jumpstarter_cli_common.print import model_print
from jumpstarter_kubernetes import (
ClientsV1Alpha1Api,
ExportersV1Alpha1Api,
Expand All @@ -22,7 +23,6 @@
handle_k8s_api_exception,
handle_k8s_config_exception,
)
from .print import print_client, print_clients, print_exporter, print_exporters, print_lease, print_leases


@click.group(cls=AliasedGroup)
Expand All @@ -45,10 +45,10 @@ async def get_client(
async with ClientsV1Alpha1Api(namespace, kubeconfig, context) as api:
if name is not None:
client = await api.get_client(name)
print_client(client, output)
model_print(client, output, namespace=namespace)
else:
clients = await api.list_clients()
print_clients(clients, namespace, output)
model_print(clients, output, namespace=namespace)
except ApiException as e:
handle_k8s_api_exception(e)
except ConfigException as e:
Expand Down Expand Up @@ -76,10 +76,10 @@ async def get_exporter(
async with ExportersV1Alpha1Api(namespace, kubeconfig, context) as api:
if name is not None:
exporter = await api.get_exporter(name)
print_exporter(exporter, devices, output)
model_print(exporter, output, devices=devices, namespace=namespace)
else:
exporters = await api.list_exporters()
print_exporters(exporters, namespace, devices, output)
model_print(exporters, output, devices=devices, namespace=namespace)
except ApiException as e:
handle_k8s_api_exception(e)
except ConfigException as e:
Expand All @@ -101,10 +101,10 @@ async def get_lease(
async with LeasesV1Alpha1Api(namespace, kubeconfig, context) as api:
if name is not None:
lease = await api.get_lease(name)
print_lease(lease, output)
model_print(lease, output, namespace=namespace)
else:
leases = await api.list_leases()
print_leases(leases, namespace, output)
model_print(leases, output, namespace=namespace)
except ApiException as e:
handle_k8s_api_exception(e)
except ConfigException as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_get_clients(_load_kube_config_mock, list_clients_mock: AsyncMock):
# No clients found
list_clients_mock.return_value = V1Alpha1ClientList(items=[])
result = runner.invoke(get, ["clients"])
assert result.exit_code == 1
assert result.exit_code == 0
Comment thread
NickCao marked this conversation as resolved.
assert "No resources found" in result.output
list_clients_mock.reset_mock()

Expand Down Expand Up @@ -636,7 +636,7 @@ def test_get_exporters(_load_kube_config_mock, list_exporters_mock: AsyncMock):
return_value=V1Alpha1ExporterList(items=[]),
):
result = runner.invoke(get, ["exporters"])
assert result.exit_code == 1
assert result.exit_code == 0
assert "No resources found" in result.output


Expand Down Expand Up @@ -800,7 +800,7 @@ def test_get_exporters_devices(_load_kube_config_mock, list_exporters_mock: Asyn
# No exporters found
list_exporters_mock.return_value = V1Alpha1ExporterList(items=[])
result = runner.invoke(get, ["exporters", "--devices"])
assert result.exit_code == 1
assert result.exit_code == 0
assert "No resources found" in result.output


Expand Down Expand Up @@ -1193,5 +1193,5 @@ def test_get_leases(_load_kube_config_mock, list_leases_mock: AsyncMock):
# No leases found
list_leases_mock.return_value = V1Alpha1LeaseList(items=[])
result = runner.invoke(get, ["leases"])
assert result.exit_code == 1
assert result.exit_code == 0
assert "No resources found" in result.output
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def import_client(
client_config.tls.insecure = insecure_tls_config
config_path = ClientConfigV1Alpha1.save(client_config, out)
# If this is the only client config, set it as default
if out is None and len(ClientConfigV1Alpha1.list()) == 1:
if out is None and len(ClientConfigV1Alpha1.list().items) == 1:
user_config = UserConfigV1Alpha1.load_or_create()
user_config.config.current_client = client_config
UserConfigV1Alpha1.save(user_config)
Expand Down
175 changes: 0 additions & 175 deletions packages/jumpstarter-cli-admin/jumpstarter_cli_admin/print.py

This file was deleted.

Loading
Loading