Skip to content
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: add functionality to get replica sets #37

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

mod resources;

use crate::resources::{cron_jobs, deployments, jobs, namespaces, pods};
use crate::resources::{cron_jobs, deployments, jobs, namespaces, pods, replica_sets};

fn main() {
tauri::Builder::default()
Expand All @@ -18,6 +18,7 @@ fn main() {
pods::get_pod_logs,
pods::get_pods,
namespaces::get_namespaces,
replica_sets::get_replica_sets
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub mod deployments;
pub mod jobs;
pub mod namespaces;
pub mod pods;
pub mod replica_sets;
11 changes: 11 additions & 0 deletions src-tauri/src/resources/replica_sets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use k8s_openapi::api::apps::v1::ReplicaSet;
use kube::{api::ListParams, core::ObjectList, Api};

use super::internal::get_api;

#[tauri::command]
pub async fn get_replica_sets(namespace: Option<String>) -> ObjectList<ReplicaSet> {
let api: Api<ReplicaSet> = get_api(namespace).await;
let lp = ListParams::default();
return api.list(&lp).await.unwrap();
}
6 changes: 3 additions & 3 deletions src/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Link } from "@tanstack/react-router";
import type { PropsWithChildren } from "react";

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

export function Layout({ children }: PropsWithChildren) {
return (
Expand All @@ -17,10 +17,10 @@ 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">
{navigationLinks.map((item) => (
{routes.map((item) => (
<Link
key={item.name}
to={item.href}
to={item.path}
className="group flex items-center rounded-md p-2 text-sm font-medium text-gray-800 hover:bg-gray-400"
>
{item.name}
Expand Down
35 changes: 35 additions & 0 deletions src/replica-sets/replica-sets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { V1ReplicaSet } 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 ReplicaSets() {
const { namespace } = useCurrentNamespace();

const result = useQuery(["replica-sets", namespace], () => {
return invoke<{ items: V1ReplicaSet[] }>(`get_replica_sets`, { namespace });
});

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

return (
<div>
<Table>
<TableHeader headers={["Name", "Images", "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?.replicas} / {item.spec?.replicas}
</TableCell>
</tr>
))}
</TableBody>
</Table>
</div>
);
}
27 changes: 13 additions & 14 deletions src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { Outlet, createReactRouter, createRouteConfig } from "@tanstack/react-router";
import { Outlet, ReactRouter, createRouteConfig } from "@tanstack/react-router";

import { AppProviders } from "./app-providers";
import { CronJobs } from "./cron-jobs/cron-jobs";
import { Deployments } from "./deployments/deployments";
import { Jobs } from "./jobs/jobs";
import { Layout } from "./layout";
import { Pods } from "./pods/pods";
import { ReplicaSets } from "./replica-sets/replica-sets";
import { TestPlayground } from "./test-playground/test-playground";

const rootRoute = createRouteConfig({
Expand All @@ -20,26 +21,24 @@ const rootRoute = createRouteConfig({
),
});

export const routes = [
{ name: "Cron Jobs", path: "/cron-jobs", component: Pods },
{ name: "Deployments", path: "/deployments", component: CronJobs },
{ name: "Jobs", path: "/jobs", component: Deployments },
{ name: "Pods", path: "/pods", component: Jobs },
{ name: "Replica Sets", path: "/replica-sets", component: ReplicaSets },
{ name: "Testing", path: "/test-playground", component: TestPlayground },
] as const;

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 }),
rootRoute.createRoute({ path: "/jobs", component: Jobs }),
rootRoute.createRoute({ path: "/test-playground", component: TestPlayground }),
...routes.map((route) => rootRoute.createRoute(route)),
]);
export const router = createReactRouter({ routeConfig });

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

declare module "@tanstack/react-router" {
interface RegisterRouter {
Expand Down
48 changes: 23 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/runtime@npm:^7.16.7, @babel/runtime@npm:^7.7.6":
"@babel/runtime@npm:^7.16.7":
version: 7.20.7
resolution: "@babel/runtime@npm:7.20.7"
dependencies:
Expand Down Expand Up @@ -728,10 +728,10 @@ __metadata:
languageName: node
linkType: hard

"@solidjs/reactivity@npm:^0.0.6":
version: 0.0.6
resolution: "@solidjs/reactivity@npm:0.0.6"
checksum: bdfb951b3a20248562b0e4e76c417becbaf564401af4a6b1c89dd95c8686496025629183d6574f1b53f477570a08646f52a316572783ab5ca7efe6bc66b3d6ae
"@solidjs/reactivity@npm:^0.0.7":
version: 0.0.7
resolution: "@solidjs/reactivity@npm:0.0.7"
checksum: 1b166aaa14c9eeaaa63db433ab9a2a166f5201ed81c767825621a31619524832f8a8e2f1692062ea0bf96785c9e47b030cf0f4bdc330d1fd616c5588bf55589a
languageName: node
linkType: hard

Expand Down Expand Up @@ -797,32 +797,32 @@ __metadata:
linkType: hard

"@tanstack/react-router@npm:beta":
version: 0.0.1-beta.48
resolution: "@tanstack/react-router@npm:0.0.1-beta.48"
version: 0.0.1-beta.53
resolution: "@tanstack/react-router@npm:0.0.1-beta.53"
dependencies:
"@babel/runtime": ^7.16.7
"@solidjs/reactivity": ^0.0.6
"@tanstack/router-core": 0.0.1-beta.45
"@solidjs/reactivity": ^0.0.7
"@tanstack/router-core": 0.0.1-beta.53
use-sync-external-store: ^1.2.0
peerDependencies:
react: ">=16"
react-dom: ">=16"
checksum: 889e8506da32a3ecec35b71844bdc23feee98bba3cb55d85a4845e7b03b941af5ec94dadccc645f8067ad3b0448b5c4b3f4aca0b207c0d13b196f03dd360a38e
checksum: 0c5087383e57bc53f771c7dc7dd0a9d18a5fc70573665df182537f49d05f0dcf4ed19daec2f8873e51071d71049dd2f5500795bba0474ffbbe28f5215072def6
languageName: node
linkType: hard

"@tanstack/router-core@npm:0.0.1-beta.45":
version: 0.0.1-beta.45
resolution: "@tanstack/router-core@npm:0.0.1-beta.45"
"@tanstack/router-core@npm:0.0.1-beta.53":
version: 0.0.1-beta.53
resolution: "@tanstack/router-core@npm:0.0.1-beta.53"
dependencies:
"@babel/runtime": ^7.16.7
"@solidjs/reactivity": ^0.0.6
history: ^5.2.0
"@solidjs/reactivity": ^0.0.7
immer: ^9.0.15
tiny-invariant: ^1.3.1
peerDependencies:
react: ">=16"
react-dom: ">=16"
checksum: 3deab3a90b060a85b451531e993c9d432803a96b636a1857726e747f57f3c20ef45127d9c2a022d3c5ee62e1b16617cd298676f90bb2b19bd5046d98d42671ba
checksum: fb7302c43a7ec23cd74730f885f93c3866ba7d00d6c5a95b45d777de17d365cfb8bc13b6527dbdf88c12d7c3d4b5d9c571ebeb1ce530b2ec4318424013dc3c7e
languageName: node
linkType: hard

Expand Down Expand Up @@ -2809,15 +2809,6 @@ __metadata:
languageName: node
linkType: hard

"history@npm:^5.2.0":
version: 5.3.0
resolution: "history@npm:5.3.0"
dependencies:
"@babel/runtime": ^7.7.6
checksum: d73c35df49d19ac172f9547d30a21a26793e83f16a78386d99583b5bf1429cc980799fcf1827eb215d31816a6600684fba9686ce78104e23bd89ec239e7c726f
languageName: node
linkType: hard

"http-cache-semantics@npm:^4.1.0":
version: 4.1.0
resolution: "http-cache-semantics@npm:4.1.0"
Expand Down Expand Up @@ -2889,6 +2880,13 @@ __metadata:
languageName: node
linkType: hard

"immer@npm:^9.0.15":
version: 9.0.18
resolution: "immer@npm:9.0.18"
checksum: 85b3153dd01fce73c40591d0d6d7cd95878dab49f8ec4744c044adac05e0dab847b30c26259c478a5f87f974897be6df2780ff5bf86c8a0a27578fdeb300eb10
languageName: node
linkType: hard

"import-fresh@npm:^3.0.0, import-fresh@npm:^3.2.1":
version: 3.3.0
resolution: "import-fresh@npm:3.3.0"
Expand Down