feature/freelens-parity-complete #87

Merged
sarman merged 16 commits from feature/freelens-parity-complete into master 2026-06-10 01:06:11 +00:00
Showing only changes of commit e15374bdd3 - Show all commits

View File

@ -27,6 +27,15 @@ impl KubeconfigGuard {
Self { path: Some(path) }
}
/// Return the path as a string without transferring ownership.
fn path_str(&self) -> String {
self.path
.as_ref()
.expect("KubeconfigGuard path already taken")
.to_string_lossy()
.into_owned()
}
/// Transfer ownership: caller is now responsible for the file.
/// Returns the path string for use with the PTY session.
fn disarm(mut self) -> String {
@ -344,8 +353,9 @@ pub async fn start_pty_exec_session(
let kubectl_path =
crate::shell::kubectl::locate_kubectl().map_err(|e| format!("kubectl not found: {e}"))?;
// Transfer ownership: PTY session now owns the temp file's lifetime.
let kubeconfig_path = kubeconfig_guard.map(|g| g.disarm());
// Obtain path string without disarming; the guard remains active so the
// file is cleaned up if session start fails below.
let kubeconfig_path = kubeconfig_guard.as_ref().map(|g| g.path_str());
// Start session
let params = crate::shell::session::SessionParams {
@ -363,6 +373,13 @@ pub async fn start_pty_exec_session(
.await
.map_err(|e| format!("Failed to start exec session: {e}"))?;
// Session started — disarm the guard so the file outlives this function.
// The PTY process needs the kubeconfig for the full session duration;
// temp dir is OS-cleaned on reboot.
if let Some(g) = kubeconfig_guard {
g.disarm();
}
Ok(session_id)
}
@ -406,8 +423,9 @@ pub async fn start_pty_attach_session(
let kubectl_path =
crate::shell::kubectl::locate_kubectl().map_err(|e| format!("kubectl not found: {e}"))?;
// Transfer ownership: PTY session now owns the temp file's lifetime.
let kubeconfig_path = kubeconfig_guard.map(|g| g.disarm());
// Obtain path string without disarming; the guard remains active so the
// file is cleaned up if session start fails below.
let kubeconfig_path = kubeconfig_guard.as_ref().map(|g| g.path_str());
// Start session
let params = crate::shell::session::SessionParams {
@ -425,6 +443,11 @@ pub async fn start_pty_attach_session(
.await
.map_err(|e| format!("Failed to start attach session: {e}"))?;
// Session started — disarm the guard so the file outlives this function.
if let Some(g) = kubeconfig_guard {
g.disarm();
}
Ok(session_id)
}