From 8020e911bae2ba7f7dafc8f71e9aeaf73a9bb898 Mon Sep 17 00:00:00 2001 From: David Morrison Date: Sat, 21 Oct 2023 13:22:22 -0700 Subject: [PATCH] fixing pre-commit and linting --- .github/workflows/verify.yml | 2 +- .pre-commit-config.yaml | 6 ++++-- ctrl/main.rs | 3 ++- ctrl/objects.rs | 3 +-- driver/runner.rs | 2 +- lib/rust/jsonutils/patch_ext.rs | 4 ++-- lib/rust/k8s/gvk.rs | 2 +- lib/rust/k8s/pod_ext.rs | 4 ++-- lib/rust/k8s/pod_lifecycle.rs | 12 ++++++------ lib/rust/store/mod.rs | 4 ++-- lib/rust/store/pod_owners_map.rs | 5 +++-- lib/rust/store/trace_store.rs | 9 ++++----- lib/rust/testutils/store.rs | 2 +- 13 files changed, 30 insertions(+), 28 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 9fd881a7..9599be35 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -65,7 +65,7 @@ jobs: - name: Run sccache uses: mozilla-actions/sccache-action@v0.0.3 - name: Lint Rust code - run: cargo clippy + run: cargo clippy -- -Dwarnings test-rust: runs-on: ubuntu-latest env: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 61f6344e..36e57fd0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: @@ -21,6 +21,8 @@ repos: args: - --target-dir - /tmp/cargo + - -- + - -Dwarnings - repo: https://github.com/futuretech6/pre-commit-rust-nightly rev: v1.1 hooks: diff --git a/ctrl/main.rs b/ctrl/main.rs index 8b86f7f4..0e54ed37 100644 --- a/ctrl/main.rs +++ b/ctrl/main.rs @@ -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] diff --git a/ctrl/objects.rs b/ctrl/objects.rs index abe28674..0e80630a 100644 --- a/ctrl/objects.rs +++ b/ctrl/objects.rs @@ -70,7 +70,6 @@ pub(super) fn build_mutating_webhook( }]), ..Default::default() }]), - ..Default::default() }) } @@ -96,7 +95,7 @@ pub(super) fn build_driver_job( cert_secret_name: &str, trace_path: &str, ) -> anyhow::Result { - 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)?, diff --git a/driver/runner.rs b/driver/runner.rs index 39c8770d..4cecd852 100644 --- a/driver/runner.rs +++ b/driver/runner.rs @@ -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); diff --git a/lib/rust/jsonutils/patch_ext.rs b/lib/rust/jsonutils/patch_ext.rs index 1a6bf6d1..2f2fe8a1 100644 --- a/lib/rust/jsonutils/patch_ext.rs +++ b/lib/rust/jsonutils/patch_ext.rs @@ -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 { diff --git a/lib/rust/k8s/gvk.rs b/lib/rust/k8s/gvk.rs index 2d27a62e..1c334a07 100644 --- a/lib/rust/k8s/gvk.rs +++ b/lib/rust/k8s/gvk.rs @@ -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]))) } } diff --git a/lib/rust/k8s/pod_ext.rs b/lib/rust/k8s/pod_ext.rs index 54d27c0f..06698e5f 100644 --- a/lib/rust/k8s/pod_ext.rs +++ b/lib/rust/k8s/pod_ext.rs @@ -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) diff --git a/lib/rust/k8s/pod_lifecycle.rs b/lib/rust/k8s/pod_lifecycle.rs index fc8a85c6..c2120bf8 100644 --- a/lib/rust/k8s/pod_lifecycle.rs +++ b/lib/rust/k8s/pod_lifecycle.rs @@ -93,9 +93,9 @@ impl PodLifecycleData { } pub fn start_ts(&self) -> Option { - 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, } } @@ -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, } } diff --git a/lib/rust/store/mod.rs b/lib/rust/store/mod.rs index 424b60db..53bd5ac9 100644 --- a/lib/rust/store/mod.rs +++ b/lib/rust/store/mod.rs @@ -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); fn delete_obj(&mut self, obj: &DynamicObject, ts: i64); - fn update_all_objs(&mut self, objs: &Vec, 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, @@ -56,7 +56,7 @@ pub trait TraceStorable { fn config(&self) -> &TracerConfig; fn has_obj(&self, ns_name: &str) -> bool; fn start_ts(&self) -> Option; - fn iter<'a>(&'a self) -> TraceIterator<'a>; + fn iter(&self) -> TraceIterator<'_>; } #[derive(Default)] diff --git a/lib/rust/store/pod_owners_map.rs b/lib/rust/store/pod_owners_map.rs index 403a24f2..2729b83a 100644 --- a/lib/rust/store/pod_owners_map.rs +++ b/lib/rust/store/pod_owners_map.rs @@ -66,7 +66,7 @@ impl PodOwnersMap { owner_ns_name: &str, pod_hash: u64, ) -> Option<&'a Vec> { - 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( @@ -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(()) }, } } diff --git a/lib/rust/store/trace_store.rs b/lib/rust/store/trace_store.rs index 876a5636..ee49f234 100644 --- a/lib/rust/store/trace_store.rs +++ b/lib/rust/store/trace_store.rs @@ -59,7 +59,6 @@ impl TraceStore { events, index, pod_owners: PodOwnersMap::new_from_parts(lifecycle_data, HashMap::new()), - ..Default::default() }) } @@ -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 { @@ -165,7 +164,7 @@ impl TraceStorable for TraceStore { self.index.remove(&ns_name); } - fn update_all_objs(&mut self, objs: &Vec, 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(); @@ -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, @@ -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 } } } diff --git a/lib/rust/testutils/store.rs b/lib/rust/testutils/store.rs index 5c06904b..239a1f19 100644 --- a/lib/rust/testutils/store.rs +++ b/lib/rust/testutils/store.rs @@ -14,7 +14,7 @@ mock! { impl TraceStorable for TraceStore { fn create_or_update_obj(&mut self, obj: &DynamicObject, ts: i64, maybe_old_hash: Option); fn delete_obj(&mut self, obj: &DynamicObject, ts: i64); - fn update_all_objs(&mut self, objs: &Vec, 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,