Skip to content

Commit 4b55b22

Browse files
committed
Apply review comments
1 parent 5b3dde1 commit 4b55b22

File tree

6 files changed

+48
-51
lines changed

6 files changed

+48
-51
lines changed

src/kube_galaxy/cmd/status.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
"""Status command handler."""
22

33
import shutil
4+
from collections.abc import Callable
45

56
import typer
67

7-
from kube_galaxy.pkg.utils.client import get_context, get_nodes, wait_for_nodes, wait_for_pods
8+
from kube_galaxy.pkg.utils.client import (
9+
get_cluster_info,
10+
get_context,
11+
get_nodes,
12+
get_pods,
13+
wait_for_nodes,
14+
wait_for_pods,
15+
)
816
from kube_galaxy.pkg.utils.errors import ClusterError
917
from kube_galaxy.pkg.utils.logging import error, info, print_dict, section, success, warning
1018
from kube_galaxy.pkg.utils.shell import run
@@ -70,6 +78,22 @@ def _verify_cluster_health(timeout: int) -> None:
7078
error("Cluster readiness checks failed", show_traceback=False)
7179
raise typer.Exit(code=1) from exc
7280

81+
_print_command_output(get_cluster_info, "Cluster Info")
82+
_print_command_output(get_nodes, "Nodes")
83+
_print_command_output(get_pods, "Pods")
84+
85+
86+
def _print_command_output(command: Callable[[], str], title: str) -> None:
87+
"""Run command and print its output with a section label."""
88+
info("")
89+
info(f"{title}:")
90+
try:
91+
if output := command().strip():
92+
info(output)
93+
except ClusterError as exc:
94+
error(f"Failed to run: {title}", show_traceback=False)
95+
raise typer.Exit(code=1) from exc
96+
7397

7498
def _check_command(cmd: str) -> str:
7599
"""Check if a command is installed and return status."""

src/kube_galaxy/pkg/components/_base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
format_component_pattern,
2626
install_binary,
2727
)
28-
from kube_galaxy.pkg.utils.errors import ComponentError
28+
from kube_galaxy.pkg.utils.errors import ClusterError, ComponentError
2929
from kube_galaxy.pkg.utils.logging import info
3030
from kube_galaxy.pkg.utils.shell import run
3131

@@ -244,7 +244,10 @@ def bootstrap_hook(self) -> None:
244244
raise ComponentError(
245245
f"{comp_name} manifest not downloaded. Run download hook first."
246246
)
247-
apply_manifest(self.manifest_path)
247+
try:
248+
apply_manifest(self.manifest_path)
249+
except ClusterError as e:
250+
raise ComponentError(f"Failed to apply manifest for {comp_name}") from e
248251

249252
pass
250253

src/kube_galaxy/pkg/testing/spread.py

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -146,33 +146,12 @@ def _create_test_namespace(component_name: str) -> str:
146146
# Normalize component name for namespace (lowercase, hyphens only)
147147
namespace = f"kube-galaxy-test-{component_name.lower().replace('_', '-')}"
148148

149-
try:
150-
labels = {
151-
"app.kubernetes.io/managed-by": "kube-galaxy",
152-
"component": component_name,
153-
}
154-
create_namespace(namespace, labels)
155-
return namespace
156-
157-
except ClusterError:
158-
raise
159-
160-
161-
def _cleanup_test_namespace(namespace: str, timeout: int = 60) -> None:
162-
"""
163-
Delete test namespace and wait for termination.
164-
165-
Args:
166-
namespace: Namespace to delete
167-
timeout: Maximum seconds to wait for deletion
168-
169-
Raises:
170-
ClusterError: If namespace deletion fails
171-
"""
172-
try:
173-
delete_namespace(namespace, timeout)
174-
except ClusterError:
175-
raise
149+
labels = {
150+
"app.kubernetes.io/managed-by": "kube-galaxy",
151+
"component": component_name,
152+
}
153+
create_namespace(namespace, labels)
154+
return namespace
176155

177156

178157
def _generate_orchestration_spread_yaml(
@@ -328,11 +307,7 @@ def _run_component_tests(
328307
raise ClusterError("Component validation failed")
329308

330309
# Generate orchestration spread.yaml
331-
try:
332-
component_suites = _generate_orchestration_spread_yaml(spread_components, kubeconfig)
333-
except ClusterError as exc:
334-
error(f"Failed to generate orchestration spread.yaml: {exc}")
335-
raise
310+
component_suites = _generate_orchestration_spread_yaml(spread_components, kubeconfig)
336311

337312
# Track test results
338313
test_results = []
@@ -390,7 +365,7 @@ def _run_component_tests(
390365
# Step 4: Cleanup namespace (always executed)
391366
if namespace:
392367
try:
393-
_cleanup_test_namespace(namespace)
368+
delete_namespace(namespace)
394369
except Exception as cleanup_exc:
395370
warning(f" Namespace cleanup failed: {cleanup_exc}")
396371

src/kube_galaxy/pkg/utils/client.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,6 @@ def get_pod_logs(namespace: str, pod_name: str, tail: int = 100) -> str:
298298
299299
Returns:
300300
Pod logs as string. Returns empty string if pod has no logs.
301-
302-
Raises:
303-
ClusterError: If logs cannot be retrieved (other than missing logs)
304301
"""
305302
result = run(
306303
["kubectl", "logs", "-n", namespace, pod_name, f"--tail={tail}"],

src/kube_galaxy/pkg/utils/logs.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,14 @@ def _collect_pod_logs(output_path: Path) -> None:
104104
namespace = pod_item["metadata"]["namespace"]
105105
pod_name = pod_item["metadata"]["name"]
106106

107-
try:
108-
# Get pod logs
109-
log_content = get_pod_logs(namespace, pod_name, tail=100)
110-
111-
log_dir = pods_dir / namespace / pod_name
112-
log_dir.mkdir(parents=True, exist_ok=True)
113-
(log_dir / "logs.txt").write_text(log_content)
114-
115-
pod_count += 1
116-
except ClusterError:
117-
# Pod might not have logs, skip
118-
pass
107+
# Get pod logs
108+
log_content = get_pod_logs(namespace, pod_name, tail=100)
109+
110+
log_dir = pods_dir / namespace / pod_name
111+
log_dir.mkdir(parents=True, exist_ok=True)
112+
(log_dir / "logs.txt").write_text(log_content)
113+
114+
pod_count += 1
119115

120116
success(f" Pod logs saved ({pod_count} pods)")
121117

tests/unit/test_status.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def fake_get_nodes():
2929
monkeypatch.setattr(status_cmd, "wait_for_pods", fake_wait_for_pods)
3030
monkeypatch.setattr(status_cmd, "get_context", fake_get_context)
3131
monkeypatch.setattr(status_cmd, "get_nodes", fake_get_nodes)
32+
monkeypatch.setattr(status_cmd, "get_cluster_info", lambda: "cluster-info")
33+
monkeypatch.setattr(status_cmd, "get_pods", lambda: "pods-output")
3234
monkeypatch.setattr(status_cmd, "_check_command", lambda _cmd: "ok")
3335
monkeypatch.setattr(status_cmd.shutil, "which", lambda _cmd: "/usr/bin/tool")
3436

0 commit comments

Comments
 (0)