diff --git a/ariadne/services/cluster_state.py b/ariadne/services/cluster_state.py index 51666ad..a720f23 100644 --- a/ariadne/services/cluster_state.py +++ b/ariadne/services/cluster_state.py @@ -1068,7 +1068,10 @@ def _summarize_longhorn_volumes(payload: dict[str, Any]) -> dict[str, Any]: return {} by_state: dict[str, int] = {} by_robustness: dict[str, int] = {} - unhealthy: list[dict[str, Any]] = [] + degraded: list[dict[str, Any]] = [] + attached_count = 0 + detached_count = 0 + degraded_count = 0 for volume in items: metadata = volume.get("metadata") if isinstance(volume.get("metadata"), dict) else {} status = volume.get("status") if isinstance(volume.get("status"), dict) else {} @@ -1080,10 +1083,17 @@ def _summarize_longhorn_volumes(payload: dict[str, Any]) -> dict[str, Any]: robustness = ( status.get("robustness") if isinstance(status.get("robustness"), str) else "unknown" ) + state_lower = state.lower() + robustness_lower = robustness.lower() by_state[state] = by_state.get(state, 0) + 1 by_robustness[robustness] = by_robustness.get(robustness, 0) + 1 - if state.lower() != "attached" or robustness.lower() != "healthy": - unhealthy.append( + if state_lower == "attached": + attached_count += 1 + elif state_lower == "detached": + detached_count += 1 + if robustness_lower in {"degraded", "faulted"}: + degraded_count += 1 + degraded.append( { "name": name, "state": state, @@ -1092,13 +1102,15 @@ def _summarize_longhorn_volumes(payload: dict[str, Any]) -> dict[str, Any]: "actual_size": status.get("actualSize"), } ) - unhealthy.sort(key=lambda item: item.get("name") or "") + degraded.sort(key=lambda item: item.get("name") or "") return { "total": len(items), "by_state": by_state, "by_robustness": by_robustness, - "unhealthy": unhealthy, - "unhealthy_count": len(unhealthy), + "attached_count": attached_count, + "detached_count": detached_count, + "degraded": degraded, + "degraded_count": degraded_count, }