-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create pod logs function, add to test component (#17)
- Loading branch information
1 parent
5a5136e
commit 2cb9eaf
Showing
4 changed files
with
47 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
use k8s_openapi::api::core::v1::Pod; | ||
|
||
use kube::api::ObjectList; | ||
use kube::{api::LogParams, core::ObjectList, Api, Client}; | ||
|
||
use super::internal::get_resource_list; | ||
|
||
#[tauri::command] | ||
pub async fn get_pods(namespace: Option<String>) -> ObjectList<Pod> { | ||
return get_resource_list(namespace).await; | ||
} | ||
|
||
#[tauri::command] | ||
pub async fn get_pod_logs(pod_name: String, container_name: Option<String>) -> String { | ||
let client = Client::try_default().await.unwrap(); | ||
|
||
let pods: Api<Pod> = Api::default_namespaced(client); | ||
|
||
let mut lp = LogParams::default(); | ||
|
||
lp.container = container_name; | ||
|
||
let log_string = pods.logs(&pod_name, &lp).await.unwrap(); | ||
|
||
// print log_string | ||
println!("{}", log_string); | ||
|
||
return log_string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { invoke } from "@tauri-apps/api"; | ||
|
||
export function TestPlayground() { | ||
const result = useQuery(["logs"], () => { | ||
return invoke<string>("get_pod_logs", { | ||
podName: "hello-minikube-7ddcbc9b8b-bs8k4", | ||
containerName: "echo-server", | ||
}); | ||
}); | ||
|
||
return ( | ||
<div> | ||
<h2>For testing out changes</h2> | ||
|
||
<pre>{result.data}</pre> | ||
</div> | ||
); | ||
} |