Skip to content

Commit

Permalink
Fix filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnedo committed Jul 29, 2024
1 parent 156f1a4 commit a8212ad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ impl DefaultExecutor {
fn remove_cron(&self, cron: CronJob) -> Result<(), Box<dyn Error>> {
let ns_name = metadata_name(&cron);
// systemctl stop skate-cronjob-{}
exec_cmd("systemctl", &["stop", &format!("skate-cronjob-{}", &ns_name.to_string())]);
let _ = exec_cmd("systemctl", &["stop", &format!("skate-cronjob-{}", &ns_name.to_string())]);

// systemctl disable skate-cronjob-{}
exec_cmd("systemctl", &["disable", &format!("skate-cronjob-{}", &ns_name.to_string())]);
let _ = exec_cmd("systemctl", &["disable", &format!("skate-cronjob-{}", &ns_name.to_string())]);
// rm /etc/systemd/system/skate-cronjob-{}.service
exec_cmd("rm", &[&format!("/etc/systemd/system/skate-cronjob-{}.service", &ns_name.to_string())]);
exec_cmd("rm", &[&format!("/etc/systemd/system/skate-cronjob-{}.timer", &ns_name.to_string())]);
let _ = exec_cmd("rm", &[&format!("/etc/systemd/system/skate-cronjob-{}.service", &ns_name.to_string())]);
let _ = exec_cmd("rm", &[&format!("/etc/systemd/system/skate-cronjob-{}.timer", &ns_name.to_string())]);
// systemctl daemon-reload
exec_cmd("systemctl", &["daemon-reload"])?;
let _ = exec_cmd("systemctl", &["daemon-reload"])?;
// systemctl reset-failed
exec_cmd("systemctl", &["reset-failed"])?;
let _ = exec_cmd("systemctl", &["reset-failed"])?;
let _ = self.store.remove_object("cronjob", &ns_name.to_string())?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/get/cronjob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub (crate) struct CronjobsLister {}
impl Lister<ObjectListItem> for CronjobsLister {
fn selector(&self, si: &SystemInfo, ns: &str, id: &str) -> Option<Vec<ObjectListItem>> {
si.cronjobs.as_ref().and_then(|jobs| Some(jobs.iter().filter(|j| {
let filterable: Box<dyn NameFilters> = Box::new(j.clone());
let filterable: Box<dyn NameFilters> = Box::new(*j);
return filterable.filter_names(id, ns);
}).map(|p| p.clone()).collect()))
}
Expand Down
9 changes: 7 additions & 2 deletions src/get/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ pub(crate) trait NameFilters {
fn name(&self) -> String;
fn namespace(&self) -> String;
fn filter_names(&self, name: &str, ns: &str) -> bool {
let ns = match ns.is_empty(){
true => &"default",
false => ns
};

if !ns.is_empty() && self.namespace() != ns {
return false;
}
if !name.is_empty() && self.id() != name && self.name() != name {
if !name.is_empty() && ( self.id() != name || self.name() != name ) {
return false;
}
if ns.is_empty() && name.is_empty() && self.namespace() != "skate" {
if ns.is_empty() && name.is_empty() && self.namespace() == "skate" {
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/get/pod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Lister<PodmanPodInfo> for PodLister {
fn selector(&self, si: &SystemInfo, ns: &str, id: &str) -> Option<Vec<PodmanPodInfo>> {
return si.pods.as_ref().and_then(|pods| {
Some(pods.iter().filter(|p| {
let filterable: Box<dyn NameFilters> = Box::new(p.clone());
let filterable: Box<dyn NameFilters> = Box::new(*p);
filterable.filter_names(id, ns)
}).map(|p| p.clone()).collect())
})
Expand Down

0 comments on commit a8212ad

Please sign in to comment.