Skip to content

Commit

Permalink
fixing pre-commit and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
drmorr0 committed Oct 23, 2023
1 parent 87b0cb3 commit 0754799
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Run sccache
uses: mozilla-actions/[email protected]
- name: Lint Rust code
run: cargo clippy
run: cargo clippy -- -Dwarnings
test-rust:
runs-on: ubuntu-latest
env:
Expand Down
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ repos:
args: ["--allow-multiple-documents"]
- id: trailing-whitespace
- repo: https://github.com/golangci/golangci-lint
rev: v1.54.2
rev: v1.55.0
hooks:
- id: golangci-lint
- id: golangci-lint-full
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
Expand All @@ -21,6 +21,8 @@ repos:
args:
- --target-dir
- /tmp/cargo
- --
- -Dwarnings
- repo: https://github.com/futuretech6/pre-commit-rust-nightly
rev: v1.1
hooks:
Expand Down
3 changes: 2 additions & 1 deletion ctrl/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ async fn run(opts: Options) -> EmptyResult {
.run(reconcile, error_policy, Arc::new(SimulationContext::new(client, opts)))
.for_each(|_| future::ready(()));

Ok(ctrl.await)
ctrl.await;
Ok(())
}

#[tokio::main]
Expand Down
3 changes: 1 addition & 2 deletions ctrl/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ pub(super) fn build_mutating_webhook(
}]),
..Default::default()
}]),
..Default::default()
})
}

