From 475a6efc54a07d80b763f9ff96acb0ae3ef046df Mon Sep 17 00:00:00 2001 From: David Hu Date: Sat, 14 Jan 2023 19:21:02 -0800 Subject: [PATCH 1/3] wip --- src-tauri/src/cron_jobs/mod.rs | 17 +++-------------- src-tauri/src/internal/mod.rs | 20 ++++++++++++++++++++ src-tauri/src/main.rs | 1 + src-tauri/src/pods/mod.rs | 18 ++++-------------- 4 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 src-tauri/src/internal/mod.rs diff --git a/src-tauri/src/cron_jobs/mod.rs b/src-tauri/src/cron_jobs/mod.rs index b1f5172..b116b9d 100644 --- a/src-tauri/src/cron_jobs/mod.rs +++ b/src-tauri/src/cron_jobs/mod.rs @@ -1,20 +1,9 @@ use k8s_openapi::api::batch::v1::CronJob; +use kube::core::ObjectList; -use kube::{ - api::{Api, ListParams, ObjectList}, - Client, -}; +use crate::internal::get_resource_list; #[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(); + return get_resource_list(namespace).await; } diff --git a/src-tauri/src/internal/mod.rs b/src-tauri/src/internal/mod.rs new file mode 100644 index 0000000..ee92204 --- /dev/null +++ b/src-tauri/src/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/main.rs b/src-tauri/src/main.rs index 8ea8a7f..2ceeef7 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -4,6 +4,7 @@ )] mod cron_jobs; +mod internal; mod namespaces; mod pods; diff --git a/src-tauri/src/pods/mod.rs b/src-tauri/src/pods/mod.rs index 498abb2..e389552 100644 --- a/src-tauri/src/pods/mod.rs +++ b/src-tauri/src/pods/mod.rs @@ -1,20 +1,10 @@ use k8s_openapi::api::core::v1::Pod; -use kube::{ - api::{Api, ListParams, ObjectList}, - Client, -}; +use kube::api::ObjectList; + +use crate::internal::get_resource_list; #[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(); + return get_resource_list(namespace).await; } From c0fe42df897e5f6a8a974e3726e0d80bdbf69ff2 Mon Sep 17 00:00:00 2001 From: David Hu Date: Sat, 14 Jan 2023 19:27:18 -0800 Subject: [PATCH 2/3] better --- src-tauri/src/main.rs | 9 ++++++--- .../src/{cron_jobs/mod.rs => resources/cron_jobs.rs} | 0 src-tauri/src/resources/mod.rs | 2 ++ src-tauri/src/{pods/mod.rs => resources/pods.rs} | 0 4 files changed, 8 insertions(+), 3 deletions(-) rename src-tauri/src/{cron_jobs/mod.rs => resources/cron_jobs.rs} (100%) create mode 100644 src-tauri/src/resources/mod.rs rename src-tauri/src/{pods/mod.rs => resources/pods.rs} (100%) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 2ceeef7..95fad47 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -3,12 +3,15 @@ windows_subsystem = "windows" )] -mod cron_jobs; mod internal; mod namespaces; -mod pods; -use crate::{cron_jobs::get_cron_jobs, namespaces::get_namespaces, pods::get_pods}; +mod resources; + +use crate::{ + namespaces::get_namespaces, + resources::{cron_jobs::get_cron_jobs, pods::get_pods}, +}; fn main() { tauri::Builder::default() diff --git a/src-tauri/src/cron_jobs/mod.rs b/src-tauri/src/resources/cron_jobs.rs similarity index 100% rename from src-tauri/src/cron_jobs/mod.rs rename to src-tauri/src/resources/cron_jobs.rs diff --git a/src-tauri/src/resources/mod.rs b/src-tauri/src/resources/mod.rs new file mode 100644 index 0000000..be909db --- /dev/null +++ b/src-tauri/src/resources/mod.rs @@ -0,0 +1,2 @@ +pub mod cron_jobs; +pub mod pods; diff --git a/src-tauri/src/pods/mod.rs b/src-tauri/src/resources/pods.rs similarity index 100% rename from src-tauri/src/pods/mod.rs rename to src-tauri/src/resources/pods.rs From 4e14b1f8ee3ad766e2244b299e0dcbb1a352ce55 Mon Sep 17 00:00:00 2001 From: David Hu Date: Sat, 14 Jan 2023 19:37:01 -0800 Subject: [PATCH 3/3] all-resources --- src-tauri/src/main.rs | 8 +------- src-tauri/src/resources/cron_jobs.rs | 4 +++- src-tauri/src/{ => resources}/internal/mod.rs | 0 src-tauri/src/resources/mod.rs | 3 +++ .../src/{namespaces/mod.rs => resources/namespaces.rs} | 0 src-tauri/src/resources/pods.rs | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) rename src-tauri/src/{ => resources}/internal/mod.rs (100%) rename src-tauri/src/{namespaces/mod.rs => resources/namespaces.rs} (100%) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 95fad47..80b42be 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -3,15 +3,9 @@ windows_subsystem = "windows" )] -mod internal; -mod namespaces; - mod resources; -use crate::{ - namespaces::get_namespaces, - resources::{cron_jobs::get_cron_jobs, 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/resources/cron_jobs.rs b/src-tauri/src/resources/cron_jobs.rs index b116b9d..8ea8cb7 100644 --- a/src-tauri/src/resources/cron_jobs.rs +++ b/src-tauri/src/resources/cron_jobs.rs @@ -1,7 +1,9 @@ use k8s_openapi::api::batch::v1::CronJob; use kube::core::ObjectList; -use crate::internal::get_resource_list; +// use crate::internal::get_resource_list; + +use super::internal::get_resource_list; #[tauri::command] pub async fn get_cron_jobs(namespace: Option) -> ObjectList { diff --git a/src-tauri/src/internal/mod.rs b/src-tauri/src/resources/internal/mod.rs similarity index 100% rename from src-tauri/src/internal/mod.rs rename to src-tauri/src/resources/internal/mod.rs diff --git a/src-tauri/src/resources/mod.rs b/src-tauri/src/resources/mod.rs index be909db..4b426d2 100644 --- a/src-tauri/src/resources/mod.rs +++ b/src-tauri/src/resources/mod.rs @@ -1,2 +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 index e389552..ed253e5 100644 --- a/src-tauri/src/resources/pods.rs +++ b/src-tauri/src/resources/pods.rs @@ -2,7 +2,7 @@ use k8s_openapi::api::core::v1::Pod; use kube::api::ObjectList; -use crate::internal::get_resource_list; +use super::internal::get_resource_list; #[tauri::command] pub async fn get_pods(namespace: Option) -> ObjectList {