Skip to content

Commit

Permalink
feat: add functionality to get deployment list (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhu2000 authored Jan 15, 2023
1 parent 592a430 commit e20a331
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 23 deletions.
6 changes: 5 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

mod resources;

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

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
get_cron_jobs,
get_deployments,
get_pods,
get_namespaces,
])
Expand Down
9 changes: 9 additions & 0 deletions src-tauri/src/resources/deployments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use k8s_openapi::api::apps::v1::Deployment;
use kube::core::ObjectList;

use super::internal::get_resource_list;

#[tauri::command]
pub async fn get_deployments(namespace: Option<String>) -> ObjectList<Deployment> {
return get_resource_list(namespace).await;
}
1 change: 1 addition & 0 deletions src-tauri/src/resources/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod cron_jobs;
pub mod deployments;
pub mod namespaces;
pub mod pods;

Expand Down
35 changes: 35 additions & 0 deletions src/deployments/deployments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { V1Deployment } from "@kubernetes/client-node";
import { useQuery } from "@tanstack/react-query";
import { invoke } from "@tauri-apps/api";

import { Table, TableHeader, TableBody, TableCell } from "../components/table";
import { useCurrentNamespace } from "../namespaces/namespaces";

export function Deployments() {
const { namespace } = useCurrentNamespace();

const result = useQuery(["deployments", namespace], () => {
return invoke<{ items: V1Deployment[] }>(`get_deployments`, { namespace });
});

const data = result.data?.items ?? [];

return (
<div>
<Table>
<TableHeader headers={["Name", "Image", "Pods"]} />
<TableBody>
{data.map((item) => (
<tr key={item.metadata?.uid}>
<TableCell>{item.metadata?.name}</TableCell>
<TableCell>{item.spec?.template.spec?.containers[0].image}</TableCell>
<TableCell>
{item.status?.availableReplicas} / {item.status?.replicas}
</TableCell>
</tr>
))}
</TableBody>
</Table>
</div>
);
}
8 changes: 2 additions & 6 deletions src/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { Link } from "@tanstack/react-router";
import type { PropsWithChildren } from "react";

import { NamespaceSelect } from "./namespaces/namespace-select";

const navigation = [
{ name: "Pods", href: "/pods" },
{ name: "Cron Jobs", href: "/cron-jobs" },
] as const;
import { navigationLinks } from "./router";

export function Layout({ children }: PropsWithChildren) {
return (
Expand All @@ -21,7 +17,7 @@ export function Layout({ children }: PropsWithChildren) {

<div className="flex flex-1 flex-col overflow-y-auto">
<nav className="flex-1 space-y-1 px-2 py-4">
{navigation.map((item) => (
{navigationLinks.map((item) => (
<Link
key={item.name}
to={item.href}
Expand Down
32 changes: 16 additions & 16 deletions src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Outlet, createReactRouter, createRouteConfig } from "@tanstack/react-ro

import { AppProviders } from "./app-providers";
import { CronJobs } from "./cron-jobs/cron-jobs";
import { Deployments } from "./deployments/deployments";
import { Layout } from "./layout";
import { Pods } from "./pods/pods";

Expand All @@ -17,24 +18,23 @@ const rootRoute = createRouteConfig({
),
});

const homeRoute = rootRoute.createRoute({
path: "/",
component: () => <div>TODO: figure out what to show by default</div>,
});

const podsRoute = rootRoute.createRoute({
path: "/pods",
component: Pods,
});

const cronJobsRoute = rootRoute.createRoute({
path: "/cron-jobs",
component: CronJobs,
});

const routeConfig = rootRoute.addChildren([homeRoute, podsRoute, cronJobsRoute]);
const routeConfig = rootRoute.addChildren([
rootRoute.createRoute({
path: "/",
component: () => <div>TODO: figure out what to show by default</div>,
}),
rootRoute.createRoute({ path: "/pods", component: Pods }),
rootRoute.createRoute({ path: "/cron-jobs", component: CronJobs }),
rootRoute.createRoute({ path: "/deployments", component: Deployments }),
]);
export const router = createReactRouter({ routeConfig });

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

declare module "@tanstack/react-router" {
interface RegisterRouter {
router: typeof router;
Expand Down

0 comments on commit e20a331

Please sign in to comment.