feat(ui): per-kind table columns for non-pod resources (#18)
* feat(ui): per-kind table columns for non-pod resources Non-pod views collapsed every resource to a single loose "Summary" string (label count / service type / "-"). Replace it with meaningful, fixed-width, kubectl-style columns per kind, rendered after the universal Namespace/Name/Status/Age: - deploy UP-TO-DATE/AVAILABLE, rs DESIRED/CURRENT/READY, sts READY, ds DESIRED/READY/AVAIL - svc TYPE/CLUSTER-IP/PORTS, ing CLASS/HOSTS/ADDRESS - job COMPLETIONS/DURATION, cronjob SCHEDULE/SUSPEND/ACTIVE - cm DATA, secret TYPE/DATA, sa SECRETS - node ROLES/VERSION - pvc VOLUME/CAPACITY/ACCESS/STORAGECLASS, pv adds RECLAIM/CLAIM - hpa REFERENCE/MINPODS/MAXPODS/REPLICAS, pdb MIN-AVAIL/MAX-UNAVAIL/ALLOWED ResourceKind::extra_columns() is the single source of truth for header labels and widths; extract_columns() in the provider emits the matching row values. A contract test asserts the two stay in lockstep for all 24 kinds. Entity model: summary: String -> columns: Vec<String>. Pods now carry an empty vec, dropping the previously-unused per-pod "node=" string on the 10k-pod hot path. Filtering and :dump/copy span all columns; kinds without distinctive columns render just the four universal ones. Tests: contract count check, deployment/service/pvc extraction, non-pod render snapshot (kind headers replace generic Summary). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(ui): richer ServiceAccount and RoleBinding columns ServiceAccounts showed only a SECRETS count (often 0 on k8s ≥1.24); RoleBindings/ClusterRoleBindings had no kind-specific columns at all (empty fallback). Add meaningful columns: - ServiceAccounts: SECRETS, PULL-SECRETS (imagePullSecrets count) - RoleBindings / ClusterRoleBindings: ROLE (roleRef kind/name, e.g. ClusterRole/view) and SUBJECTS (abbreviated kind:name list, e.g. sa:build,u:alice) Test: rolebinding role/subjects extraction; the all-kinds column-count contract test covers the new headers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
517502fef6
commit
8cbe27e7f3
8 files changed
+594
-57
No files matched your search
@@ -215,6 +215,14 @@ Root problem: full object JSON kept for every entity.
|
||||
arrow (`Name ↑` / `Status ↓`), the top bar carries a `[SORT] <col><arrow>` field, and `:sort
|
||||
<name|namespace|status|age> [asc|desc]` sets it explicitly (added to command autocomplete). Tests:
|
||||
header-arrow render snapshot + `:sort` column/direction parsing.
|
||||
**Per-kind columns**: non-pod views no longer collapse to a loose `Summary` string — each kind
|
||||
renders meaningful, fixed-width columns after the universal Namespace/Name/Status/Age (deploy
|
||||
UP-TO-DATE/AVAILABLE, svc TYPE/CLUSTER-IP/PORTS, pvc VOLUME/CAPACITY/ACCESS/STORAGECLASS, hpa,
|
||||
cronjob, node ROLES/VERSION, etc.). Single source of truth `ResourceKind::extra_columns()` drives
|
||||
both header and `extract_columns()` row values; a contract test asserts they stay in lockstep for
|
||||
all 24 kinds. Entity model: `summary: String` → `columns: Vec<String>` (pods now carry an empty
|
||||
vec — drops the unused per-pod `node=` string on the 10k-pod hot path). Filter + `:dump`/copy span
|
||||
all columns.
|
||||
Remaining: revisit when new views/commands land (e.g. interactive dynamic-list overlay).
|
||||
- [ ] **5.3 Config defaults for large fleets** — review fps_limit / delta_channel_capacity /
|
||||
warm_contexts / TTL defaults; document tuning.
|
||||
|
||||
@@ -72,6 +72,30 @@ Press `E` on any resource (pod, deployment, node, …) to see **its** events —
|
||||
`involvedObject` is that resource — newest first (LAST / TYPE / REASON / COUNT / SOURCE / MESSAGE),
|
||||
like the Events section of `kubectl describe`. Selecting an Event resource itself shows its manifest.
|
||||
|
||||
## Resource Columns
|
||||
|
||||
Every table starts with the universal columns **Namespace · Name · Status · Age**. Beyond those,
|
||||
each kind shows columns tailored to it (like `kubectl get`), e.g.:
|
||||
|
||||
- **Deployments** — `UP-TO-DATE`, `AVAILABLE`
|
||||
- **ReplicaSets** — `DESIRED`, `CURRENT`, `READY`
|
||||
- **StatefulSets** — `READY`
|
||||
- **DaemonSets** — `DESIRED`, `READY`, `AVAIL`
|
||||
- **Services** — `TYPE`, `CLUSTER-IP`, `PORTS`
|
||||
- **Ingresses** — `CLASS`, `HOSTS`, `ADDRESS`
|
||||
- **Jobs** — `COMPLETIONS`, `DURATION`
|
||||
- **CronJobs** — `SCHEDULE`, `SUSPEND`, `ACTIVE`
|
||||
- **ConfigMaps** — `DATA`; **Secrets** — `TYPE`, `DATA`
|
||||
- **ServiceAccounts** — `SECRETS`, `PULL-SECRETS`
|
||||
- **RoleBindings / ClusterRoleBindings** — `ROLE` (e.g. `ClusterRole/view`), `SUBJECTS` (e.g. `sa:build,u:alice`)
|
||||
- **Nodes** — `ROLES`, `VERSION`
|
||||
- **PVCs** — `VOLUME`, `CAPACITY`, `ACCESS`, `STORAGECLASS`; **PVs** add `RECLAIM`, `CLAIM`
|
||||
- **HPAs** — `REFERENCE`, `MINPODS`, `MAXPODS`, `REPLICAS`
|
||||
- **PodDisruptionBudgets** — `MIN-AVAIL`, `MAX-UNAVAIL`, `ALLOWED`
|
||||
|
||||
Kinds without distinctive columns show just the four universal ones. Pods are special — see Metrics.
|
||||
Filtering and `:dump`/copy operate over all visible columns.
|
||||
|
||||
## Metrics
|
||||
|
||||
If the cluster has a metrics-server (`metrics.k8s.io`), krust shows live usage and right-sizing.
|
||||
|
||||
+382
-24
@@ -1032,7 +1032,7 @@ where
|
||||
.collect();
|
||||
|
||||
let status = extract_status(kind, &raw);
|
||||
let summary = extract_summary(kind, &raw);
|
||||
let columns = extract_columns(kind, &raw);
|
||||
// Extract the few scalar fields the all-rows hot paths need, then drop the full JSON.
|
||||
let extracted = extracted_for(kind, &raw);
|
||||
|
||||
@@ -1041,7 +1041,7 @@ where
|
||||
status,
|
||||
age,
|
||||
labels,
|
||||
summary,
|
||||
columns,
|
||||
extracted,
|
||||
})
|
||||
}
|
||||
@@ -1115,28 +1115,300 @@ fn extract_pod_status(raw: &serde_json::Value) -> String {
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn extract_summary(kind: ResourceKind, raw: &serde_json::Value) -> String {
|
||||
/// Produce the kind-specific column values for an entity, in the exact order declared by
|
||||
/// [`ResourceKind::extra_columns`]. The lengths must match (enforced by `kind_columns_contract`).
|
||||
fn extract_columns(kind: ResourceKind, raw: &serde_json::Value) -> Vec<String> {
|
||||
// Small readers over the raw JSON.
|
||||
let s = |p: &str| {
|
||||
raw.pointer(p)
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.map(str::to_string)
|
||||
};
|
||||
let i = |p: &str| raw.pointer(p).and_then(serde_json::Value::as_i64);
|
||||
let int_cell = |p: &str| i(p).unwrap_or(0).to_string();
|
||||
// Count of keys in an object (ConfigMap/Secret `data`) or elements in an array.
|
||||
let count = |p: &str| match raw.pointer(p) {
|
||||
Some(serde_json::Value::Object(m)) => m.len().to_string(),
|
||||
Some(serde_json::Value::Array(a)) => a.len().to_string(),
|
||||
_ => "0".to_string(),
|
||||
};
|
||||
let dash = || "-".to_string();
|
||||
|
||||
match kind {
|
||||
ResourceKind::Pods => raw
|
||||
.pointer("/spec/nodeName")
|
||||
ResourceKind::Deployments => vec![
|
||||
int_cell("/status/updatedReplicas"),
|
||||
int_cell("/status/availableReplicas"),
|
||||
],
|
||||
ResourceKind::ReplicaSets => vec![
|
||||
int_cell("/spec/replicas"),
|
||||
int_cell("/status/replicas"),
|
||||
int_cell("/status/readyReplicas"),
|
||||
],
|
||||
ResourceKind::StatefulSets => vec![format!(
|
||||
"{}/{}",
|
||||
i("/status/readyReplicas").unwrap_or(0),
|
||||
i("/spec/replicas").unwrap_or(0)
|
||||
)],
|
||||
ResourceKind::DaemonSets => vec![
|
||||
int_cell("/status/desiredNumberScheduled"),
|
||||
int_cell("/status/numberReady"),
|
||||
int_cell("/status/numberAvailable"),
|
||||
],
|
||||
ResourceKind::Services => vec![
|
||||
s("/spec/type").unwrap_or_else(|| "ClusterIP".to_string()),
|
||||
s("/spec/clusterIP").unwrap_or_else(dash),
|
||||
service_ports(raw),
|
||||
],
|
||||
ResourceKind::Ingresses => vec![
|
||||
s("/spec/ingressClassName").unwrap_or_else(dash),
|
||||
ingress_hosts(raw),
|
||||
ingress_address(raw),
|
||||
],
|
||||
ResourceKind::Jobs => vec![
|
||||
format!(
|
||||
"{}/{}",
|
||||
i("/status/succeeded").unwrap_or(0),
|
||||
i("/spec/completions")
|
||||
.map(|c| c.to_string())
|
||||
.unwrap_or_else(|| "1".to_string())
|
||||
),
|
||||
job_duration(raw),
|
||||
],
|
||||
ResourceKind::CronJobs => vec![
|
||||
s("/spec/schedule").unwrap_or_else(dash),
|
||||
raw.pointer("/spec/suspend")
|
||||
.and_then(serde_json::Value::as_bool)
|
||||
.unwrap_or(false)
|
||||
.to_string(),
|
||||
count("/status/active"),
|
||||
],
|
||||
ResourceKind::ConfigMaps => vec![count("/data")],
|
||||
ResourceKind::Secrets => vec![
|
||||
s("/type").unwrap_or_else(|| "Opaque".to_string()),
|
||||
count("/data"),
|
||||
],
|
||||
ResourceKind::Nodes => vec![
|
||||
node_roles(raw),
|
||||
s("/status/nodeInfo/kubeletVersion").unwrap_or_else(dash),
|
||||
],
|
||||
ResourceKind::PersistentVolumeClaims => vec![
|
||||
s("/spec/volumeName").unwrap_or_else(dash),
|
||||
s("/status/capacity/storage").unwrap_or_else(dash),
|
||||
access_modes(raw),
|
||||
s("/spec/storageClassName").unwrap_or_else(dash),
|
||||
],
|
||||
ResourceKind::PersistentVolumes => vec![
|
||||
s("/spec/capacity/storage").unwrap_or_else(dash),
|
||||
access_modes(raw),
|
||||
s("/spec/persistentVolumeReclaimPolicy").unwrap_or_else(dash),
|
||||
pv_claim(raw),
|
||||
s("/spec/storageClassName").unwrap_or_else(dash),
|
||||
],
|
||||
ResourceKind::HorizontalPodAutoscalers => vec![
|
||||
format!(
|
||||
"{}/{}",
|
||||
s("/spec/scaleTargetRef/kind").unwrap_or_else(dash),
|
||||
s("/spec/scaleTargetRef/name").unwrap_or_else(dash)
|
||||
),
|
||||
int_cell("/spec/minReplicas"),
|
||||
int_cell("/spec/maxReplicas"),
|
||||
int_cell("/status/currentReplicas"),
|
||||
],
|
||||
ResourceKind::ServiceAccounts => vec![count("/secrets"), count("/imagePullSecrets")],
|
||||
ResourceKind::RoleBindings | ResourceKind::ClusterRoleBindings => {
|
||||
vec![role_ref(raw), subjects_summary(raw)]
|
||||
}
|
||||
ResourceKind::PodDisruptionBudgets => vec![
|
||||
int_or_str("/spec/minAvailable", raw),
|
||||
int_or_str("/spec/maxUnavailable", raw),
|
||||
int_cell("/status/disruptionsAllowed"),
|
||||
],
|
||||
_ => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
/// `spec.ports[]` rendered as `port/proto` joined by commas (e.g. `80/TCP,443/TCP`).
|
||||
fn service_ports(raw: &serde_json::Value) -> String {
|
||||
let Some(ports) = raw.pointer("/spec/ports").and_then(|v| v.as_array()) else {
|
||||
return "-".to_string();
|
||||
};
|
||||
let rendered: Vec<String> = ports
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let port = p.pointer("/port").and_then(serde_json::Value::as_i64);
|
||||
let proto = p
|
||||
.pointer("/protocol")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or("TCP");
|
||||
match port {
|
||||
Some(port) => format!("{port}/{proto}"),
|
||||
None => proto.to_string(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
if rendered.is_empty() {
|
||||
"-".to_string()
|
||||
} else {
|
||||
rendered.join(",")
|
||||
}
|
||||
}
|
||||
|
||||
/// Distinct `spec.rules[].host` values joined by commas.
|
||||
fn ingress_hosts(raw: &serde_json::Value) -> String {
|
||||
let Some(rules) = raw.pointer("/spec/rules").and_then(|v| v.as_array()) else {
|
||||
return "-".to_string();
|
||||
};
|
||||
let hosts: Vec<&str> = rules
|
||||
.iter()
|
||||
.filter_map(|r| r.pointer("/host").and_then(serde_json::Value::as_str))
|
||||
.collect();
|
||||
if hosts.is_empty() {
|
||||
"*".to_string()
|
||||
} else {
|
||||
hosts.join(",")
|
||||
}
|
||||
}
|
||||
|
||||
/// First `status.loadBalancer.ingress[]` ip or hostname.
|
||||
fn ingress_address(raw: &serde_json::Value) -> String {
|
||||
raw.pointer("/status/loadBalancer/ingress")
|
||||
.and_then(|v| v.as_array())
|
||||
.and_then(|a| a.first())
|
||||
.and_then(|e| {
|
||||
e.pointer("/ip")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.or_else(|| e.pointer("/hostname").and_then(serde_json::Value::as_str))
|
||||
})
|
||||
.map(str::to_string)
|
||||
.unwrap_or_else(|| "-".to_string())
|
||||
}
|
||||
|
||||
/// Job wall-clock duration from `status.startTime` to `status.completionTime` (or now).
|
||||
fn job_duration(raw: &serde_json::Value) -> String {
|
||||
let parse = |p: &str| {
|
||||
raw.pointer(p)
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.map(|node| format!("node={node}"))
|
||||
.unwrap_or_else(|| "-".to_string()),
|
||||
ResourceKind::Services => raw
|
||||
.pointer("/spec/type")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or("ClusterIP")
|
||||
.to_string(),
|
||||
ResourceKind::Events => raw
|
||||
.pointer("/reason")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or("-")
|
||||
.to_string(),
|
||||
_ => raw
|
||||
.pointer("/metadata/labels")
|
||||
.and_then(serde_json::Value::as_object)
|
||||
.map(|labels| format!("{} labels", labels.len()))
|
||||
.unwrap_or_else(|| "-".to_string()),
|
||||
.and_then(|t| DateTime::parse_from_rfc3339(t).ok())
|
||||
.map(|t| t.with_timezone(&Utc))
|
||||
};
|
||||
let Some(start) = parse("/status/startTime") else {
|
||||
return "-".to_string();
|
||||
};
|
||||
let end = parse("/status/completionTime").unwrap_or_else(Utc::now);
|
||||
let secs = end.signed_duration_since(start).num_seconds().max(0);
|
||||
if secs >= 3600 {
|
||||
format!("{}h{}m", secs / 3600, (secs % 3600) / 60)
|
||||
} else if secs >= 60 {
|
||||
format!("{}m{}s", secs / 60, secs % 60)
|
||||
} else {
|
||||
format!("{secs}s")
|
||||
}
|
||||
}
|
||||
|
||||
/// Role names from `node-role.kubernetes.io/<role>` labels, joined by commas.
|
||||
fn node_roles(raw: &serde_json::Value) -> String {
|
||||
let Some(labels) = raw.pointer("/metadata/labels").and_then(|v| v.as_object()) else {
|
||||
return "<none>".to_string();
|
||||
};
|
||||
let roles: Vec<&str> = labels
|
||||
.keys()
|
||||
.filter_map(|k| k.strip_prefix("node-role.kubernetes.io/"))
|
||||
.filter(|r| !r.is_empty())
|
||||
.collect();
|
||||
if roles.is_empty() {
|
||||
"<none>".to_string()
|
||||
} else {
|
||||
roles.join(",")
|
||||
}
|
||||
}
|
||||
|
||||
/// `spec.accessModes[]` abbreviated (RWO/ROX/RWX/RWOP) and joined.
|
||||
fn access_modes(raw: &serde_json::Value) -> String {
|
||||
let Some(modes) = raw.pointer("/spec/accessModes").and_then(|v| v.as_array()) else {
|
||||
return "-".to_string();
|
||||
};
|
||||
let abbr: Vec<&str> = modes
|
||||
.iter()
|
||||
.filter_map(serde_json::Value::as_str)
|
||||
.map(|m| match m {
|
||||
"ReadWriteOnce" => "RWO",
|
||||
"ReadOnlyMany" => "ROX",
|
||||
"ReadWriteMany" => "RWX",
|
||||
"ReadWriteOncePod" => "RWOP",
|
||||
other => other,
|
||||
})
|
||||
.collect();
|
||||
if abbr.is_empty() {
|
||||
"-".to_string()
|
||||
} else {
|
||||
abbr.join(",")
|
||||
}
|
||||
}
|
||||
|
||||
/// PV bound claim as `namespace/name`.
|
||||
fn pv_claim(raw: &serde_json::Value) -> String {
|
||||
let ns = raw
|
||||
.pointer("/spec/claimRef/namespace")
|
||||
.and_then(serde_json::Value::as_str);
|
||||
let name = raw
|
||||
.pointer("/spec/claimRef/name")
|
||||
.and_then(serde_json::Value::as_str);
|
||||
match (ns, name) {
|
||||
(Some(ns), Some(name)) => format!("{ns}/{name}"),
|
||||
(None, Some(name)) => name.to_string(),
|
||||
_ => "-".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Role/ClusterRole referenced by a (Cluster)RoleBinding, as `kind/name` (e.g. `ClusterRole/view`).
|
||||
fn role_ref(raw: &serde_json::Value) -> String {
|
||||
let kind = raw
|
||||
.pointer("/roleRef/kind")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or("-");
|
||||
let name = raw
|
||||
.pointer("/roleRef/name")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or("-");
|
||||
format!("{kind}/{name}")
|
||||
}
|
||||
|
||||
/// Binding subjects as `abbrev:name` joined by commas (sa/u/g for ServiceAccount/User/Group).
|
||||
fn subjects_summary(raw: &serde_json::Value) -> String {
|
||||
let Some(subjects) = raw.pointer("/subjects").and_then(|v| v.as_array()) else {
|
||||
return "-".to_string();
|
||||
};
|
||||
let parts: Vec<String> = subjects
|
||||
.iter()
|
||||
.map(|s| {
|
||||
let kind = s.pointer("/kind").and_then(serde_json::Value::as_str);
|
||||
let name = s
|
||||
.pointer("/name")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or("?");
|
||||
let abbr = match kind {
|
||||
Some("ServiceAccount") => "sa",
|
||||
Some("User") => "u",
|
||||
Some("Group") => "g",
|
||||
Some(other) => other,
|
||||
None => "?",
|
||||
};
|
||||
format!("{abbr}:{name}")
|
||||
})
|
||||
.collect();
|
||||
if parts.is_empty() {
|
||||
"-".to_string()
|
||||
} else {
|
||||
parts.join(",")
|
||||
}
|
||||
}
|
||||
|
||||
/// A field that may be an integer or a percentage string (e.g. PDB `minAvailable`).
|
||||
fn int_or_str(pointer: &str, raw: &serde_json::Value) -> String {
|
||||
match raw.pointer(pointer) {
|
||||
Some(serde_json::Value::Number(n)) => n.to_string(),
|
||||
Some(serde_json::Value::String(s)) => s.clone(),
|
||||
_ => "-".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1234,8 +1506,8 @@ mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
use super::{
|
||||
ActionError, KubeResourceProvider, api_resource_spec_for_kind, extract_status,
|
||||
is_forbidden_watcher_error, next_watch_backoff, select_warm_contexts,
|
||||
ActionError, KubeResourceProvider, api_resource_spec_for_kind, extract_columns,
|
||||
extract_status, is_forbidden_watcher_error, next_watch_backoff, select_warm_contexts,
|
||||
};
|
||||
use crate::{
|
||||
cluster::ActionExecutor,
|
||||
@@ -1521,6 +1793,92 @@ mod tests {
|
||||
assert_eq!(status, "ImagePullBackOff");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_columns_matches_declared_header_count_for_every_kind() {
|
||||
// The header (ResourceKind::extra_columns) and the per-row values (extract_columns) must
|
||||
// stay in lockstep; an empty object exercises every default branch.
|
||||
for kind in ResourceKind::ORDERED {
|
||||
let values = extract_columns(kind, &json!({}));
|
||||
assert_eq!(
|
||||
values.len(),
|
||||
kind.extra_columns().len(),
|
||||
"{kind} column count mismatch: {values:?} vs headers {:?}",
|
||||
kind.extra_columns()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_columns_renders_deployment_and_service_fields() {
|
||||
let deploy = json!({
|
||||
"spec": { "replicas": 3 },
|
||||
"status": { "readyReplicas": 2, "updatedReplicas": 3, "availableReplicas": 2 }
|
||||
});
|
||||
// headers: UP-TO-DATE, AVAILABLE
|
||||
assert_eq!(
|
||||
extract_columns(ResourceKind::Deployments, &deploy),
|
||||
vec!["3".to_string(), "2".to_string()]
|
||||
);
|
||||
|
||||
let svc = json!({
|
||||
"spec": {
|
||||
"type": "LoadBalancer",
|
||||
"clusterIP": "10.0.0.5",
|
||||
"ports": [ { "port": 80, "protocol": "TCP" }, { "port": 443, "protocol": "TCP" } ]
|
||||
}
|
||||
});
|
||||
// headers: TYPE, CLUSTER-IP, PORTS
|
||||
assert_eq!(
|
||||
extract_columns(ResourceKind::Services, &svc),
|
||||
vec![
|
||||
"LoadBalancer".to_string(),
|
||||
"10.0.0.5".to_string(),
|
||||
"80/TCP,443/TCP".to_string()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_columns_abbreviates_pvc_access_modes() {
|
||||
let pvc = json!({
|
||||
"spec": {
|
||||
"volumeName": "pv-001",
|
||||
"accessModes": ["ReadWriteOnce"],
|
||||
"storageClassName": "gp3"
|
||||
},
|
||||
"status": { "capacity": { "storage": "10Gi" } }
|
||||
});
|
||||
// headers: VOLUME, CAPACITY, ACCESS, STORAGECLASS
|
||||
assert_eq!(
|
||||
extract_columns(ResourceKind::PersistentVolumeClaims, &pvc),
|
||||
vec![
|
||||
"pv-001".to_string(),
|
||||
"10Gi".to_string(),
|
||||
"RWO".to_string(),
|
||||
"gp3".to_string()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extract_columns_summarizes_rolebinding_role_and_subjects() {
|
||||
let rb = json!({
|
||||
"roleRef": { "kind": "ClusterRole", "name": "view" },
|
||||
"subjects": [
|
||||
{ "kind": "ServiceAccount", "name": "build", "namespace": "ci" },
|
||||
{ "kind": "User", "name": "alice" }
|
||||
]
|
||||
});
|
||||
// headers: ROLE, SUBJECTS
|
||||
assert_eq!(
|
||||
extract_columns(ResourceKind::RoleBindings, &rb),
|
||||
vec![
|
||||
"ClusterRole/view".to_string(),
|
||||
"sa:build,u:alice".to_string()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
fn readonly_provider() -> KubeResourceProvider {
|
||||
KubeResourceProvider {
|
||||
contexts: vec!["ctx".to_string()],
|
||||
|
||||
+103
-1
@@ -99,6 +99,106 @@ impl ResourceKind {
|
||||
| ResourceKind::ClusterRoleBindings
|
||||
)
|
||||
}
|
||||
|
||||
/// Kind-specific table columns shown after the universal Namespace/Name/Status/Age.
|
||||
///
|
||||
/// This is the single source of truth for both the table header (labels + widths) and the
|
||||
/// per-row values: `extract_columns` in the cluster provider MUST emit exactly these values,
|
||||
/// in this order, for the same kind. The
|
||||
/// `extract_columns_matches_declared_header_count_for_every_kind` test enforces the count.
|
||||
/// Kinds with no meaningful extra columns return `&[]` and render with just the four
|
||||
/// universal columns.
|
||||
pub fn extra_columns(self) -> &'static [ExtraColumn] {
|
||||
use ExtraColumn as C;
|
||||
const DEPLOY: &[ExtraColumn] = &[C::new("UP-TO-DATE", 11), C::new("AVAILABLE", 10)];
|
||||
const RS: &[ExtraColumn] = &[
|
||||
C::new("DESIRED", 8),
|
||||
C::new("CURRENT", 8),
|
||||
C::new("READY", 7),
|
||||
];
|
||||
const STS: &[ExtraColumn] = &[C::new("READY", 8)];
|
||||
const DS: &[ExtraColumn] = &[C::new("DESIRED", 8), C::new("READY", 7), C::new("AVAIL", 7)];
|
||||
const SVC: &[ExtraColumn] = &[
|
||||
C::new("TYPE", 13),
|
||||
C::new("CLUSTER-IP", 16),
|
||||
C::new("PORTS", 22),
|
||||
];
|
||||
const ING: &[ExtraColumn] = &[
|
||||
C::new("CLASS", 12),
|
||||
C::new("HOSTS", 30),
|
||||
C::new("ADDRESS", 20),
|
||||
];
|
||||
const JOB: &[ExtraColumn] = &[C::new("COMPLETIONS", 12), C::new("DURATION", 10)];
|
||||
const CJ: &[ExtraColumn] = &[
|
||||
C::new("SCHEDULE", 14),
|
||||
C::new("SUSPEND", 8),
|
||||
C::new("ACTIVE", 7),
|
||||
];
|
||||
const CM: &[ExtraColumn] = &[C::new("DATA", 6)];
|
||||
const SECRET: &[ExtraColumn] = &[C::new("TYPE", 30), C::new("DATA", 6)];
|
||||
const NODE: &[ExtraColumn] = &[C::new("ROLES", 20), C::new("VERSION", 16)];
|
||||
const PVC: &[ExtraColumn] = &[
|
||||
C::new("VOLUME", 22),
|
||||
C::new("CAPACITY", 10),
|
||||
C::new("ACCESS", 10),
|
||||
C::new("STORAGECLASS", 16),
|
||||
];
|
||||
const PV: &[ExtraColumn] = &[
|
||||
C::new("CAPACITY", 10),
|
||||
C::new("ACCESS", 10),
|
||||
C::new("RECLAIM", 10),
|
||||
C::new("CLAIM", 26),
|
||||
C::new("STORAGECLASS", 16),
|
||||
];
|
||||
const HPA: &[ExtraColumn] = &[
|
||||
C::new("REFERENCE", 26),
|
||||
C::new("MINPODS", 8),
|
||||
C::new("MAXPODS", 8),
|
||||
C::new("REPLICAS", 9),
|
||||
];
|
||||
const SA: &[ExtraColumn] = &[C::new("SECRETS", 8), C::new("PULL-SECRETS", 13)];
|
||||
const BINDING: &[ExtraColumn] = &[C::new("ROLE", 26), C::new("SUBJECTS", 34)];
|
||||
const PDB: &[ExtraColumn] = &[
|
||||
C::new("MIN-AVAIL", 10),
|
||||
C::new("MAX-UNAVAIL", 12),
|
||||
C::new("ALLOWED", 8),
|
||||
];
|
||||
match self {
|
||||
ResourceKind::Deployments => DEPLOY,
|
||||
ResourceKind::ReplicaSets => RS,
|
||||
ResourceKind::StatefulSets => STS,
|
||||
ResourceKind::DaemonSets => DS,
|
||||
ResourceKind::Services => SVC,
|
||||
ResourceKind::Ingresses => ING,
|
||||
ResourceKind::Jobs => JOB,
|
||||
ResourceKind::CronJobs => CJ,
|
||||
ResourceKind::ConfigMaps => CM,
|
||||
ResourceKind::Secrets => SECRET,
|
||||
ResourceKind::Nodes => NODE,
|
||||
ResourceKind::PersistentVolumeClaims => PVC,
|
||||
ResourceKind::PersistentVolumes => PV,
|
||||
ResourceKind::HorizontalPodAutoscalers => HPA,
|
||||
ResourceKind::ServiceAccounts => SA,
|
||||
ResourceKind::RoleBindings | ResourceKind::ClusterRoleBindings => BINDING,
|
||||
ResourceKind::PodDisruptionBudgets => PDB,
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A kind-specific table column appended after the universal Namespace/Name/Status/Age columns.
|
||||
/// See [`ResourceKind::extra_columns`] for the header/value contract.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct ExtraColumn {
|
||||
pub header: &'static str,
|
||||
/// Fixed display width in cells.
|
||||
pub width: u16,
|
||||
}
|
||||
|
||||
impl ExtraColumn {
|
||||
pub const fn new(header: &'static str, width: u16) -> Self {
|
||||
ExtraColumn { header, width }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ResourceKind {
|
||||
@@ -163,7 +263,9 @@ pub struct ResourceEntity {
|
||||
pub status: String,
|
||||
pub age: Option<DateTime<Utc>>,
|
||||
pub labels: Vec<(String, String)>,
|
||||
pub summary: String,
|
||||
/// Kind-specific column values, in the order declared by [`ResourceKind::extra_columns`].
|
||||
/// Empty for kinds (and pods, which render live metric columns) that have no extra columns.
|
||||
pub columns: Vec<String>,
|
||||
/// Compact fields extracted once at ingest for the all-rows hot paths (pulse aggregates,
|
||||
/// log fan-in owner mapping, container pickers). The full object is fetched on demand for
|
||||
/// detail/describe/edit via `ResourceProvider::get_object`, never retained per row.
|
||||
|
||||
+1
-1
@@ -224,7 +224,7 @@ mod tests {
|
||||
status: "Running".to_string(),
|
||||
age: Some(Utc::now()),
|
||||
labels: vec![("app".to_string(), "demo".to_string())],
|
||||
summary: "test".to_string(),
|
||||
columns: vec![],
|
||||
extracted: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
+48
-6
@@ -1365,14 +1365,24 @@ impl App {
|
||||
let request = self.view_request_for_tab(&active);
|
||||
let vm = self.projected_view(&request);
|
||||
let mut lines = Vec::with_capacity(vm.len().saturating_add(1));
|
||||
lines.push("namespace\tname\tstatus\tage\tsummary".to_string());
|
||||
let mut header = String::from("namespace\tname\tstatus\tage");
|
||||
for col in active.kind().extra_columns() {
|
||||
header.push('\t');
|
||||
header.push_str(col.header);
|
||||
}
|
||||
lines.push(header);
|
||||
// Copy/dump materializes the full list (user-initiated, not a hot path).
|
||||
for key in &vm.order {
|
||||
if let Some(row) = materialize_row(&self.store, key) {
|
||||
lines.push(format!(
|
||||
"{}\t{}\t{}\t{}\t{}",
|
||||
row.namespace, row.name, row.status, row.age, row.summary
|
||||
));
|
||||
let mut line = format!(
|
||||
"{}\t{}\t{}\t{}",
|
||||
row.namespace, row.name, row.status, row.age
|
||||
);
|
||||
for cell in &row.columns {
|
||||
line.push('\t');
|
||||
line.push_str(cell);
|
||||
}
|
||||
lines.push(line);
|
||||
}
|
||||
}
|
||||
Some(lines.join("\n"))
|
||||
@@ -2594,7 +2604,12 @@ mod tests {
|
||||
status: status.to_string(),
|
||||
age: Some(Utc::now()),
|
||||
labels: vec![("app".to_string(), "demo".to_string())],
|
||||
summary: "snapshot".to_string(),
|
||||
// Match the kind's column count so header/cell widths line up in render tests.
|
||||
columns: kind
|
||||
.extra_columns()
|
||||
.iter()
|
||||
.map(|_| "-".to_string())
|
||||
.collect(),
|
||||
extracted: Default::default(),
|
||||
}
|
||||
}
|
||||
@@ -3100,6 +3115,33 @@ mod tests {
|
||||
assert!(snap.contains("[SORT] status↓"), "sort top bar: {snap}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_pod_table_renders_kind_specific_columns() {
|
||||
let mut app = test_app();
|
||||
let kind_idx = ResourceKind::ORDERED
|
||||
.iter()
|
||||
.position(|k| *k == ResourceKind::Deployments)
|
||||
.expect("deployments in ORDERED");
|
||||
app.current_tab_mut().kind_idx = kind_idx;
|
||||
|
||||
let mut entity = mk_entity(
|
||||
"ctx-dev",
|
||||
ResourceKind::Deployments,
|
||||
Some("default"),
|
||||
"api",
|
||||
"3/3 ready",
|
||||
);
|
||||
entity.columns = vec!["3".to_string(), "3".to_string()]; // UP-TO-DATE, AVAILABLE
|
||||
app.store.apply(StateDelta::Upsert(entity));
|
||||
|
||||
let snap = render_snapshot(&mut app, 160, 20);
|
||||
// kind-specific headers replace the old generic "Summary"
|
||||
assert!(snap.contains("UP-TO-DATE"), "header: {snap}");
|
||||
assert!(snap.contains("AVAILABLE"), "header: {snap}");
|
||||
assert!(!snap.contains("Summary"), "no generic summary col: {snap}");
|
||||
assert!(snap.contains("api"), "row name: {snap}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn events_pane_shows_correlated_events_for_a_pod() {
|
||||
let mut app = test_app();
|
||||
|
||||
+21
-19
@@ -694,13 +694,14 @@ impl App {
|
||||
num(mem.lim_pct, mem.lim_sev),
|
||||
]
|
||||
} else {
|
||||
vec![
|
||||
let mut cells = vec![
|
||||
Cell::from(row.namespace),
|
||||
Cell::from(row.name),
|
||||
Cell::from(status),
|
||||
Cell::from(row.age),
|
||||
Cell::from(row.summary),
|
||||
]
|
||||
];
|
||||
cells.extend(row.columns.into_iter().map(Cell::from));
|
||||
cells
|
||||
};
|
||||
Some(Row::new(cells).style(severity_style(&theme, sev)))
|
||||
})
|
||||
@@ -749,22 +750,23 @@ impl App {
|
||||
],
|
||||
)
|
||||
} else {
|
||||
(
|
||||
vec![
|
||||
mark("Namespace", SortColumn::Namespace),
|
||||
mark("Name", SortColumn::Name),
|
||||
mark("Status", SortColumn::Status),
|
||||
mark("Age", SortColumn::Age),
|
||||
Cell::from("Summary"),
|
||||
],
|
||||
vec![
|
||||
Constraint::Length(20),
|
||||
Constraint::Min(24),
|
||||
Constraint::Length(18),
|
||||
Constraint::Length(8),
|
||||
Constraint::Min(10),
|
||||
],
|
||||
)
|
||||
let mut header = vec![
|
||||
mark("Namespace", SortColumn::Namespace),
|
||||
mark("Name", SortColumn::Name),
|
||||
mark("Status", SortColumn::Status),
|
||||
mark("Age", SortColumn::Age),
|
||||
];
|
||||
let mut widths = vec![
|
||||
Constraint::Length(20),
|
||||
Constraint::Min(24),
|
||||
Constraint::Length(18),
|
||||
Constraint::Length(8),
|
||||
];
|
||||
for col in active.kind().extra_columns() {
|
||||
header.push(Cell::from(col.header));
|
||||
widths.push(Constraint::Length(col.width));
|
||||
}
|
||||
(header, widths)
|
||||
};
|
||||
let title = if pods_view {
|
||||
let legend = if self.pod_metrics.is_empty() {
|
||||
|
||||
@@ -22,7 +22,8 @@ pub struct ViewRow {
|
||||
pub name: String,
|
||||
pub status: String,
|
||||
pub age: String,
|
||||
pub summary: String,
|
||||
/// Kind-specific column values, in [`crate::model::ResourceKind::extra_columns`] order.
|
||||
pub columns: Vec<String>,
|
||||
}
|
||||
|
||||
/// Ordered, filtered view of a resource list. Holds only row *identities* (keys); display rows are
|
||||
@@ -91,7 +92,7 @@ impl ViewProjector for SimpleViewProjector {
|
||||
/// - empty → match everything
|
||||
/// - `!<rest>` → invert the result of `<rest>`
|
||||
/// - `k=v`, `k==v`, `k!=v` → label selector (comma-separated requirements, all must hold)
|
||||
/// - anything else → case-insensitive substring over name/namespace/status/summary
|
||||
/// - anything else → case-insensitive substring over name/namespace/status/columns
|
||||
#[derive(Debug, Clone)]
|
||||
enum Filter {
|
||||
All,
|
||||
@@ -201,7 +202,7 @@ fn substring_match(entity: &crate::model::ResourceEntity, needle_lower: &str) ->
|
||||
.as_deref()
|
||||
.is_some_and(|ns| contains(ns))
|
||||
|| contains(&entity.status)
|
||||
|| contains(&entity.summary)
|
||||
|| entity.columns.iter().any(|c| contains(c))
|
||||
}
|
||||
|
||||
/// Build the display row for a single key (visible-window materialization). Returns None if the
|
||||
@@ -218,7 +219,7 @@ pub fn materialize_row(store: &StateStore, key: &ResourceKey) -> Option<ViewRow>
|
||||
name: entity.key.name.clone(),
|
||||
status: entity.status.clone(),
|
||||
age: human_age(entity.age),
|
||||
summary: entity.summary.clone(),
|
||||
columns: entity.columns.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -257,7 +258,7 @@ mod tests {
|
||||
status: status.to_string(),
|
||||
age: Some(Utc::now() - Duration::minutes(5)),
|
||||
labels: vec![],
|
||||
summary: format!("{name}-summary"),
|
||||
columns: vec![format!("{name}-summary")],
|
||||
extracted: Default::default(),
|
||||
}));
|
||||
}
|
||||
@@ -295,7 +296,7 @@ mod tests {
|
||||
.iter()
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect(),
|
||||
summary: String::new(),
|
||||
columns: vec![],
|
||||
extracted: Default::default(),
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user