From 8753a05a0423be6f74da2a85927096955d4e6488 Mon Sep 17 00:00:00 2001 From: Shaun Arman Date: Sun, 7 Jun 2026 11:20:57 -0500 Subject: [PATCH] fix(kubernetes): address PR #76 review findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove duplicate state.inner() calls in subscribe_to_k8s_events and subscribe_to_all_k8s_events (copy-paste error) - Share all AppState Arc fields in OAuth callback task — clusters, port_forwards, refresh_registry, and watchers were previously constructed as fresh isolated instances instead of being cloned from the live AppState - Replace infinite sleep loop in Watcher::start with an immediate warn-and-return, preventing Tokio thread leaks from stub watchers --- src-tauri/src/commands/integrations.rs | 14 ++++++++------ src-tauri/src/commands/kube.rs | 2 -- src-tauri/src/kube/watcher.rs | 13 ++++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src-tauri/src/commands/integrations.rs b/src-tauri/src/commands/integrations.rs index 95438976..9c4ecd06 100644 --- a/src-tauri/src/commands/integrations.rs +++ b/src-tauri/src/commands/integrations.rs @@ -326,6 +326,10 @@ pub async fn initiate_oauth( let integration_webviews = app_state.integration_webviews.clone(); let mcp_connections = app_state.mcp_connections.clone(); let pending_approvals = app_state.pending_approvals.clone(); + let clusters = app_state.clusters.clone(); + let port_forwards = app_state.port_forwards.clone(); + let refresh_registry = app_state.refresh_registry.clone(); + let watchers = app_state.watchers.clone(); tokio::spawn(async move { let app_state_for_callback = AppState { @@ -335,12 +339,10 @@ pub async fn initiate_oauth( integration_webviews, mcp_connections, pending_approvals, - clusters: Arc::new(tokio::sync::Mutex::new(std::collections::HashMap::new())), - port_forwards: Arc::new(tokio::sync::Mutex::new(std::collections::HashMap::new())), - refresh_registry: Arc::new(tokio::sync::Mutex::new( - crate::kube::RefreshRegistry::new(), - )), - watchers: Arc::new(Mutex::new(std::collections::HashMap::new())), + clusters, + port_forwards, + refresh_registry, + watchers, }; while let Some(callback) = callback_rx.recv().await { tracing::info!("Received OAuth callback for state: {}", callback.state); diff --git a/src-tauri/src/commands/kube.rs b/src-tauri/src/commands/kube.rs index 0737be06..241c49a1 100644 --- a/src-tauri/src/commands/kube.rs +++ b/src-tauri/src/commands/kube.rs @@ -4064,7 +4064,6 @@ pub async fn subscribe_to_k8s_events( state: State<'_, AppState>, ) -> Result { let _app_state = state.inner(); - let _app_state = state.inner(); let rx = crate::kube::start_resource_watcher(_app_state, cluster_id, namespace, resource_type) .await @@ -4091,7 +4090,6 @@ pub async fn subscribe_to_all_k8s_events( state: State<'_, AppState>, ) -> Result { let _app_state = state.inner(); - let _app_state = state.inner(); let rx = crate::kube::start_all_resources_watcher(_app_state, cluster_id) .await diff --git a/src-tauri/src/kube/watcher.rs b/src-tauri/src/kube/watcher.rs index 515dd7c2..0da0433a 100644 --- a/src-tauri/src/kube/watcher.rs +++ b/src-tauri/src/kube/watcher.rs @@ -32,11 +32,14 @@ impl Watcher { self.resource_type, self.cluster_id, self.namespace ); - // Placeholder for watcher implementation - // Requires k8s-openapi with watch feature and tokio-stream - loop { - tokio::time::sleep(tokio::time::Duration::from_secs(60)).await; - } + // TODO: implement real watch stream via k8s-openapi + tokio-stream + tracing::warn!( + resource_type = %self.resource_type, + cluster_id = %self.cluster_id, + namespace = %self.namespace, + "Watcher is a stub — no events will be emitted until k8s watch stream is implemented" + ); + Ok(()) } }