Skip to content

Commit

Permalink
feat: create pod logs function, add to test component (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhu2000 authored Jan 15, 2023
1 parent 5a5136e commit 2cb9eaf
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@

mod resources;

use crate::resources::{
cron_jobs::get_cron_jobs, deployments::get_deployments, namespaces::get_namespaces,
pods::get_pods,
};
use crate::resources::{cron_jobs, deployments, namespaces, pods};

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
get_cron_jobs,
get_deployments,
get_pods,
get_namespaces,
cron_jobs::get_cron_jobs,
deployments::get_deployments,
pods::get_pod_logs,
pods::get_pods,
namespaces::get_namespaces,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
20 changes: 19 additions & 1 deletion src-tauri/src/resources/pods.rs
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;
}
3 changes: 3 additions & 0 deletions src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CronJobs } from "./cron-jobs/cron-jobs";
import { Deployments } from "./deployments/deployments";
import { Layout } from "./layout";
import { Pods } from "./pods/pods";
import { TestPlayground } from "./test-playground/test-playground";

const rootRoute = createRouteConfig({
component: () => (
Expand All @@ -26,13 +27,15 @@ const routeConfig = rootRoute.addChildren([
rootRoute.createRoute({ path: "/pods", component: Pods }),
rootRoute.createRoute({ path: "/cron-jobs", component: CronJobs }),
rootRoute.createRoute({ path: "/deployments", component: Deployments }),
rootRoute.createRoute({ path: "/test-playground", component: TestPlayground }),
]);
export const router = createReactRouter({ routeConfig });

export const navigationLinks = [
{ name: "Cron Jobs", href: "/cron-jobs" },
{ name: "Deployments", href: "/deployments" },
{ name: "Pods", href: "/pods" },
{ name: "Testing", href: "/test-playground" },
] as const;

declare module "@tanstack/react-router" {
Expand Down
19 changes: 19 additions & 0 deletions src/test-playground/test-playground.tsx
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>
);
}

0 comments on commit 2cb9eaf

Please sign in to comment.