Skip to content

Commit

Permalink
Assorted clippy fixes (#1043)
Browse files Browse the repository at this point in the history
* clippy: blacklisted-names is deprecated in favor of disallowed-names

Signed-off-by: Cyril Plisko <cyril.plisko@mountall.com>

* clippy::needless_borrow

Signed-off-by: Cyril Plisko <cyril.plisko@mountall.com>

* clippy::needless_lifetimes

Signed-off-by: Cyril Plisko <cyril.plisko@mountall.com>

* clippy::redundant_clone

Signed-off-by: Cyril Plisko <cyril.plisko@mountall.com>

* clippy::explicit_auto_deref

Signed-off-by: Cyril Plisko <cyril.plisko@mountall.com>

* clippy::iter_kv_map

Signed-off-by: Cyril Plisko <cyril.plisko@mountall.com>

* clippy::bool_assert_comparison

Signed-off-by: Cyril Plisko <cyril.plisko@mountall.com>

* clippy::derive_partial_eq_without_eq

Signed-off-by: Cyril Plisko <cyril.plisko@mountall.com>

Signed-off-by: Cyril Plisko <cyril.plisko@mountall.com>
  • Loading branch information
imp committed Oct 5, 2022
1 parent d6b33ce commit a26e7f3
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion clippy.toml
@@ -1 +1 @@
blacklisted-names = []
disallowed-names = []
2 changes: 1 addition & 1 deletion examples/crd_derive.rs
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
/// Our spec for Foo
///
/// A struct with our chosen Kind will be created for us, using the following kube attrs
#[derive(CustomResource, Serialize, Deserialize, Default, Debug, PartialEq, Clone, JsonSchema)]
#[derive(CustomResource, Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, JsonSchema)]
#[kube(
group = "clux.dev",
version = "v1",
Expand Down
2 changes: 1 addition & 1 deletion examples/crd_derive_schema.rs
Expand Up @@ -19,7 +19,7 @@ use serde::{Deserialize, Serialize};
// - https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#defaulting
// - https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#defaulting-and-nullable

#[derive(CustomResource, Serialize, Deserialize, Default, Debug, PartialEq, Clone, JsonSchema)]
#[derive(CustomResource, Serialize, Deserialize, Default, Debug, PartialEq, Eq, Clone, JsonSchema)]
#[kube(
group = "clux.dev",
version = "v1",
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_client_trace.rs
Expand Up @@ -42,9 +42,9 @@ async fn main() -> anyhow::Result<()> {
})
.on_response(|response: &Response<Body>, latency: Duration, span: &Span| {
let status = response.status();
span.record("http.status_code", &status.as_u16());
span.record("http.status_code", status.as_u16());
if status.is_client_error() || status.is_server_error() {
span.record("otel.status_code", &"ERROR");
span.record("otel.status_code", "ERROR");
}
tracing::debug!("finished in {}ms", latency.as_millis())
}),
Expand Down
4 changes: 2 additions & 2 deletions examples/dynamic_jsonpath.rs
Expand Up @@ -20,12 +20,12 @@ async fn main() -> anyhow::Result<()> {
);

let pods: Api<Pod> = Api::<Pod>::all(client);
let list_params = ListParams::default().fields(&*field_selector);
let list_params = ListParams::default().fields(&field_selector);
let list = pods.list(&list_params).await?;

