1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! In-memory store of the currently-watched resource set.
use std::collections::HashMap;
use kube::core::DynamicObject;
/// Messages flowing from watch tasks to the UI loop. Tagged with a
/// `generation` so messages from a superseded watch can be discarded.
pub enum Msg {
Reset {
generation: u64,
},
Applied {
generation: u64,
key: String,
obj: Box<DynamicObject>,
},
Deleted {
generation: u64,
key: String,
},
Synced {
generation: u64,
},
LogLines {
generation: u64,
lines: Vec<String>,
},
/// Point-in-time usage snapshot from the metrics API, keyed by "ns/name"
/// (pods) or "name" (nodes) -> (cpu millicores, memory bytes).
Metrics {
generation: u64,
data: HashMap<String, (i64, i64)>,
/// Per-container usage keyed by `namespace/pod/container`.
containers: HashMap<String, (i64, i64)>,
},
/// CRD `additionalPrinterColumns` fallback for a custom-resource plural,
/// fetched off-thread (`None` = CRD had nothing usable for the version).
PrinterColumns {
generation: u64,
plural: String,
view: Box<Option<crate::views::View>>,
},
PulseData {
generation: u64,
data: Pulse,
},
XrayData {
generation: u64,
items: Vec<XrayItem>,
},
/// Findings for the explain-unhealthy view, gathered off-thread.
Explain {
generation: u64,
title: String,
findings: Vec<crate::explain::Finding>,
},
/// Result of an off-thread `kubectl describe` (or its YAML fallback).
Detail {
generation: u64,
title: String,
lines: Vec<String>,
/// Set when describe failed and we fell back to YAML.
warn: Option<String>,
},
/// Live Event rows for the selected object.
Events {
generation: u64,
title: String,
lines: Vec<String>,
},
/// Result of an off-thread log save.
LogsSaved {
generation: u64,
result: Result<std::path::PathBuf, String>,
},
/// Result of an off-thread clipboard copy.
ClipboardCopied {
generation: u64,
copied: bool,
success: String,
failure: String,
},
/// Namespace list for the switcher, fetched off-thread.
Namespaces {
generation: u64,
list: Vec<String>,
},
/// Kubeconfig context names for the switcher, fetched off-thread.
Contexts {
generation: u64,
list: Vec<String>,
},
/// Result of an off-thread context switch (rebuilds client + discovery).
ContextSwitched {
generation: u64,
name: String,
result: Result<Box<crate::k8s::Cluster>, String>,
},
/// Resource plurals the user may `list`, computed for namespace `ns`
/// (empty = cluster default). Dropped if the active namespace has since
/// changed. "*" = all.
Rbac {
generation: u64,
ns: String,
allowed: std::collections::HashSet<String>,
},
/// A log provider autodiscovered in the cluster (no `[providers.logs]`
/// url configured), cached so later `L` presses skip the service lookup.
/// Tagged with the view generation: a context switch invalidates it.
LogProviderDiscovered {
generation: u64,
provider: Box<crate::providers::LogProvider>,
},
Error {
generation: u64,
error: String,
},
}
/// Cluster-health snapshot for the pulse dashboard.
#[derive(Clone, Default)]
pub struct Pulse {
pub nodes_ready: usize,
pub nodes_total: usize,
pub pods_running: usize,
pub pods_pending: usize,
pub pods_failed: usize,
pub pods_succeeded: usize,
pub pods_total: usize,
pub deploys_ready: usize,
pub deploys_total: usize,
pub sts_ready: usize,
pub sts_total: usize,
pub ds_ready: usize,
pub ds_total: usize,
pub jobs_total: usize,
pub pvc_bound: usize,
pub pvc_total: usize,
}
/// A flattened node in the xray tree (owner → children → containers).
#[derive(Clone)]
pub struct XrayItem {
pub depth: usize,
pub kind: String,
pub name: String,
pub ns: String,
pub status: String,
/// Set when this row is a container leaf (its pod is `name`).
pub container: Option<String>,
}
/// Stable identity for a resource row.
pub fn row_key(obj: &DynamicObject) -> String {
match (&obj.metadata.namespace, &obj.metadata.name) {
(Some(ns), Some(name)) => format!("{ns}/{name}"),
(None, Some(name)) => name.clone(),
_ => obj
.metadata
.uid
.clone()
.unwrap_or_else(|| "<unknown>".into()),
}
}
#[derive(Default)]
pub struct Store {
items: HashMap<String, DynamicObject>,
pub synced: bool,
}
impl Store {
pub fn clear(&mut self) {
self.items.clear();
self.synced = false;
}
pub fn apply(&mut self, key: String, obj: DynamicObject) {
self.items.insert(key, obj);
}
pub fn remove(&mut self, key: &str) {
self.items.remove(key);
}
pub fn len(&self) -> usize {
self.items.len()
}
pub fn get(&self, key: &str) -> Option<&DynamicObject> {
self.items.get(key)
}
pub fn iter(&self) -> impl Iterator<Item = (&String, &DynamicObject)> {
self.items.iter()
}
}