Skip to content

Commit

Permalink
feat: added view for PVCs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen Nijhuis committed Dec 27, 2023
1 parent d040b32 commit 7123015
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 3 deletions.
35 changes: 34 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -274,6 +276,35 @@ async fn list_ingresses(
.map_err(|err| SerializableKubeError::from(err));
}

#[tauri::command]
async fn list_persistentvolumes(
context: &str,
) -> Result<Vec<PersistentVolume>, SerializableKubeError> {
let client: Client = client_with_context(context).await?;
let pv_api: Api<PersistentVolume> = 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<Vec<PersistentVolumeClaim>, SerializableKubeError> {
let client: Client = client_with_context(context).await?;
let pvc_api: Api<PersistentVolumeClaim> = 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<Mutex<Box<dyn Write + Send>>>,
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/Navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import NavigationItem from "./NavigationItem.vue";
<NavigationItem
icon="persistentvolumeclaims"
title="Persistent Volume Claims"
:to="{ name: 'PersistenVolumeClaims' }"
:to="{ name: 'PersistentVolumeClaims' }"
/>
</NavigationGroup>
</div>
Expand Down
30 changes: 30 additions & 0 deletions src/components/tables/persistentvolumeclaims/columns.ts
Original file line number Diff line number Diff line change
@@ -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<V1PersistentVolumeClaim>[] = [
{
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()
),
},
];
9 changes: 8 additions & 1 deletion src/providers/CommandPaletteProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToRefs<CommandPaletteState>> =
Symbol("CommandPaletteState");
export const OpenCommandPaletteKey: InjectionKey<() => void> =
Expand Down Expand Up @@ -51,7 +53,7 @@ export default {
};

const close = () => {
if (singleCommand.value) {
if (singleCommand.value && state.callStack.size === 1) {
singleCommand.value = false;
clearStack();
}
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const routes: Array<RouteRecordRaw> = [
name: "Ingresses",
component: () => import("./views/Ingresses.vue"),
},
{
path: "/persistentvolumeclaims",
name: "PersistentVolumeClaims",
component: () => import("./views/PersistentVolumeClaims.vue"),
},
];

const router = createRouter({
Expand Down
11 changes: 11 additions & 0 deletions src/services/Kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
V1Ingress,
V1Job,
V1Namespace,
V1PersistentVolumeClaim,
V1Pod,
V1Secret,
V1Service,
Expand Down Expand Up @@ -134,4 +135,14 @@ export class Kubernetes {
namespace: namespace,
});
}

static async getPersistentVolumeClaims(
context: string,
namespace: string
): Promise<V1PersistentVolumeClaim[]> {
return invoke("list_persistentvolumeclaims", {
context: context,
namespace: namespace,
});
}
}
54 changes: 54 additions & 0 deletions src/views/PersistentVolumeClaims.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script setup lang="ts">
import { injectStrict } from "@/lib/utils";
import { V1PersistentVolumeClaim } from "@kubernetes/client-node";
import { Kubernetes } from "@/services/Kubernetes";
import { ref, h } from "vue";
import { useToast, ToastAction } from "@/components/ui/toast";
import { KubeContextStateKey } from "@/providers/KubeContextProvider";
const { context, namespace } = injectStrict(KubeContextStateKey);
import DataTable from "@/components/ui/DataTable.vue";
import { columns } from "@/components/tables/persistentvolumeclaims/columns";
import { useDataRefresher } from "@/composables/refresher";
const { toast } = useToast();
const pvcs = ref<V1PersistentVolumeClaim[]>([]);
async function getPersistentVolumeClaims(refresh: boolean = false) {
if (!refresh) {
pvcs.value = [];
}
Kubernetes.getPersistentVolumeClaims(
context.value,
namespace.value === "all" ? "" : namespace.value
)
.then((results: V1PersistentVolumeClaim[]) => {
pvcs.value = results;
})
.catch((error) => {
toast({
title: "An error occured",
description: error.message,
variant: "destructive",
action: h(
ToastAction,
{ altText: "Retry", onClick: () => startRefreshing() },
{ default: () => "Retry" }
),
});
stopRefreshing();
});
}
const { startRefreshing, stopRefreshing } = useDataRefresher(
getPersistentVolumeClaims,
1000,
[context, namespace]
);
</script>
x
<template>
<DataTable :data="pvcs" :columns="columns" />
</template>

0 comments on commit 7123015

Please sign in to comment.