Expand All @@ -96,7 +95,7 @@ pub(super) fn build_driver_job(
cert_secret_name: &str,
trace_path: &str,
) -> anyhow::Result<batchv1::Job> {
let trace_url = Url::parse(&trace_path)?;
let trace_url = Url::parse(trace_path)?;
let (trace_vm, trace_volume, trace_mount_path) = match storage::get_scheme(&trace_url)? {
storage::Scheme::AmazonS3 => todo!(),
storage::Scheme::Local => get_local_trace_volume(&trace_url)?,
Expand Down
2 changes: 1 addition & 1 deletion driver/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl TraceRunner {
// We're currently assuming that all tracked objects are namespace-scoped,
// this will panic/fail if that is not true.
for obj in &evt.applied_objs {
let gvk = GVK::from_dynamic_obj(&obj)?;
let gvk = GVK::from_dynamic_obj(obj)?;
let original_ns = obj.namespace().unwrap();
let virtual_ns = format!("{}-{}", self.ctx.virtual_ns_prefix, original_ns);

Expand Down
4 changes: 2 additions & 2 deletions lib/rust/jsonutils/patch_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ err_impl! {JsonPatchError,
}

pub fn escape(path: &str) -> String {
let path = path.replace("~", "~0");
path.replace("/", "~1")
let path = path.replace('~', "~0");
path.replace('/', "~1")
}

pub fn add(path: &str, key: &str, value: &Value, obj: &mut Value, overwrite: bool) -> EmptyResult {
Expand Down
2 changes: 1 addition & 1 deletion lib/rust/k8s/gvk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<'de> de::Visitor<'de> for GVKVisitor {
return Err(E::custom(format!("invalid format for gvk: {value}")));
}

let parts = vec![p1[0], p2[0], p2[1]];
let parts = [p1[0], p2[0], p2[1]];
Ok(GVK(GroupVersionKind::gvk(parts[0], parts[1], parts[2])))
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rust/k8s/pod_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ impl PodExt for corev1::Pod {

if let Some(containers) = spec.init_containers.as_mut() {
for container in containers {
(*container).volume_mounts = Some(filter_volumes!(container.volume_mounts));
container.volume_mounts = Some(filter_volumes!(container.volume_mounts));
}
}

for container in &mut spec.containers {
(*container).volume_mounts = Some(filter_volumes!(container.volume_mounts));
container.volume_mounts = Some(filter_volumes!(container.volume_mounts));
}

Ok(spec)
Expand Down
12 changes: 6 additions & 6 deletions lib/rust/k8s/pod_lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ impl PodLifecycleData {
}

pub fn start_ts(&self) -> Option<i64> {
match self {
&PodLifecycleData::Running(ts) => Some(ts),
&PodLifecycleData::Finished(ts, _) => Some(ts),
match *self {
PodLifecycleData::Running(ts) => Some(ts),
PodLifecycleData::Finished(ts, _) => Some(ts),
_ => None,
}
}
Expand All @@ -104,9 +104,9 @@ impl PodLifecycleData {
// If at least one of the pod's lifecycle events appears between the given time window, OR
// if the pod is still running at the end of the given time window, it counts as
// overlapping the time window.
match self {
&PodLifecycleData::Running(ts) => ts < end_ts,
&PodLifecycleData::Finished(s, e) => (start_ts <= s && s < end_ts) || (start_ts <= e && e < end_ts),
match *self {
PodLifecycleData::Running(ts) => ts < end_ts,
PodLifecycleData::Finished(s, e) => (start_ts <= s && s < end_ts) || (start_ts <= e && e < end_ts),
_ => false,
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rust/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct TraceIterator<'a> {
pub trait TraceStorable {
fn create_or_update_obj(&mut self, obj: &DynamicObject, ts: i64, maybe_old_hash: Option<u64>);
fn delete_obj(&mut self, obj: &DynamicObject, ts: i64);
fn update_all_objs(&mut self, objs: &Vec<DynamicObject>, ts: i64);
fn update_all_objs(&mut self, objs: &[DynamicObject], ts: i64);
fn lookup_pod_lifecycle(&self, owner_ns_name: &str, pod_hash: u64, seq: usize) -> PodLifecycleData;
fn record_pod_lifecycle(
&mut self,
Expand All @@ -56,7 +56,7 @@ pub trait TraceStorable {
fn config(&self) -> &TracerConfig;
fn has_obj(&self, ns_name: &str) -> bool;
fn start_ts(&self) -> Option<i64>;
fn iter<'a>(&'a self) -> TraceIterator<'a>;
fn iter(&self) -> TraceIterator<'_>;
}

#[derive(Default)]
Expand Down
5 changes: 3 additions & 2 deletions lib/rust/store/pod_owners_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl PodOwnersMap {
owner_ns_name: &str,
pod_hash: u64,
) -> Option<&'a Vec<PodLifecycleData>> {
Some(self.m.get(owner_ns_name)?.get(&pod_hash)?)
self.m.get(owner_ns_name)?.get(&pod_hash)
}

pub(super) fn store_new_pod_lifecycle(
Expand Down Expand Up @@ -112,7 +112,8 @@ impl PodOwnersMap {
))?;

info!("updating pod {ns_name} owned by {owner_ns_name} with hash {hash}: {lifecycle_data:?}");
Ok(*pod_entry = lifecycle_data.clone())
*pod_entry = lifecycle_data.clone();
Ok(())
},
}
}
Expand Down
9 changes: 4 additions & 5 deletions lib/rust/store/trace_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl TraceStore {
events,
index,
pod_owners: PodOwnersMap::new_from_parts(lifecycle_data, HashMap::new()),
..Default::default()
})
}

Expand Down Expand Up @@ -91,7 +90,7 @@ impl TraceStore {
break;
}

if let Some(new_evt) = filter_event(&evt, filter) {
if let Some(new_evt) = filter_event(evt, filter) {
for obj in &new_evt.applied_objs {
let ns_name = obj.namespaced_name();
if new_evt.ts < start_ts {
Expand Down Expand Up @@ -165,7 +164,7 @@ impl TraceStorable for TraceStore {
self.index.remove(&ns_name);
}

fn update_all_objs(&mut self, objs: &Vec<DynamicObject>, ts: i64) {
fn update_all_objs(&mut self, objs: &[DynamicObject], ts: i64) {
let mut old_index = take(&mut self.index);
for obj in objs {
let ns_name = obj.namespaced_name();
Expand All @@ -179,7 +178,7 @@ impl TraceStorable for TraceStore {
}

fn lookup_pod_lifecycle(&self, owner_ns_name: &str, pod_hash: u64, seq: usize) -> PodLifecycleData {
let maybe_lifecycle_data = self.pod_owners.lifecycle_data_for(&owner_ns_name, pod_hash);
let maybe_lifecycle_data = self.pod_owners.lifecycle_data_for(owner_ns_name, pod_hash);
match maybe_lifecycle_data {
Some(data) => data[seq % data.len()].clone(),
_ => PodLifecycleData::Empty,
Expand Down Expand Up @@ -248,7 +247,7 @@ impl TraceStorable for TraceStore {
}
}

fn iter<'a>(&'a self) -> TraceIterator<'a> {
fn iter(&self) -> TraceIterator<'_> {
TraceIterator { events: &self.events, idx: 0 }
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rust/testutils/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mock! {
impl TraceStorable for TraceStore {
fn create_or_update_obj(&mut self, obj: &DynamicObject, ts: i64, maybe_old_hash: Option<u64>);
fn delete_obj(&mut self, obj: &DynamicObject, ts: i64);
fn update_all_objs(&mut self, objs: &Vec<DynamicObject>, ts: i64);
fn update_all_objs(&mut self, objs: &[DynamicObject], ts: i64);
fn lookup_pod_lifecycle(&self, owner_ns_name: &str, pod_hash: u64, seq: usize) -> PodLifecycleData;
fn record_pod_lifecycle(
&mut self,
Expand Down

0 comments on commit 0754799

Please sign in to comment.