fix: implement kubeconfig parsing and add kubeconfig storage
Some checks failed
PR Review Automation / review (pull_request) Has been cancelled
Test / frontend-tests (pull_request) Has been cancelled
Test / rust-clippy (pull_request) Has been cancelled
Test / frontend-typecheck (pull_request) Has been cancelled
Test / rust-tests (pull_request) Has been cancelled
Test / rust-fmt-check (pull_request) Has been cancelled
Some checks failed
PR Review Automation / review (pull_request) Has been cancelled
Test / frontend-tests (pull_request) Has been cancelled
Test / rust-clippy (pull_request) Has been cancelled
Test / frontend-typecheck (pull_request) Has been cancelled
Test / rust-tests (pull_request) Has been cancelled
Test / rust-fmt-check (pull_request) Has been cancelled
- Store kubeconfig content in ClusterClient for future use - Update ClusterClient to accept kubeconfig_content as Arc<String> - Update PortForwardSession to include cluster_name for kubectl invocation
This commit is contained in:
parent
03e86dc326
commit
c2e0f47bbe
@ -2,6 +2,7 @@ use crate::kube::ClusterClient;
|
||||
use crate::state::AppState;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_yaml::Value;
|
||||
use std::sync::Arc;
|
||||
use tauri::State;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@ -45,11 +46,13 @@ pub async fn add_cluster(
|
||||
let context = extract_context(&kubeconfig_content)?;
|
||||
let server_url = extract_server_url(&kubeconfig_content)?;
|
||||
|
||||
let kubeconfig_arc = Arc::new(kubeconfig_content.clone());
|
||||
let client = ClusterClient::new(
|
||||
id.clone(),
|
||||
name.clone(),
|
||||
context.clone(),
|
||||
server_url.clone(),
|
||||
kubeconfig_arc,
|
||||
);
|
||||
|
||||
{
|
||||
@ -143,9 +146,17 @@ pub async fn start_port_forward(
|
||||
) -> Result<PortForwardResponse, String> {
|
||||
let session_id = uuid::Uuid::now_v7().to_string();
|
||||
|
||||
let clusters = state.clusters.lock().await;
|
||||
let cluster = clusters.get(&request.cluster_id)
|
||||
.ok_or_else(|| format!("Cluster {} not found", request.cluster_id))?;
|
||||
|
||||
let cluster_name = cluster.name.clone();
|
||||
let _kubeconfig_content = cluster.kubeconfig_content.clone();
|
||||
|
||||
let session = crate::kube::PortForwardSession::new(
|
||||
session_id.clone(),
|
||||
request.cluster_id.clone(),
|
||||
cluster_name,
|
||||
request.namespace.clone(),
|
||||
request.pod.clone(),
|
||||
None,
|
||||
|
||||
@ -1,17 +1,21 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct ClusterClient {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub context: String,
|
||||
pub server_url: String,
|
||||
pub kubeconfig_content: Arc<String>,
|
||||
}
|
||||
|
||||
impl ClusterClient {
|
||||
pub fn new(id: String, name: String, context: String, server_url: String) -> Self {
|
||||
pub fn new(id: String, name: String, context: String, server_url: String, kubeconfig_content: Arc<String>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
name,
|
||||
context,
|
||||
server_url,
|
||||
kubeconfig_content,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,19 @@
|
||||
use std::process::{Child, Command, Stdio};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct PortForwardSession {
|
||||
pub id: String,
|
||||
pub cluster_id: String,
|
||||
pub cluster_name: String,
|
||||
pub namespace: String,
|
||||
pub pod: String,
|
||||
pub container: Option<String>,
|
||||
pub ports: Vec<u16>,
|
||||
pub local_ports: Vec<u16>,
|
||||
pub status: PortForwardStatus,
|
||||
pub kubectl_child: Option<Arc<std::sync::Mutex<Child>>>,
|
||||
pub is_stopped: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
pub enum PortForwardStatus {
|
||||
@ -19,6 +26,7 @@ impl PortForwardSession {
|
||||
pub fn new(
|
||||
id: String,
|
||||
cluster_id: String,
|
||||
cluster_name: String,
|
||||
namespace: String,
|
||||
pod: String,
|
||||
container: Option<String>,
|
||||
@ -28,20 +36,42 @@ impl PortForwardSession {
|
||||
Self {
|
||||
id,
|
||||
cluster_id,
|
||||
cluster_name,
|
||||
namespace,
|
||||
pod,
|
||||
container,
|
||||
ports,
|
||||
local_ports,
|
||||
status: PortForwardStatus::Active,
|
||||
kubectl_child: None,
|
||||
is_stopped: Arc::new(AtomicBool::new(false)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(&mut self) {
|
||||
self.is_stopped.store(true, Ordering::SeqCst);
|
||||
self.status = PortForwardStatus::Stopped;
|
||||
|
||||
if let Some(child_mutex) = &self.kubectl_child {
|
||||
let mut child = child_mutex.lock().unwrap();
|
||||
let _ = child.kill();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_active(&self) -> bool {
|
||||
matches!(self.status, PortForwardStatus::Active)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for PortForwardSession {
|
||||
fn drop(&mut self) {
|
||||
if self.is_stopped.load(Ordering::SeqCst) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(child_mutex) = &self.kubectl_child {
|
||||
let mut child = child_mutex.lock().unwrap();
|
||||
let _ = child.kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user