diff --git a/src-tauri/src/cron_jobs/mod.rs b/src-tauri/src/cron_jobs/mod.rs deleted file mode 100644 index b1f5172..0000000 --- a/src-tauri/src/cron_jobs/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -use k8s_openapi::api::batch::v1::CronJob; - -use kube::{ - api::{Api, ListParams, ObjectList}, - Client, -}; - -#[tauri::command] -pub async fn get_cron_jobs(namespace: Option) -> ObjectList { - let client = Client::try_default().await.unwrap(); - - // match namespace - let cron_jobs: Api = match namespace { - Some(ns) => Api::namespaced(client, &ns), - None => Api::all(client), - }; - - let lp = ListParams::default(); - return cron_jobs.list(&lp).await.unwrap(); -} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 8ea8a7f..80b42be 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -3,11 +3,9 @@ windows_subsystem = "windows" )] -mod cron_jobs; -mod namespaces; -mod pods; +mod resources; -use crate::{cron_jobs::get_cron_jobs, namespaces::get_namespaces, pods::get_pods}; +use crate::resources::{cron_jobs::get_cron_jobs, namespaces::get_namespaces, pods::get_pods}; fn main() { tauri::Builder::default() diff --git a/src-tauri/src/pods/mod.rs b/src-tauri/src/pods/mod.rs deleted file mode 100644 index 498abb2..0000000 --- a/src-tauri/src/pods/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -use k8s_openapi::api::core::v1::Pod; - -use kube::{ - api::{Api, ListParams, ObjectList}, - Client, -}; - -#[tauri::command] -pub async fn get_pods(namespace: Option) -> ObjectList { - let client = Client::try_default().await.unwrap(); - - // match namespace - let pods: Api = match namespace { - Some(ns) => Api::namespaced(client, &ns), - None => Api::all(client), - }; - - let lp = ListParams::default(); - return pods.list(&lp).await.unwrap(); -} diff --git a/src-tauri/src/resources/cron_jobs.rs b/src-tauri/src/resources/cron_jobs.rs new file mode 100644 index 0000000..8ea8cb7 --- /dev/null +++ b/src-tauri/src/resources/cron_jobs.rs @@ -0,0 +1,11 @@ +use k8s_openapi::api::batch::v1::CronJob; +use kube::core::ObjectList; + +// use crate::internal::get_resource_list; + +use super::internal::get_resource_list; + +#[tauri::command] +pub async fn get_cron_jobs(namespace: Option) -> ObjectList { + return get_resource_list(namespace).await; +} diff --git a/src-tauri/src/resources/internal/mod.rs b/src-tauri/src/resources/internal/mod.rs new file mode 100644 index 0000000..ee92204 --- /dev/null +++ b/src-tauri/src/resources/internal/mod.rs @@ -0,0 +1,20 @@ +use k8s_openapi::NamespaceResourceScope; +use kube::{api::ListParams, core::ObjectList, Api, Client}; + +pub async fn get_resource_list(namespace: Option) -> ObjectList +where + T: serde::de::DeserializeOwned + + std::fmt::Debug + + Clone + + k8s_openapi::Metadata + + kube::Resource, + ::DynamicType: std::default::Default, +{ + let client = Client::try_default().await.unwrap(); + let api: Api = match namespace { + Some(ns) => Api::namespaced(client, &ns), + None => Api::all(client), + }; + let lp = ListParams::default(); + return api.list(&lp).await.unwrap(); +} diff --git a/src-tauri/src/resources/mod.rs b/src-tauri/src/resources/mod.rs new file mode 100644 index 0000000..4b426d2 --- /dev/null +++ b/src-tauri/src/resources/mod.rs @@ -0,0 +1,5 @@ +pub mod cron_jobs; +pub mod namespaces; +pub mod pods; + +mod internal; diff --git a/src-tauri/src/namespaces/mod.rs b/src-tauri/src/resources/namespaces.rs similarity index 100% rename from src-tauri/src/namespaces/mod.rs rename to src-tauri/src/resources/namespaces.rs diff --git a/src-tauri/src/resources/pods.rs b/src-tauri/src/resources/pods.rs new file mode 100644 index 0000000..ed253e5 --- /dev/null +++ b/src-tauri/src/resources/pods.rs @@ -0,0 +1,10 @@ +use k8s_openapi::api::core::v1::Pod; + +use kube::api::ObjectList; + +use super::internal::get_resource_list; + +#[tauri::command] +pub async fn get_pods(namespace: Option) -> ObjectList { + return get_resource_list(namespace).await; +}