fix(kubernetes): address PR #76 review findings
Some checks failed
Test / frontend-tests (pull_request) Successful in 1m35s
Test / frontend-typecheck (pull_request) Successful in 1m43s
PR Review Automation / review (pull_request) Successful in 4m12s
Test / rust-fmt-check (pull_request) Failing after 11m14s
Test / rust-clippy (pull_request) Successful in 12m46s
Test / rust-tests (pull_request) Successful in 13m56s

- 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
This commit is contained in:
Shaun Arman 2026-06-07 11:20:57 -05:00
parent 664aeaafad
commit 8753a05a04
3 changed files with 16 additions and 13 deletions

View File

@ -326,6 +326,10 @@ pub async fn initiate_oauth(
let integration_webviews = app_state.integration_webviews.clone(); let integration_webviews = app_state.integration_webviews.clone();
let mcp_connections = app_state.mcp_connections.clone(); let mcp_connections = app_state.mcp_connections.clone();
let pending_approvals = app_state.pending_approvals.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 { tokio::spawn(async move {
let app_state_for_callback = AppState { let app_state_for_callback = AppState {
@ -335,12 +339,10 @@ pub async fn initiate_oauth(
integration_webviews, integration_webviews,
mcp_connections, mcp_connections,
pending_approvals, pending_approvals,
clusters: Arc::new(tokio::sync::Mutex::new(std::collections::HashMap::new())), clusters,
port_forwards: Arc::new(tokio::sync::Mutex::new(std::collections::HashMap::new())), port_forwards,
refresh_registry: Arc::new(tokio::sync::Mutex::new( refresh_registry,
crate::kube::RefreshRegistry::new(), watchers,
)),
watchers: Arc::new(Mutex::new(std::collections::HashMap::new())),
}; };
while let Some(callback) = callback_rx.recv().await { while let Some(callback) = callback_rx.recv().await {
tracing::info!("Received OAuth callback for state: {}", callback.state); tracing::info!("Received OAuth callback for state: {}", callback.state);

View File

@ -4064,7 +4064,6 @@ pub async fn subscribe_to_k8s_events(
state: State<'_, AppState>, state: State<'_, AppState>,
) -> Result<String, String> { ) -> Result<String, String> {
let _app_state = state.inner(); let _app_state = state.inner();
let _app_state = state.inner();
let rx = crate::kube::start_resource_watcher(_app_state, cluster_id, namespace, resource_type) let rx = crate::kube::start_resource_watcher(_app_state, cluster_id, namespace, resource_type)
.await .await
@ -4091,7 +4090,6 @@ pub async fn subscribe_to_all_k8s_events(
state: State<'_, AppState>, state: State<'_, AppState>,
) -> Result<String, String> { ) -> Result<String, String> {
let _app_state = state.inner(); let _app_state = state.inner();
let _app_state = state.inner();
let rx = crate::kube::start_all_resources_watcher(_app_state, cluster_id) let rx = crate::kube::start_all_resources_watcher(_app_state, cluster_id)
.await .await

View File

@ -32,11 +32,14 @@ impl Watcher {
self.resource_type, self.cluster_id, self.namespace self.resource_type, self.cluster_id, self.namespace
); );
// Placeholder for watcher implementation // TODO: implement real watch stream via k8s-openapi + tokio-stream
// Requires k8s-openapi with watch feature and tokio-stream tracing::warn!(
loop { resource_type = %self.resource_type,
tokio::time::sleep(tokio::time::Duration::from_secs(60)).await; cluster_id = %self.cluster_id,
} namespace = %self.namespace,
"Watcher is a stub — no events will be emitted until k8s watch stream is implemented"
);
Ok(())
} }
} }