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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
use super::*;
impl App {
pub(super) fn key_containers(&mut self, key: KeyEvent) {
let len = self.container_list.len();
match key.code {
KeyCode::Esc | KeyCode::Char('q') => self.mode = Mode::Table,
KeyCode::Char('j') | KeyCode::Down => list_step(&mut self.container_state, len, true),
KeyCode::Char('k') | KeyCode::Up => list_step(&mut self.container_state, len, false),
KeyCode::Enter | KeyCode::Char('l') => {
if let Some(i) = self.container_state.selected()
&& let Some(c) = self.container_list.get(i).cloned()
&& let Some((ns, name)) = self.container_pod.clone()
{
self.launch_logs(
LogSource::Single {
ns,
pod: name.clone(),
container: Some(c.clone()),
previous: false,
},
format!("{name}:{c} — logs"),
);
}
}
KeyCode::Char('p') => {
if let Some(i) = self.container_state.selected()
&& let Some(c) = self.container_list.get(i).cloned()
&& let Some((ns, name)) = self.container_pod.clone()
{
self.launch_logs(
LogSource::Single {
ns,
pod: name.clone(),
container: Some(c.clone()),
previous: true,
},
format!("{name}:{c} — previous logs"),
);
}
}
KeyCode::Char('s') => {
if let Some(i) = self.container_state.selected()
&& let Some(c) = self.container_list.get(i).cloned()
&& let Some((ns, name)) = self.container_pod.clone()
{
self.exec_into(ns, name, Some(c));
}
}
KeyCode::Char('L') => {
if let Some(i) = self.container_state.selected()
&& let Some(c) = self.container_list.get(i).cloned()
&& let Some((ns, name)) = self.container_pod.clone()
{
self.launch_provider_container_logs(ns, name, c);
}
}
// Transfer files to/from this container (`kubectl cp -c`).
KeyCode::Char('t') => {
if let Some(i) = self.container_state.selected()
&& let Some(c) = self.container_list.get(i).cloned()
&& let Some((ns, name)) = self.container_pod.clone()
{
self.open_transfer_menu(ns, name, Some(c));
}
}
// Debug an ephemeral container targeting this container's namespace
// (`kubectl debug --target`). The picker's pod is the selected row,
// so request_debug reads it back from the table selection.
KeyCode::Char('d') => {
if let Some(i) = self.container_state.selected()
&& let Some(c) = self.container_list.get(i).cloned()
{
self.mode = Mode::Table;
self.request_debug(Some(c));
}
}
_ => {}
}
}
/// Execute a confirmed action. Shared by the y/n confirm dialog and the
/// guardrail typed-confirmation prompt.
pub(super) fn run_confirm_action(&mut self, action: ConfirmAction) {
match action {
ConfirmAction::Delete {
targets,
force,
cascade,
..
} => {
self.do_delete(targets, force, cascade);
self.marked.clear();
}
ConfirmAction::Edit { argv } => {
// argv is `<kubectl> edit <kind> <name> [-n <ns>]`; recover the
// name (and namespace) that follow `edit` for the journal entry.
let label = argv
.iter()
.position(|a| a == "edit")
.and_then(|i| argv.get(i + 2))
.map(|name| match argv.iter().position(|a| a == "-n") {
Some(j) => match argv.get(j + 1) {
Some(ns) => format!("{name} in {ns}"),
None => name.clone(),
},
None => name.clone(),
})
.unwrap_or_default();
self.note_action("edit", label);
self.pending = Some(Suspend::Shell(argv));
}
ConfirmAction::Exec { ns, name } => {
self.exec_into(ns, name, None);
}
ConfirmAction::Transfer {
ns,
pod,
container,
src,
dest,
} => {
self.start_transfer(ns, pod, container, true, src, dest);
}
ConfirmAction::Drain { targets } => {
self.do_drain_nodes(targets);
self.marked.clear();
}
ConfirmAction::Restart { kind, name, ns } => {
self.do_restart(kind, name, ns);
}
ConfirmAction::HelmRollback { ns, name, revision } => {
self.do_helm_rollback(ns, name, revision);
}
ConfirmAction::HelmUninstall { targets } => {
self.do_helm_uninstall(targets);
self.marked.clear();
}
ConfirmAction::NodeDebug {
node,
image,
namespace,
profile,
} => {
self.do_node_debug(node, image, namespace, profile);
}
ConfirmAction::CleanupDebuggers => {
self.do_cleanup_debuggers();
}
ConfirmAction::Plugin {
jobs,
name,
mode,
timeout,
} => {
self.launch_plugin(jobs, name, mode, timeout);
}
}
}
pub(super) fn key_confirm(&mut self, key: KeyEvent) {
match key.code {
KeyCode::Char('y') | KeyCode::Char('Y') | KeyCode::Enter => {
if let Some(action) = self.confirm_action.take() {
self.run_confirm_action(action);
}
self.mode = Mode::Table;
}
KeyCode::Char('f') | KeyCode::Char('F') => {
let update = match self.confirm_action.as_mut() {
Some(ConfirmAction::Delete {
targets,
force,
cascade,
managed,
}) => {
*force = !*force;
Some((targets.clone(), *force, *cascade, managed.clone()))
}
_ => None,
};
if let Some((targets, force, cascade, managed)) = update {
self.confirm_label = delete_confirm_label(
&self.kind_plural,
&targets,
force,
cascade,
managed.as_deref(),
);
}
}
KeyCode::Char('c') | KeyCode::Char('C') => {
let update = match self.confirm_action.as_mut() {
Some(ConfirmAction::Delete {
targets,
force,
cascade,
managed,
}) => {
*cascade = cascade.next();
Some((targets.clone(), *force, *cascade, managed.clone()))
}
_ => None,
};
if let Some((targets, force, cascade, managed)) = update {
self.confirm_label = delete_confirm_label(
&self.kind_plural,
&targets,
force,
cascade,
managed.as_deref(),
);
}
}
_ => {
self.confirm_action = None;
self.mode = Mode::Table;
}
}
}
pub(super) fn key_prompt(&mut self, key: KeyEvent) {
if edit_chord(&key, &mut self.prompt_input) {
return;
}
match key.code {
KeyCode::Esc => {
// The lookback prompt is the one prompt opened from the logs
// view; every other prompt starts at (and returns to) the table.
self.mode = if self.prompt_over_logs() {
Mode::Logs
} else {
Mode::Table
};
self.prompt_kind = None;
}
KeyCode::Enter => {
let input = self.prompt_input.trim().to_string();
self.mode = if self.prompt_over_logs() {
Mode::Logs
} else {
Mode::Table
};
match self.prompt_kind.take() {
Some(PromptKind::Scale { ns, name }) => match input.parse::<i32>() {
Ok(n) if n >= 0 => self.do_scale(ns, name, n),
_ => self.flash_warn("invalid replica count"),
},
Some(PromptKind::PortForward { ns, name }) => {
if input.is_empty() {
self.flash_warn("no ports given");
} else {
let target = if self.kind_plural == "services" {
format!("svc/{name}")
} else {
name
};
self.start_port_forward(ns, target, input);
}
}
Some(PromptKind::SetImage {
ns,
name,
plural,
container,
}) => {
if input.is_empty() {
self.flash_warn("no image given");
} else {
self.do_set_image(ns, name, plural, container, input);
}
}
Some(PromptKind::Debug { ns, pod, target }) => {
if input.is_empty() {
self.flash_warn("no debug image given");
} else {
self.do_debug(ns, pod, target, input);
}
}
// The transfer prompts chain: source path first, then the
// destination (prefilled with the source's file name on
// download, since it usually lands in the CWD as-is).
Some(PromptKind::Transfer {
ns,
pod,
container,
upload,
src: None,
}) => {
if input.is_empty() {
self.flash_warn("no path given — transfer cancelled");
} else {
self.prompt_label = if upload {
format!("Upload {input} to {pod} — remote path:")
} else {
format!("Download {pod}:{input} — local path:")
};
self.prompt_input = if upload {
String::new()
} else {
input.rsplit('/').next().unwrap_or_default().to_string()
};
self.prompt_kind = Some(PromptKind::Transfer {
ns,
pod,
container,
upload,
src: Some(input),
});
self.mode = Mode::Prompt;
}
}
Some(PromptKind::Transfer {
ns,
pod,
container,
upload,
src: Some(src),
}) => {
if input.is_empty() {
self.flash_warn("no path given — transfer cancelled");
} else {
self.do_transfer(ns, pod, container, upload, src, input);
}
}
// Empty input = cancel, keep the current period.
Some(PromptKind::ProviderLookback) if !input.is_empty() => {
self.apply_provider_lookback(&input)
}
Some(PromptKind::ProviderLookback) => {}
Some(PromptKind::GuardConfirm { expected, action }) => {
if input == expected {
self.run_confirm_action(*action);
} else {
self.flash_warn("guardrail: input did not match — cancelled");
}
}
None => {}
}
}
KeyCode::Backspace => {
self.prompt_input.pop();
}
KeyCode::Char(c) => self.prompt_input.push(c),
_ => {}
}
}
}