-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: all functionality to view logs and auto poll for new logs #18
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
use k8s_openapi::api::batch::v1::CronJob; | ||
use kube::core::ObjectList; | ||
use kube::{api::ListParams, core::ObjectList, Api}; | ||
|
||
use super::internal::get_resource_list; | ||
use super::internal::get_api; | ||
|
||
#[tauri::command] | ||
pub async fn get_cron_jobs(namespace: Option<String>) -> ObjectList<CronJob> { | ||
return get_resource_list(namespace).await; | ||
let api: Api<CronJob> = get_api(namespace).await; | ||
let lp = ListParams::default(); | ||
return api.list(&lp).await.unwrap(); | ||
} |
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,9 +1,11 @@ | ||
use k8s_openapi::api::apps::v1::Deployment; | ||
use kube::core::ObjectList; | ||
use kube::{api::ListParams, core::ObjectList, Api}; | ||
|
||
use super::internal::get_resource_list; | ||
use super::internal::get_api; | ||
|
||
#[tauri::command] | ||
pub async fn get_deployments(namespace: Option<String>) -> ObjectList<Deployment> { | ||
return get_resource_list(namespace).await; | ||
let api: Api<Deployment> = get_api(namespace).await; | ||
let lp = ListParams::default(); | ||
return api.list(&lp).await.unwrap(); | ||
} |
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,28 +1,31 @@ | ||
use k8s_openapi::api::core::v1::Pod; | ||
|
||
use kube::{api::LogParams, core::ObjectList, Api, Client}; | ||
use kube::{ | ||
api::{ListParams, LogParams}, | ||
core::ObjectList, | ||
Api, | ||
}; | ||
|
||
use super::internal::get_resource_list; | ||
use super::internal::get_api; | ||
|
||
#[tauri::command] | ||
pub async fn get_pods(namespace: Option<String>) -> ObjectList<Pod> { | ||
return get_resource_list(namespace).await; | ||
let api: Api<Pod> = get_api(namespace).await; | ||
let lp = ListParams::default(); | ||
return api.list(&lp).await.unwrap(); | ||
} | ||
|
||
#[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); | ||
pub async fn get_pod_logs( | ||
namespace: Option<String>, | ||
pod_name: String, | ||
container_name: Option<String>, | ||
) -> String { | ||
let pods: Api<Pod> = get_api(namespace).await; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* This example requires Tailwind CSS v2.0+ */ | ||
import { Dialog, Transition } from "@headlessui/react"; | ||
import { XMarkIcon } from "@heroicons/react/24/outline"; | ||
import { type V1Pod } from "@kubernetes/client-node"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { invoke } from "@tauri-apps/api"; | ||
import { Fragment, useEffect, useRef } from "react"; | ||
|
||
interface PodLogsProps { | ||
isOpen: boolean; | ||
selectedPod: V1Pod | null; | ||
handleClose: () => void; | ||
} | ||
|
||
export default function PodLogs({ isOpen, selectedPod, handleClose }: PodLogsProps) { | ||
const podName = selectedPod?.metadata?.name; | ||
const namespace = selectedPod?.metadata?.namespace; | ||
const container = selectedPod?.spec?.containers[0].name; | ||
|
||
const result = useQuery( | ||
["pod-logs", podName], | ||
() => { | ||
return invoke<string>("get_pod_logs", { | ||
podName: podName, | ||
namespace, | ||
container, | ||
}); | ||
}, | ||
{ enabled: !!podName, refetchInterval: 5000 } | ||
); | ||
|
||
const logBottomRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
// 👇️ scroll to bottom every time messages change | ||
logBottomRef.current?.scrollIntoView({ behavior: "smooth" }); | ||
}, [result.data]); | ||
|
||
return ( | ||
<Transition.Root show={isOpen} as={Fragment}> | ||
<Dialog as="div" className="relative z-10" onClose={handleClose}> | ||
<div className="fixed inset-0 bg-black/30" aria-hidden="true" /> | ||
<div className="fixed inset-0 overflow-hidden"> | ||
<div className="absolute inset-0 overflow-hidden"> | ||
<div className="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10"> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="transform transition ease-in-out duration-500" | ||
enterFrom="translate-x-full" | ||
enterTo="translate-x-0" | ||
leave="transform transition ease-in-out duration-500" | ||
leaveFrom="translate-x-0" | ||
leaveTo="translate-x-full" | ||
> | ||
<Dialog.Panel className="pointer-events-auto w-screen max-w-4xl"> | ||
<div className="flex h-full flex-col overflow-y-scroll bg-white p-6 shadow-xl"> | ||
<div className="flex items-center justify-between"> | ||
<Dialog.Title className="text-lg font-medium text-gray-900"> | ||
{selectedPod?.metadata?.name} | ||
</Dialog.Title> | ||
|
||
<Dialog.Description className="text-sm text-gray-500"> | ||
{/* TODO: update this to be a selector to pick containers */} | ||
Container: {selectedPod?.spec?.containers[0].name} | ||
</Dialog.Description> | ||
|
||
<button | ||
type="button" | ||
className="rounded-md p-2 text-gray-400 hover:bg-gray-200 hover:text-gray-600" | ||
onClick={handleClose} | ||
> | ||
<span className="sr-only">Close</span> | ||
<XMarkIcon className="h-6 w-6" aria-hidden="true" /> | ||
</button> | ||
</div> | ||
|
||
<div className="relative h-full flex-1"> | ||
<div className="absolute inset-0 h-full"> | ||
<div className="h-full shadow-xl" aria-hidden="true"> | ||
<pre className="h-full overflow-y-scroll rounded-md bg-gray-200 p-4 text-sm text-gray-500"> | ||
{result.data} | ||
<div ref={logBottomRef} /> | ||
</pre> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</Dialog.Panel> | ||
</Transition.Child> | ||
</div> | ||
</div> | ||
</div> | ||
</Dialog> | ||
</Transition.Root> | ||
); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced with just a function that returns the API since each resource has their own params to use to filter down the list etc.