Skip to content

Commit

Permalink
chore: refactor tauri commands to be more shareable. (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhu2000 authored Jan 15, 2023
1 parent 1bbdaf7 commit 3ea390e
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 44 deletions.
20 changes: 0 additions & 20 deletions src-tauri/src/cron_jobs/mod.rs

This file was deleted.

6 changes: 2 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 0 additions & 20 deletions src-tauri/src/pods/mod.rs

This file was deleted.

11 changes: 11 additions & 0 deletions src-tauri/src/resources/cron_jobs.rs
Original file line number Diff line number Diff line change
@@ -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<String>) -> ObjectList<CronJob> {
return get_resource_list(namespace).await;
}
20 changes: 20 additions & 0 deletions src-tauri/src/resources/internal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use k8s_openapi::NamespaceResourceScope;
use kube::{api::ListParams, core::ObjectList, Api, Client};

pub async fn get_resource_list<T>(namespace: Option<String>) -> ObjectList<T>
where
T: serde::de::DeserializeOwned
+ std::fmt::Debug
+ Clone
+ k8s_openapi::Metadata
+ kube::Resource<Scope = NamespaceResourceScope>,
<T as kube::Resource>::DynamicType: std::default::Default,
{
let client = Client::try_default().await.unwrap();
let api: Api<T> = match namespace {
Some(ns) => Api::namespaced(client, &ns),
None => Api::all(client),
};
let lp = ListParams::default();
return api.list(&lp).await.unwrap();
}
5 changes: 5 additions & 0 deletions src-tauri/src/resources/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod cron_jobs;
pub mod namespaces;
pub mod pods;

mod internal;
File renamed without changes.
10 changes: 10 additions & 0 deletions src-tauri/src/resources/pods.rs
Original file line number Diff line number Diff line change
@@ -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<String>) -> ObjectList<Pod> {
return get_resource_list(namespace).await;
}

0 comments on commit 3ea390e

Please sign in to comment.