Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
Closed
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
24 changes: 8 additions & 16 deletions packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import asyncclick as click
from jumpstarter_cli_common import (
AliasedGroup,
OutputMode,
OutputType,
echo,
opt_context,
opt_kubeconfig,
opt_labels,
opt_log_level,
opt_namespace,
opt_nointeractive,
opt_output_all,
opt_output_auto,
)
from jumpstarter_kubernetes import ClientsV1Alpha1Api, ExportersV1Alpha1Api, V1Alpha1Client, V1Alpha1Exporter
from kubernetes_asyncio.client.exceptions import ApiException
Expand All @@ -38,12 +38,8 @@ def create(log_level: Optional[str]):


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}")
if output is not None:
echo(client.dump(output))


@create.command("client")
Expand Down Expand Up @@ -75,7 +71,7 @@ def print_created_client(client: V1Alpha1Client, output: OutputType):
@opt_context
@opt_oidc_username
@opt_nointeractive
@opt_output_all
@opt_output_auto(V1Alpha1Client)
async def create_client(
name: Optional[str],
kubeconfig: Optional[str],
Expand Down Expand Up @@ -127,12 +123,8 @@ async def create_client(


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}")
if output is not None:
echo(exporter.dump(output))


@create.command("exporter")
Expand All @@ -156,7 +148,7 @@ def print_created_exporter(exporter: V1Alpha1Exporter, output: OutputType):
@opt_context
@opt_oidc_username
@opt_nointeractive
@opt_output_all
@opt_output_auto(V1Alpha1Exporter)
async def create_exporter(
name: Optional[str],
kubeconfig: Optional[str],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
credential:
name: {name}-credential
endpoint: {endpoint}

""".format(name=CLIENT_NAME, endpoint=CLIENT_ENDPOINT)

UNSAFE_CLIENT_CONFIG = ClientConfigV1Alpha1(
Expand Down Expand Up @@ -214,7 +213,6 @@ async def test_create_client(
name: {name}-credential
devices: []
endpoint: {endpoint}

""".format(name=EXPORTER_NAME, endpoint=EXPORTER_ENDPOINT)

EXPORTER_CONFIG = ExporterConfigV1Alpha1(
Expand Down
11 changes: 7 additions & 4 deletions packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
opt_kubeconfig,
opt_log_level,
opt_namespace,
opt_output_all,
opt_output_auto,
)
from jumpstarter_kubernetes import (
ClientsV1Alpha1Api,
ExportersV1Alpha1Api,
LeasesV1Alpha1Api,
V1Alpha1Client,
V1Alpha1Exporter,
V1Alpha1Lease,
)
from kubernetes_asyncio.client.exceptions import ApiException
from kubernetes_asyncio.config.config_exception import ConfigException
Expand All @@ -41,7 +44,7 @@ def get(log_level: Optional[str]):
@opt_namespace
@opt_kubeconfig
@opt_context
@opt_output_all
@opt_output_auto(V1Alpha1Client)
async def get_client(
name: Optional[str], kubeconfig: Optional[str], context: Optional[str], namespace: str, output: OutputType
):
Expand All @@ -65,7 +68,7 @@ async def get_client(
@opt_namespace
@opt_kubeconfig
@opt_context
@opt_output_all
@opt_output_auto(V1Alpha1Exporter)
@click.option("-d", "--devices", is_flag=True, help="Display the devices hosted by the exporter(s)")
async def get_exporter(
name: Optional[str],
Expand Down Expand Up @@ -95,7 +98,7 @@ async def get_exporter(
@opt_namespace
@opt_kubeconfig
@opt_context
@opt_output_all
@opt_output_auto(V1Alpha1Lease)
async def get_lease(
name: Optional[str], kubeconfig: Optional[str], context: Optional[str], namespace: str, output: OutputType
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def getheaders(self):
credential:
name: test-credential
endpoint: grpc://example.com:443

"""


Expand Down Expand Up @@ -217,7 +216,6 @@ async def test_get_client(_load_kube_config_mock, get_client_mock: AsyncMock):
name: another-credential
endpoint: grpc://example.com:443
kind: ClientList

"""

CLIENTS_LIST_NAME = """client.jumpstarter.dev/test
Expand All @@ -227,7 +225,6 @@ async def test_get_client(_load_kube_config_mock, get_client_mock: AsyncMock):
CLIENTS_LIST_EMPTY_YAML = """apiVersion: jumpstarter.dev/v1alpha1
items: []
kind: ClientList

"""


Expand Down Expand Up @@ -334,7 +331,6 @@ async def test_get_clients(_load_kube_config_mock, list_clients_mock: AsyncMock)
name: test-credential
devices: []
endpoint: grpc://example.com:443

"""


Expand Down Expand Up @@ -448,7 +444,6 @@ async def test_get_exporter(_load_kube_config_mock, get_exporter_mock: AsyncMock
hardware: rpi4
uuid: f7cd30ac-64a3-42c6-ba31-b25f033b97c1
endpoint: grpc://example.com:443

"""


Expand Down Expand Up @@ -592,7 +587,6 @@ async def test_get_exporter_devices(_load_kube_config_mock, get_exporter_mock: A
devices: []
endpoint: grpc://example.com:443
kind: ExporterList

"""

EXPORTERS_LIST_NAME = """exporter.jumpstarter.dev/test
Expand Down Expand Up @@ -760,7 +754,6 @@ async def test_get_exporters(_load_kube_config_mock, list_exporters_mock: AsyncM
uuid: f7cd30ac-64a3-42c6-ba31-b25f033b97c1
endpoint: grpc://example.com:443
kind: ExporterList

"""

EXPORTERS_DEVICES_LIST_NAME = EXPORTERS_LIST_NAME
Expand Down Expand Up @@ -936,7 +929,6 @@ async def test_get_exporters_devices(_load_kube_config_mock, list_exporters_mock
ended: true
exporter:
name: test_exporter

"""


Expand Down Expand Up @@ -1145,7 +1137,6 @@ async def test_get_lease(_load_kube_config_mock, get_lease_mock: AsyncMock):
exporter:
name: test_exporter
kind: LeaseList

"""

LEASES_LIST_NAME = """lease.jumpstarter.dev/82a8ac0d-d7ff-4009-8948-18a3c5c607b1
Expand Down
95 changes: 36 additions & 59 deletions packages/jumpstarter-cli-admin/jumpstarter_cli_admin/print.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import asyncclick as click
from jumpstarter_cli_common import (
OutputMode,
OutputType,
echo,
make_table,
time_since,
)
from jumpstarter_kubernetes import (
V1Alpha1Client,
V1Alpha1Exporter,
V1Alpha1Lease,
V1Alpha1List,
)
from jumpstarter.common.pydantic import SerializableBaseModelList

CLIENT_COLUMNS = ["NAME", "ENDPOINT", "AGE"]

Check failure on line 15 in packages/jumpstarter-cli-admin/jumpstarter_cli_admin/print.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/print.py:1:1: I001 Import block is un-sorted or un-formatted


def make_client_row(client: V1Alpha1Client):
Expand All @@ -24,27 +24,18 @@


def print_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}")
if output:
echo(client.dump(output))
else:
click.echo(make_table(CLIENT_COLUMNS, [make_client_row(client)]))


def print_clients(clients: V1Alpha1List[V1Alpha1Client], namespace: str, output: OutputType):
if output == OutputMode.JSON:
click.echo(clients.dump_json())
elif output == OutputMode.YAML:
click.echo(clients.dump_yaml())
elif output == OutputMode.NAME:
for item in clients.items:
click.echo(f"client.jumpstarter.dev/{item.metadata.name}")
elif len(clients.items) == 0:
raise click.ClickException(f'No resources found in "{namespace}" namespace')
def print_clients(clients: SerializableBaseModelList[V1Alpha1Client], namespace: str, output: OutputType):
if output:
echo(clients.dump(output))
else:
if len(clients.items) == 0:
raise click.ClickException(f'No resources found in "{namespace}" namespace')
click.echo(make_table(CLIENT_COLUMNS, list(map(make_client_row, clients.items))))


Expand Down Expand Up @@ -85,33 +76,28 @@


def print_exporter(exporter: V1Alpha1Exporter, devices: bool, 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}")
elif devices:
# Print the devices for the exporter
click.echo(make_table(DEVICE_COLUMNS, get_device_rows([exporter])))
if output:
echo(exporter.dump(output))
else:
click.echo(make_table(EXPORTER_COLUMNS, [make_exporter_row(exporter)]))


def print_exporters(exporters: V1Alpha1List[V1Alpha1Exporter], namespace: str, devices: bool, output: OutputType):
if output == OutputMode.JSON:
click.echo(exporters.dump_json())
elif output == OutputMode.YAML:
click.echo(exporters.dump_yaml())
elif output == OutputMode.NAME:
for item in exporters.items:
click.echo(f"exporter.jumpstarter.dev/{item.metadata.name}")
elif len(exporters.items) == 0:
raise click.ClickException(f'No resources found in "{namespace}" namespace')
elif devices:
click.echo(make_table(DEVICE_COLUMNS, get_device_rows(exporters.items)))
if devices:
# Print the devices for the exporter
click.echo(make_table(DEVICE_COLUMNS, get_device_rows([exporter])))
else:
click.echo(make_table(EXPORTER_COLUMNS, [make_exporter_row(exporter)]))


def print_exporters(
exporters: SerializableBaseModelList[V1Alpha1Exporter], namespace: str, devices: bool, output: OutputType
):
if output:
echo(exporters.dump(output))
else:
click.echo(make_table(EXPORTER_COLUMNS, list(map(make_exporter_row, exporters.items))))
if len(exporters.items) == 0:
raise click.ClickException(f'No resources found in "{namespace}" namespace')
if devices:
click.echo(make_table(DEVICE_COLUMNS, get_device_rows(exporters.items)))
else:
click.echo(make_table(EXPORTER_COLUMNS, list(map(make_exporter_row, exporters.items))))


LEASE_COLUMNS = ["NAME", "CLIENT", "SELECTOR", "EXPORTER", "STATUS", "REASON", "BEGIN", "END", "DURATION", "AGE"]
Expand Down Expand Up @@ -154,25 +140,16 @@


def print_lease(lease: V1Alpha1Lease, output: OutputType):
if output == OutputMode.JSON:
click.echo(lease.dump_json())
elif output == OutputMode.YAML:
click.echo(lease.dump_yaml())
elif output == OutputMode.NAME:
click.echo(f"lease.jumpstarter.dev/{lease.metadata.name}")
if output:
echo(lease.dump(output))
else:
click.echo(make_table(LEASE_COLUMNS, [make_lease_row(lease)]))


def print_leases(leases: V1Alpha1List[V1Alpha1Lease], namespace: str, output: OutputType):
if output == OutputMode.JSON:
click.echo(leases.dump_json())
elif output == OutputMode.YAML:
click.echo(leases.dump_yaml())
elif output == OutputMode.NAME:
for item in leases.items:
click.echo(f"lease.jumpstarter.dev/{item.metadata.name}")
elif len(leases.items) == 0:
raise click.ClickException(f'No resources found in "{namespace}" namespace')
def print_leases(leases: SerializableBaseModelList[V1Alpha1Lease], namespace: str, output: OutputType):
if output:
echo(leases.dump(output))
else:
if len(leases.items) == 0:
raise click.ClickException(f'No resources found in "{namespace}" namespace')
click.echo(make_table(LEASE_COLUMNS, list(map(make_lease_row, leases.items))))
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .alias import AliasedGroup
from .config import opt_config
from .echo import echo
from .opt import (
NameOutputType,
OutputMode,
Expand All @@ -12,6 +13,7 @@
opt_namespace,
opt_nointeractive,
opt_output_all,
opt_output_auto,
opt_output_name_only,
opt_output_path_only,
)
Expand All @@ -21,6 +23,7 @@

__all__ = [
"AliasedGroup",
"echo",
"make_table",
"opt_config",
"opt_context",
Expand All @@ -32,6 +35,7 @@
"opt_output_all",
"opt_output_name_only",
"opt_output_path_only",
"opt_output_auto",
"OutputMode",
"OutputType",
"NameOutputType",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from functools import partial

import asyncclick as click

echo = partial(click.echo, nl=False)
Loading
Loading