Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor tauri commands to be more shareable. #14

Merged
merged 3 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}