Compare commits

..

No commits in common. "d65593af1e648e97970da2d5a3940c181d7c21fb" and "98e2abb463ec29440caabbae4b2e624da243683e" have entirely different histories.

4 changed files with 41 additions and 179 deletions

View File

@ -199,61 +199,6 @@ pub async fn connect_cluster_from_kubeconfig(
Ok(())
}
/// Diagnostic: test a kubeconfig's ability to reach the cluster.
///
/// Returns a human-readable summary including the context name, kubectl binary
/// path, exit code, and the full stdout/stderr from `kubectl cluster-info`.
/// This command is safe to call at any time — it writes a temp file, tests the
/// connection, then deletes the file regardless of the outcome.
#[tauri::command]
pub async fn test_kubectl_connection(
cluster_id: String,
state: State<'_, AppState>,
) -> Result<String, String> {
let (kubeconfig_content, context) = {
let clusters = state.clusters.lock().await;
let cluster = clusters.get(&cluster_id).ok_or_else(|| {
format!(
"Cluster {} not found in session — try re-selecting the cluster",
cluster_id
)
})?;
(cluster.kubeconfig_content.clone(), cluster.context.clone())
};
let temp_dir = std::env::temp_dir();
let temp_path = temp_dir.join(format!("kubeconfig-{}-diag.yaml", cluster_id));
let _cleanup = TempFileCleanup(temp_path.clone());
std::fs::write(&temp_path, kubeconfig_content.as_ref())
.map_err(|e| format!("Failed to write kubeconfig temp file: {e}"))?;
let kubectl_path = locate_kubectl()?;
let output = Command::new(&kubectl_path)
.arg("cluster-info")
.arg("--context")
.arg(context.as_str())
.arg("--kubeconfig")
.arg(&temp_path)
.output()
.await
.map_err(|e| format!("Failed to execute kubectl: {e}"))?;
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
let exit_code = output.status.code().unwrap_or(-1);
Ok(format!(
"Context: {context}\nKubectl: {kubectl}\nExit: {exit}\n\n--- stdout ---\n{stdout}\n--- stderr ---\n{stderr}",
context = context,
kubectl = kubectl_path.display(),
exit = exit_code,
stdout = if stdout.is_empty() { "(none)" } else { &stdout },
stderr = if stderr.is_empty() { "(none)" } else { &stderr },
))
}
#[tauri::command]
pub async fn remove_cluster(id: String, state: State<'_, AppState>) -> Result<(), String> {
// Check existence in memory BEFORE touching the DB
@ -335,8 +280,7 @@ pub async fn test_cluster_connection(
let output = Command::new(kubectl_path)
.arg("cluster-info")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -390,8 +334,7 @@ pub async fn discover_pods(
.arg(&namespace)
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -530,8 +473,7 @@ pub async fn start_port_forward(
.args(&args)
.arg("--context")
.arg(cluster.context.as_str())
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.spawn()
.map_err(|e| format!("Failed to spawn kubectl: {e}"))?;
@ -839,8 +781,7 @@ pub async fn list_namespaces(
.arg("namespaces")
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -927,8 +868,7 @@ pub async fn list_pods(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -1051,8 +991,7 @@ pub async fn list_services(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -1210,8 +1149,7 @@ pub async fn list_deployments(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -1345,8 +1283,7 @@ pub async fn list_statefulsets(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -1464,8 +1401,7 @@ pub async fn list_daemonsets(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -1630,8 +1566,7 @@ pub async fn get_pod_logs(
.arg(namespace)
.arg("-c")
.arg(container_name)
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -1681,8 +1616,7 @@ pub async fn scale_deployment(
.arg(replicas.to_string())
.arg("-n")
.arg(namespace)
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -1728,8 +1662,7 @@ pub async fn restart_deployment(
.arg(deployment_name)
.arg("-n")
.arg(namespace)
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -1775,8 +1708,7 @@ pub async fn delete_resource(
.arg(resource_name)
.arg("-n")
.arg(namespace)
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -1845,8 +1777,7 @@ pub async fn exec_pod(
cmd.arg("--").arg(shell_cmd).arg("-c").arg(&command);
cmd.arg("--kubeconfig")
.arg(&temp_path)
cmd.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str());
@ -2107,8 +2038,7 @@ pub async fn list_replicasets(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -2226,8 +2156,7 @@ pub async fn list_jobs(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -2383,8 +2312,7 @@ pub async fn list_cronjobs(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -2511,8 +2439,7 @@ pub async fn list_configmaps(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -2610,8 +2537,7 @@ pub async fn list_secrets(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -2710,8 +2636,7 @@ pub async fn list_nodes(
.arg("nodes")
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -2904,8 +2829,7 @@ pub async fn list_events(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -3034,8 +2958,7 @@ pub async fn list_ingresses(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -3161,8 +3084,7 @@ pub async fn list_persistentvolumeclaims(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -3287,8 +3209,7 @@ pub async fn list_persistentvolumes(
.arg("persistentvolumes")
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -3419,8 +3340,7 @@ pub async fn list_serviceaccounts(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -3518,8 +3438,7 @@ pub async fn list_roles(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -3604,8 +3523,7 @@ pub async fn list_clusterroles(
.arg("clusterroles")
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -3685,8 +3603,7 @@ pub async fn list_rolebindings(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -3782,8 +3699,7 @@ pub async fn list_clusterrolebindings(
.arg("clusterrolebindings")
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -3874,8 +3790,7 @@ pub async fn list_horizontalpodautoscalers(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -3988,8 +3903,7 @@ pub async fn list_storageclasses(
.arg("storageclasses")
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -4099,8 +4013,7 @@ pub async fn list_networkpolicies(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -4211,8 +4124,7 @@ pub async fn list_resourcequotas(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -4333,8 +4245,7 @@ pub async fn list_limitranges(
let output = kubectl_cmd
.arg("-o")
.arg("json")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -4426,8 +4337,7 @@ pub async fn cordon_node(
let output = Command::new(kubectl_path)
.arg("cordon")
.arg(node_name)
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -4468,8 +4378,7 @@ pub async fn uncordon_node(
let output = Command::new(kubectl_path)
.arg("uncordon")
.arg(node_name)
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -4513,8 +4422,7 @@ pub async fn drain_node(
.arg("--ignore-daemonsets")
.arg("--delete-emptydir-data")
.arg("--force")
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -4560,8 +4468,7 @@ pub async fn rollback_deployment(
.arg(deployment_name)
.arg("-n")
.arg(namespace)
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.output()
@ -4607,8 +4514,7 @@ pub async fn create_resource(
.arg("-")
.arg("-n")
.arg(namespace)
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.stdin(Stdio::piped())
@ -4671,8 +4577,7 @@ pub async fn edit_resource(
.arg("-")
.arg("-n")
.arg(namespace)
.arg("--kubeconfig")
.arg(&temp_path)
.env("KUBECONFIG", temp_path.to_string_lossy().to_string())
.arg("--context")
.arg(context.as_str())
.stdin(Stdio::piped())

View File

@ -181,7 +181,6 @@ pub fn run() {
// Kubernetes Management
commands::kube::add_cluster,
commands::kube::connect_cluster_from_kubeconfig,
commands::kube::test_kubectl_connection,
commands::kube::remove_cluster,
commands::kube::list_clusters,
commands::kube::start_port_forward,

View File

@ -917,10 +917,6 @@ export const removeClusterCmd = (id: string) =>
export const connectClusterFromKubeconfigCmd = (id: string) =>
invoke<void>("connect_cluster_from_kubeconfig", { id });
/** Diagnostic: runs kubectl cluster-info and returns a human-readable summary. */
export const testKubectlConnectionCmd = (clusterId: string) =>
invoke<string>("test_kubectl_connection", { clusterId });
export const listClustersCmd = () =>
invoke<ClusterInfo[]>("list_clusters");

View File

@ -1,13 +1,11 @@
import { useState, useEffect } from 'react';
import { Upload, Check, Trash2, FileCode, FlaskConical } from 'lucide-react';
import { Upload, Check, Trash2, FileCode } from 'lucide-react';
import { Button, Card, CardHeader, CardTitle, CardContent, Badge } from '@/components/ui';
import {
uploadKubeconfigCmd,
listKubeconfigsCmd,
activateKubeconfigCmd,
deleteKubeconfigCmd,
connectClusterFromKubeconfigCmd,
testKubectlConnectionCmd,
type KubeconfigInfo,
} from '@/lib/tauriCommands';
@ -17,8 +15,6 @@ export default function KubeconfigManager() {
const [uploadContent, setUploadContent] = useState('');
const [uploadName, setUploadName] = useState('');
const [error, setError] = useState('');
const [testResult, setTestResult] = useState<{ id: string; output: string } | null>(null);
const [testingId, setTestingId] = useState<string | null>(null);
const loadConfigs = async () => {
try {
@ -94,22 +90,6 @@ export default function KubeconfigManager() {
}
};
const handleTestConnection = async (id: string) => {
setTestingId(id);
setTestResult(null);
setError('');
try {
// Ensure the cluster is loaded into the session first
await connectClusterFromKubeconfigCmd(id).catch(() => {});
const output = await testKubectlConnectionCmd(id);
setTestResult({ id, output });
} catch (err) {
setTestResult({ id, output: String(err) });
} finally {
setTestingId(null);
}
};
return (
<div className="p-6 space-y-6">
<div>
@ -220,16 +200,6 @@ export default function KubeconfigManager() {
</div>
<div className="flex gap-2">
<Button
variant="outline"
size="sm"
onClick={() => handleTestConnection(config.id)}
disabled={testingId === config.id}
title="Test kubectl connection"
>
<FlaskConical className="h-4 w-4 mr-1" />
{testingId === config.id ? 'Testing…' : 'Test'}
</Button>
{!config.is_active && (
<Button
variant="outline"
@ -251,13 +221,6 @@ export default function KubeconfigManager() {
</Button>
</div>
</div>
{/* Test result for this config */}
{testResult?.id === config.id && (
<div className="mt-3 rounded-md bg-slate-950 p-3 font-mono text-xs text-slate-300 overflow-x-auto max-h-64 overflow-y-auto">
<pre>{testResult.output}</pre>
</div>
)}
</div>
))}
</div>
@ -280,7 +243,6 @@ export default function KubeconfigManager() {
<li>Multiple clusters can be configured and switched between</li>
<li>The active configuration is used for kubectl commands</li>
<li>All kubeconfig files are encrypted using AES-256-GCM</li>
<li>Use the <strong>Test</strong> button to diagnose connection issues</li>
</ul>
</CardContent>
</Card>