From 7123015d67a215efd53ec898f3b68c256afd6fe6 Mon Sep 17 00:00:00 2001 From: Jeroen Nijhuis Date: Wed, 27 Dec 2023 13:42:39 +0100 Subject: [PATCH] feat: added view for PVCs --- src-tauri/src/main.rs | 35 +++++++++++- src/components/Navigation.vue | 2 +- .../tables/persistentvolumeclaims/columns.ts | 30 +++++++++++ src/providers/CommandPaletteProvider.ts | 9 +++- src/router.ts | 5 ++ src/services/Kubernetes.ts | 11 ++++ src/views/PersistentVolumeClaims.vue | 54 +++++++++++++++++++ 7 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 src/components/tables/persistentvolumeclaims/columns.ts create mode 100644 src/views/PersistentVolumeClaims.vue diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6d6bd40..f9166c9 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -7,7 +7,9 @@ use k8s_openapi::api::networking::v1::Ingress; use tauri::Manager; use k8s_openapi::api::apps::v1::Deployment; -use k8s_openapi::api::core::v1::{ConfigMap, Namespace, Pod, Secret, Service}; +use k8s_openapi::api::core::v1::{ + ConfigMap, Namespace, PersistentVolume, PersistentVolumeClaim, Pod, Secret, Service, +}; use kube::api::ListParams; use kube::config::{KubeConfigOptions, Kubeconfig, KubeconfigError}; use kube::{api::Api, Client, Config, Error}; @@ -274,6 +276,35 @@ async fn list_ingresses( .map_err(|err| SerializableKubeError::from(err)); } +#[tauri::command] +async fn list_persistentvolumes( + context: &str, +) -> Result, SerializableKubeError> { + let client: Client = client_with_context(context).await?; + let pv_api: Api = Api::all(client); + + return pv_api + .list(&ListParams::default()) + .await + .map(|pvs| pvs.items) + .map_err(|err| SerializableKubeError::from(err)); +} + +#[tauri::command] +async fn list_persistentvolumeclaims( + context: &str, + namespace: &str, +) -> Result, SerializableKubeError> { + let client: Client = client_with_context(context).await?; + let pvc_api: Api = Api::namespaced(client, namespace); + + return pvc_api + .list(&ListParams::default()) + .await + .map(|pvcs| pvcs.items) + .map_err(|err| SerializableKubeError::from(err)); +} + struct TerminalSession { writer: Arc>>, } @@ -393,6 +424,8 @@ fn main() { list_services, list_virtual_services, list_ingresses, + list_persistentvolumes, + list_persistentvolumeclaims, create_tty_session, stop_tty_session, write_to_pty diff --git a/src/components/Navigation.vue b/src/components/Navigation.vue index 9a39ee3..083935a 100644 --- a/src/components/Navigation.vue +++ b/src/components/Navigation.vue @@ -56,7 +56,7 @@ import NavigationItem from "./NavigationItem.vue"; diff --git a/src/components/tables/persistentvolumeclaims/columns.ts b/src/components/tables/persistentvolumeclaims/columns.ts new file mode 100644 index 0000000..1b2bc3c --- /dev/null +++ b/src/components/tables/persistentvolumeclaims/columns.ts @@ -0,0 +1,30 @@ +import { V1PersistentVolumeClaim } from "@kubernetes/client-node"; +import { ColumnDef } from "@tanstack/vue-table"; +import { formatDateTimeDifference } from "@/lib/utils"; + +export const columns: ColumnDef[] = [ + { + accessorKey: "metadata.name", + header: "Name", + }, + { + header: "Storage Class", + accessorKey: "spec.storageClassName", + }, + { + header: "Size", + accessorKey: "status.capacity.storage", + }, + { + header: "Status", + accessorKey: "status.phase", + }, + { + header: "Age", + accessorFn: (row) => + formatDateTimeDifference( + row.metadata?.creationTimestamp || new Date(), + new Date() + ), + }, +]; diff --git a/src/providers/CommandPaletteProvider.ts b/src/providers/CommandPaletteProvider.ts index 2f3ff03..21506f8 100644 --- a/src/providers/CommandPaletteProvider.ts +++ b/src/providers/CommandPaletteProvider.ts @@ -7,6 +7,8 @@ import { } from "@/providers/KubeContextProvider"; import { provide, reactive, InjectionKey, toRefs, ToRefs } from "vue"; +export const RegisterCommandStateKey: InjectionKey<(command: Command) => void> = + Symbol("RegisterComand"); export const CommandPaletteStateKey: InjectionKey> = Symbol("CommandPaletteState"); export const OpenCommandPaletteKey: InjectionKey<() => void> = @@ -51,7 +53,7 @@ export default { }; const close = () => { - if (singleCommand.value) { + if (singleCommand.value && state.callStack.size === 1) { singleCommand.value = false; clearStack(); } @@ -95,11 +97,16 @@ export default { } }; + const registerCommand = (command: Command) => { + state.commands.push(command); + }; + provide(OpenCommandPaletteKey, open); provide(CloseCommandPaletteKey, close); provide(PushCommandKey, push); provide(ClearCommandCallStackKey, clearStack); provide(ShowSingleCommandKey, showSingleCommand); + provide(RegisterCommandStateKey, registerCommand); }, render(): any { return this.$slots.default(); diff --git a/src/router.ts b/src/router.ts index 45522ce..46036ac 100644 --- a/src/router.ts +++ b/src/router.ts @@ -46,6 +46,11 @@ const routes: Array = [ name: "Ingresses", component: () => import("./views/Ingresses.vue"), }, + { + path: "/persistentvolumeclaims", + name: "PersistentVolumeClaims", + component: () => import("./views/PersistentVolumeClaims.vue"), + }, ]; const router = createRouter({ diff --git a/src/services/Kubernetes.ts b/src/services/Kubernetes.ts index 6617c64..b0c0f8a 100644 --- a/src/services/Kubernetes.ts +++ b/src/services/Kubernetes.ts @@ -5,6 +5,7 @@ import { V1Ingress, V1Job, V1Namespace, + V1PersistentVolumeClaim, V1Pod, V1Secret, V1Service, @@ -134,4 +135,14 @@ export class Kubernetes { namespace: namespace, }); } + + static async getPersistentVolumeClaims( + context: string, + namespace: string + ): Promise { + return invoke("list_persistentvolumeclaims", { + context: context, + namespace: namespace, + }); + } } diff --git a/src/views/PersistentVolumeClaims.vue b/src/views/PersistentVolumeClaims.vue new file mode 100644 index 0000000..4d17004 --- /dev/null +++ b/src/views/PersistentVolumeClaims.vue @@ -0,0 +1,54 @@ + +x +