-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: tracer doesn't delete objects on restart
- Loading branch information
Showing
32 changed files
with
364 additions
and
214 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ use tokio::io::{ | |
BufWriter, | ||
}; | ||
use tokio::process::Command; | ||
use tracing::*; | ||
|
||
use crate::prelude::*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
use tracing::*; | ||
|
||
use super::*; | ||
use crate::prelude::*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
use kube::api::{ | ||
DynamicObject, | ||
GroupVersionKind, | ||
}; | ||
use kube::api::DynamicObject; | ||
use kube::discovery::ApiResource; | ||
use rstest::*; | ||
|
||
use crate::prelude::*; | ||
|
||
#[fixture] | ||
pub fn test_deployment(#[default(TEST_DEPLOYMENT)] name: &str) -> DynamicObject { | ||
DynamicObject::new( | ||
&name, | ||
&ApiResource::from_gvk(&GroupVersionKind::gvk("core".into(), "v1".into(), "deployment".into())), | ||
) | ||
.within(TEST_NAMESPACE) | ||
DynamicObject::new(&name, &ApiResource::from_gvk(&DEPL_GVK)).within(TEST_NAMESPACE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use std::collections::VecDeque; | ||
use std::ops::Index; | ||
|
||
use kube::api::DynamicObject; | ||
use sk_core::prelude::*; | ||
use tracing::*; | ||
|
||
use crate::{ | ||
TraceAction, | ||
TraceEvent, | ||
}; | ||
|
||
#[derive(Default)] | ||
pub struct TraceEventList(VecDeque<TraceEvent>); | ||
|
||
impl TraceEventList { | ||
pub(crate) fn append(&mut self, ts: i64, obj: &DynamicObject, action: TraceAction) { | ||
info!( | ||
"{:?} @ {ts}: {} {}", | ||
action, | ||
obj.types | ||
.clone() | ||
.map(|tm| format!("{}.{}", tm.api_version, tm.kind)) | ||
.unwrap_or("<unknown type>".into()), | ||
obj.namespaced_name(), | ||
); | ||
|
||
let obj = obj.clone(); | ||
match self.0.back_mut() { | ||
Some(evt) if evt.ts == ts => match action { | ||
TraceAction::ObjectApplied => evt.applied_objs.push(obj), | ||
TraceAction::ObjectDeleted => evt.deleted_objs.push(obj), | ||
}, | ||
_ => { | ||
let evt = match action { | ||
TraceAction::ObjectApplied => TraceEvent { ts, applied_objs: vec![obj], ..Default::default() }, | ||
TraceAction::ObjectDeleted => TraceEvent { ts, deleted_objs: vec![obj], ..Default::default() }, | ||
}; | ||
self.0.push_back(evt); | ||
}, | ||
} | ||
} | ||
|
||
pub(crate) fn back(&self) -> Option<&TraceEvent> { | ||
self.0.back() | ||
} | ||
|
||
pub(crate) fn front(&self) -> Option<&TraceEvent> { | ||
self.0.front() | ||
} | ||
|
||
pub(crate) fn is_empty(&self) -> bool { | ||
self.0.is_empty() | ||
} | ||
|
||
pub(crate) fn len(&self) -> usize { | ||
self.0.len() | ||
} | ||
} | ||
|
||
impl Index<usize> for TraceEventList { | ||
type Output = TraceEvent; | ||
|
||
fn index(&self, i: usize) -> &Self::Output { | ||
&self.0[i] | ||
} | ||
} | ||
|
||
impl From<VecDeque<TraceEvent>> for TraceEventList { | ||
fn from(v: VecDeque<TraceEvent>) -> TraceEventList { | ||
TraceEventList(v) | ||
} | ||
} | ||
|
||
impl From<Vec<TraceEvent>> for TraceEventList { | ||
fn from(v: Vec<TraceEvent>) -> TraceEventList { | ||
TraceEventList(v.into()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
impl FromIterator<TraceEvent> for TraceEventList { | ||
fn from_iter<T: IntoIterator<Item = TraceEvent>>(ii: T) -> Self { | ||
TraceEventList(ii.into_iter().collect()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.