// Use the given JSONPATH to filter the ObjectList
let list_json = serde_json::to_value(&list)?;
let res = jsonpath_lib::select(&list_json, &*jsonpath).unwrap();
let res = jsonpath_lib::select(&list_json, &jsonpath).unwrap();
info!("\t\t {:?}", res);
Ok(())
}
2 changes: 1 addition & 1 deletion examples/pod_cp.rs
Expand Up @@ -58,7 +58,7 @@ async fn main() -> anyhow::Result<()> {
// Write the data to pod
{
let mut header = tar::Header::new_gnu();
header.set_path(&file_name).unwrap();
header.set_path(file_name).unwrap();
header.set_size(data.len() as u64);
header.set_cksum();

Expand Down
2 changes: 1 addition & 1 deletion kube-client/src/api/mod.rs
Expand Up @@ -254,6 +254,6 @@ mod test {
let _: Api<corev1::Node> = Api::all(client.clone());
let _: Api<corev1::Pod> = Api::default_namespaced(client.clone());
let _: Api<corev1::PersistentVolume> = Api::all(client.clone());
let _: Api<corev1::ConfigMap> = Api::namespaced(client.clone(), "default");
let _: Api<corev1::ConfigMap> = Api::namespaced(client, "default");
}
}
8 changes: 4 additions & 4 deletions kube-client/src/client/builder.rs
Expand Up @@ -143,9 +143,9 @@ impl TryFrom<Config> for ClientBuilder<BoxService<Request<hyper::Body>, Response
})
.on_response(|res: &Response<hyper::Body>, _latency: Duration, span: &Span| {
let status = res.status();
span.record("http.status_code", &status.as_u16());
span.record("http.status_code", status.as_u16());
if status.is_client_error() || status.is_server_error() {
span.record("otel.status_code", &"ERROR");
span.record("otel.status_code", "ERROR");
}
})
// Explicitly disable `on_body_chunk`. The default does nothing.
Expand All @@ -159,10 +159,10 @@ impl TryFrom<Config> for ClientBuilder<BoxService<Request<hyper::Body>, Response
// - Polling `Body` errored
// - the response was classified as failure (5xx)
// - End of stream was classified as failure
span.record("otel.status_code", &"ERROR");
span.record("otel.status_code", "ERROR");
match ec {
ServerErrorsFailureClass::StatusCode(status) => {
span.record("http.status_code", &status.as_u16());
span.record("http.status_code", status.as_u16());
tracing::error!("failed with status {}", status)
}
ServerErrorsFailureClass::Error(err) => {
Expand Down
18 changes: 9 additions & 9 deletions kube-client/src/config/file_config.rs
Expand Up @@ -51,7 +51,7 @@ pub struct Kubeconfig {

/// Preferences stores extensions for cli.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct Preferences {
/// Enable colors
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -63,7 +63,7 @@ pub struct Preferences {

/// NamedExtention associates name with extension.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct NamedExtension {
/// Name of extension
pub name: String,
Expand All @@ -73,7 +73,7 @@ pub struct NamedExtension {

/// NamedCluster associates name with cluster.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct NamedCluster {
/// Name of cluster
pub name: String,
Expand All @@ -83,7 +83,7 @@ pub struct NamedCluster {

/// Cluster stores information to connect Kubernetes cluster.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct Cluster {
/// The address of the kubernetes cluster (https://hostname:port).
pub server: String,
Expand Down Expand Up @@ -209,13 +209,13 @@ pub struct AuthInfo {
#[cfg(test)]
impl PartialEq for AuthInfo {
fn eq(&self, other: &Self) -> bool {
serde_json::to_value(&self).unwrap() == serde_json::to_value(&other).unwrap()
serde_json::to_value(self).unwrap() == serde_json::to_value(other).unwrap()
}
}

/// AuthProviderConfig stores auth for specified cloud provider.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct AuthProviderConfig {
/// Name of the auth provider
pub name: String,
Expand All @@ -225,7 +225,7 @@ pub struct AuthProviderConfig {

/// ExecConfig stores credential-plugin configuration.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct ExecConfig {
/// Preferred input version of the ExecInfo.
///
Expand All @@ -247,7 +247,7 @@ pub struct ExecConfig {

/// NamedContext associates name with context.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct NamedContext {
/// Name of the context
pub name: String,
Expand All @@ -257,7 +257,7 @@ pub struct NamedContext {

/// Context stores tuple of cluster and user information.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub struct Context {
/// Name of the cluster for this context
pub cluster: String,
Expand Down
10 changes: 5 additions & 5 deletions kube-client/src/discovery/apigroup.rs
Expand Up @@ -275,8 +275,8 @@ impl ApiGroup {
})
});
lookup
.into_iter()
.map(|(_, mut v)| {
.into_values()
.map(|mut v| {
v.sort_by_cached_key(|(ar, _)| Reverse(Version::parse(ar.version.as_str()).priority()));
v[0].to_owned()
})
Expand Down Expand Up @@ -353,15 +353,15 @@ mod tests {
data: vec![
GroupVersionData {
version: "v1alpha1".to_string(),
resources: vec![(testlowversioncr_v1alpha1.clone(), ac.clone())],
resources: vec![(testlowversioncr_v1alpha1, ac.clone())],
},
GroupVersionData {
version: "v1".to_string(),
resources: vec![(testcr_v1.clone(), ac.clone())],
resources: vec![(testcr_v1, ac.clone())],
},
GroupVersionData {
version: "v2alpha1".to_string(),
resources: vec![(testcr_v2alpha1.clone(), ac.clone())],
resources: vec![(testcr_v2alpha1, ac)],
},
],
preferred: Some(String::from("v1")),
Expand Down
2 changes: 1 addition & 1 deletion kube-core/src/admission.rs
Expand Up @@ -234,7 +234,7 @@ pub enum Operation {
/// .into_review();
///
/// ```
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct AdmissionResponse {
Expand Down
4 changes: 2 additions & 2 deletions kube-core/src/object.rs
Expand Up @@ -47,7 +47,7 @@ impl<T: Clone> ObjectList<T> {
/// let first = objectlist.iter().next();
/// println!("First element: {:?}", first); // prints "First element: Some(1)"
/// ```
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &T> + 'a {
pub fn iter(&self) -> impl Iterator<Item = &T> {
self.items.iter()
}

Expand All @@ -70,7 +70,7 @@ impl<T: Clone> ObjectList<T> {
/// println!("First element: {:?}", elem); // prints "First element: 2"
/// }

pub fn iter_mut<'a>(&'a mut self) -> impl Iterator<Item = &mut T> + 'a {
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
self.items.iter_mut()
}
}
Expand Down
6 changes: 3 additions & 3 deletions kube-core/src/response.rs
Expand Up @@ -2,7 +2,7 @@
use serde::{Deserialize, Serialize};

/// A Kubernetes status object
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)]
pub struct Status {
/// Status of the operation
///
Expand Down Expand Up @@ -95,7 +95,7 @@ pub enum StatusSummary {
}

/// Status details object on the [`Status`] object
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct StatusDetails {
/// The name attribute of the resource associated with the status StatusReason (when there is a single name which can be described)
Expand Down Expand Up @@ -133,7 +133,7 @@ pub struct StatusDetails {
}

/// Status cause object on the [`StatusDetails`] object
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct StatusCause {
/// A machine-readable description of the cause of the error. If this value is empty there is no information available.
#[serde(default, skip_serializing_if = "String::is_empty")]
Expand Down
2 changes: 1 addition & 1 deletion kube-derive/src/custom_resource.rs
Expand Up @@ -608,6 +608,6 @@ mod tests {
assert_eq!(kube_attrs.group, "clux.dev".to_string());
assert_eq!(kube_attrs.version, "v1".to_string());
assert_eq!(kube_attrs.kind, "Foo".to_string());
assert_eq!(kube_attrs.namespaced, true);
assert!(kube_attrs.namespaced);
}
}

0 comments on commit a26e7f3

Please sign in to comment.