diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 230078a83..5e5de67c8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -33,4 +33,4 @@ jobs: - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt - - run: rustfmt +nightly --edition 2021 --check $(find . -type f -iname *.rs) + - run: rustfmt +nightly --edition 2024 --check $(find . -type f -iname *.rs) diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml index 4e2f14e1d..5a6865118 100644 --- a/.github/workflows/rustfmt.yml +++ b/.github/workflows/rustfmt.yml @@ -17,7 +17,7 @@ jobs: - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt - - run: rustfmt +nightly --edition 2021 $(find . -type f -iname *.rs) + - run: rustfmt +nightly --edition 2024 $(find . -type f -iname *.rs) - name: Create Pull Request uses: peter-evans/create-pull-request@v7 with: @@ -25,7 +25,7 @@ jobs: signoff: true title: rustfmt body: | - Changes from `rustfmt +nightly --edition 2021 $(find . -type f -iname *.rs)`. + Changes from `rustfmt +nightly --edition 2024 $(find . -type f -iname *.rs)`. branch: rustfmt # Delete branch when merged delete-branch: true diff --git a/e2e/job.rs b/e2e/job.rs index 6e980217e..f08e166a7 100644 --- a/e2e/job.rs +++ b/e2e/job.rs @@ -1,8 +1,8 @@ use k8s_openapi::api::batch::v1::Job; use kube::{ + Client, api::{Api, DeleteParams, PostParams}, runtime::wait::{await_condition, conditions}, - Client, }; use tracing::info; diff --git a/examples/admission_controller.rs b/examples/admission_controller.rs index 8789ac702..96f12abb1 100644 --- a/examples/admission_controller.rs +++ b/examples/admission_controller.rs @@ -1,11 +1,11 @@ use json_patch::jsonptr::PointerBuf; use kube::core::{ - admission::{AdmissionRequest, AdmissionResponse, AdmissionReview}, DynamicObject, Resource, ResourceExt, + admission::{AdmissionRequest, AdmissionResponse, AdmissionReview}, }; use std::{convert::Infallible, error::Error}; use tracing::*; -use warp::{reply, Filter, Reply}; +use warp::{Filter, Reply, reply}; #[tokio::main] async fn main() { diff --git a/examples/cert_check.rs b/examples/cert_check.rs index 99295d225..fdb59b740 100644 --- a/examples/cert_check.rs +++ b/examples/cert_check.rs @@ -1,13 +1,13 @@ use std::borrow::Cow; use k8s_openapi::{ - api::core::v1::{ConfigMap, Namespace as Ns}, NamespaceResourceScope, + api::core::v1::{ConfigMap, Namespace as Ns}, }; use kube::{ + Client, Resource, api::ObjectMeta, client::scope::{Cluster, Namespace}, - Client, Resource, }; use serde::{Deserialize, Serialize}; use tracing::*; diff --git a/examples/configmapgen_controller.rs b/examples/configmapgen_controller.rs index 41b1ad1e4..18e9f96bc 100644 --- a/examples/configmapgen_controller.rs +++ b/examples/configmapgen_controller.rs @@ -5,12 +5,12 @@ use anyhow::Result; use futures::StreamExt; use k8s_openapi::api::core::v1::ConfigMap; use kube::{ + Client, CustomResource, api::{Api, ObjectMeta, Patch, PatchParams, Resource}, runtime::{ controller::{Action, Config, Controller}, watcher, }, - Client, CustomResource, }; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; diff --git a/examples/crd_api.rs b/examples/crd_api.rs index d0123b28b..bf4ffdccd 100644 --- a/examples/crd_api.rs +++ b/examples/crd_api.rs @@ -1,4 +1,4 @@ -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use either::Either::{Left, Right}; use garde::Validate; use schemars::JsonSchema; @@ -10,9 +10,9 @@ use tracing::*; use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition; use kube::{ + Client, CustomResource, api::{Api, DeleteParams, ListParams, Patch, PatchParams, PostParams, ResourceExt}, core::crd::CustomResourceExt, - Client, CustomResource, }; // Own custom resource @@ -212,9 +212,10 @@ async fn main() -> Result<()> { match foos.create(&pp, &fx).await { Err(kube::Error::Api(ae)) => { assert_eq!(ae.code, 422); - assert!(ae - .message - .contains("spec.name in body should be at least 3 chars long")); + assert!( + ae.message + .contains("spec.name in body should be at least 3 chars long") + ); } Err(e) => bail!("somehow got unexpected error from validation: {:?}", e), Ok(o) => bail!("somehow created {:?} despite validation", o), diff --git a/examples/crd_apply.rs b/examples/crd_apply.rs index eae7d49fe..40a417f55 100644 --- a/examples/crd_apply.rs +++ b/examples/crd_apply.rs @@ -8,9 +8,9 @@ use apiexts::CustomResourceDefinition; use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1 as apiexts; use kube::{ + Client, CustomResource, CustomResourceExt, api::{Api, Patch, PatchParams, ResourceExt}, runtime::wait::{await_condition, conditions}, - Client, CustomResource, CustomResourceExt, }; /// Spec object for Foo diff --git a/examples/crd_derive.rs b/examples/crd_derive.rs index be7eb9d33..125f6b810 100644 --- a/examples/crd_derive.rs +++ b/examples/crd_derive.rs @@ -1,7 +1,7 @@ use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition; use kube::{ - core::object::{HasSpec, HasStatus}, CustomResource, CustomResourceExt, Resource, + core::object::{HasSpec, HasStatus}, }; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; diff --git a/examples/crd_derive_custom_schema.rs b/examples/crd_derive_custom_schema.rs index 4fcf95ac3..795d1f7fd 100644 --- a/examples/crd_derive_custom_schema.rs +++ b/examples/crd_derive_custom_schema.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use kube::CustomResourceExt; use kube_derive::CustomResource; -use schemars::{json_schema, JsonSchema}; +use schemars::{JsonSchema, json_schema}; use serde::{Deserialize, Serialize}; /// CustomResource with manually implemented `JsonSchema` diff --git a/examples/crd_derive_multi.rs b/examples/crd_derive_multi.rs index 12ff7986e..1fc03d903 100644 --- a/examples/crd_derive_multi.rs +++ b/examples/crd_derive_multi.rs @@ -1,9 +1,9 @@ use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition; use kube::{ + Client, CustomResource, CustomResourceExt, ResourceExt, api::{Api, Patch, PatchParams}, core::crd::merge_crds, runtime::wait::{await_condition, conditions}, - Client, CustomResource, CustomResourceExt, ResourceExt, }; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -108,7 +108,7 @@ async fn main() -> anyhow::Result<()> { .await .unwrap_err(); info!("cannot get old on v1 anymore: {:?}", v1err); // mandatory field oldprop truncated - // ...but the change is still there: + // ...but the change is still there: let old_still_there = v2api.get("old").await?; assert_eq!(old_still_there.spec.name, "i am old2"); diff --git a/examples/crd_derive_schema.rs b/examples/crd_derive_schema.rs index e10903f1c..2403ae80b 100644 --- a/examples/crd_derive_schema.rs +++ b/examples/crd_derive_schema.rs @@ -1,13 +1,13 @@ -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use futures::{StreamExt, TryStreamExt}; use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition; use kube::{ + Client, CustomResource, CustomResourceExt, KubeSchema, api::{ Api, ApiResource, DeleteParams, DynamicObject, GroupVersionKind, Patch, PatchParams, PostParams, WatchEvent, WatchParams, }, runtime::wait::{await_condition, conditions}, - Client, CustomResource, CustomResourceExt, KubeSchema, }; use serde::{Deserialize, Serialize}; diff --git a/examples/crd_reflector.rs b/examples/crd_reflector.rs index f01fb9165..3cef4620b 100644 --- a/examples/crd_reflector.rs +++ b/examples/crd_reflector.rs @@ -3,9 +3,9 @@ use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomRe use tracing::*; use kube::{ - api::{Api, Patch, PatchParams, ResourceExt}, - runtime::{reflector, watcher, WatchStreamExt}, Client, CustomResource, CustomResourceExt, + api::{Api, Patch, PatchParams, ResourceExt}, + runtime::{WatchStreamExt, reflector, watcher}, }; use schemars::JsonSchema; diff --git a/examples/custom_client.rs b/examples/custom_client.rs index 0b61a8810..a1d47c17d 100644 --- a/examples/custom_client.rs +++ b/examples/custom_client.rs @@ -4,7 +4,7 @@ use k8s_openapi::api::core::v1::Pod; use tower::BoxError; use tracing::*; -use kube::{client::ConfigExt, Api, Client, Config, ResourceExt}; +use kube::{Api, Client, Config, ResourceExt, client::ConfigExt}; #[tokio::main] async fn main() -> anyhow::Result<()> { diff --git a/examples/custom_client_tls.rs b/examples/custom_client_tls.rs index 1ecf3077e..e5b2f5e11 100644 --- a/examples/custom_client_tls.rs +++ b/examples/custom_client_tls.rs @@ -6,7 +6,7 @@ use k8s_openapi::api::core::v1::Pod; use tower::{BoxError, ServiceBuilder}; use tracing::*; -use kube::{client::ConfigExt, Api, Client, Config, ResourceExt}; +use kube::{Api, Client, Config, ResourceExt, client::ConfigExt}; #[tokio::main] async fn main() -> anyhow::Result<()> { diff --git a/examples/custom_client_trace.rs b/examples/custom_client_trace.rs index 25cb1aa6c..f6952c44c 100644 --- a/examples/custom_client_trace.rs +++ b/examples/custom_client_trace.rs @@ -9,8 +9,8 @@ use tower_http::{decompression::DecompressionLayer, trace::TraceLayer}; use tracing::{Span, *}; use kube::{ - client::{Body, ConfigExt}, Api, Client, Config, ResourceExt, + client::{Body, ConfigExt}, }; #[tokio::main] diff --git a/examples/dynamic_api.rs b/examples/dynamic_api.rs index 879417528..ca0524507 100644 --- a/examples/dynamic_api.rs +++ b/examples/dynamic_api.rs @@ -1,9 +1,9 @@ //! In this example we will implement something similar to `kubectl get all`. use kube::{ - api::{Api, DynamicObject, ResourceExt}, - discovery::{verbs, Discovery, Scope}, Client, + api::{Api, DynamicObject, ResourceExt}, + discovery::{Discovery, Scope, verbs}, }; use tracing::*; diff --git a/examples/dynamic_jsonpath.rs b/examples/dynamic_jsonpath.rs index bc4b02d48..06f390219 100644 --- a/examples/dynamic_jsonpath.rs +++ b/examples/dynamic_jsonpath.rs @@ -2,8 +2,8 @@ use anyhow::{Context, Error}; use jsonpath_rust::JsonPath; use k8s_openapi::api::core::v1::Pod; use kube::{ - api::{Api, ListParams}, Client, + api::{Api, ListParams}, }; use tracing::*; diff --git a/examples/dynamic_pod.rs b/examples/dynamic_pod.rs index 80d3556be..c357f72c9 100644 --- a/examples/dynamic_pod.rs +++ b/examples/dynamic_pod.rs @@ -1,6 +1,6 @@ use kube::{ - api::{Api, ApiResource, NotUsed, Object, ResourceExt}, Client, + api::{Api, ApiResource, NotUsed, Object, ResourceExt}, }; use serde::Deserialize; use tracing::*; diff --git a/examples/dynamic_watcher.rs b/examples/dynamic_watcher.rs index 9ab6753c6..1f1440772 100644 --- a/examples/dynamic_watcher.rs +++ b/examples/dynamic_watcher.rs @@ -1,7 +1,7 @@ use futures::{Stream, StreamExt, TryStreamExt}; use kube::{ api::{Api, ApiResource, DynamicObject, GroupVersionKind, Resource, ResourceExt}, - runtime::{metadata_watcher, watcher, watcher::Event, WatchStreamExt}, + runtime::{WatchStreamExt, metadata_watcher, watcher, watcher::Event}, }; use serde::de::DeserializeOwned; use tracing::*; diff --git a/examples/errorbounded_configmap_watcher.rs b/examples/errorbounded_configmap_watcher.rs index db9e69830..f4d5ca30a 100644 --- a/examples/errorbounded_configmap_watcher.rs +++ b/examples/errorbounded_configmap_watcher.rs @@ -1,10 +1,10 @@ use futures::prelude::*; use k8s_openapi::api::core::v1::ConfigMap; use kube::{ + Client, Resource, api::{Api, ObjectMeta}, core::DeserializeGuard, - runtime::{reflector::ObjectRef, watcher, WatchStreamExt}, - Client, Resource, + runtime::{WatchStreamExt, reflector::ObjectRef, watcher}, }; use serde::Deserialize; use tracing::*; diff --git a/examples/event_watcher.rs b/examples/event_watcher.rs index dd33229f0..fb556b576 100644 --- a/examples/event_watcher.rs +++ b/examples/event_watcher.rs @@ -7,8 +7,8 @@ use k8s_openapi::{ chrono::Utc, }; use kube::{ - runtime::{watcher, WatchStreamExt}, Api, Client, ResourceExt, + runtime::{WatchStreamExt, watcher}, }; /// limited variant of `kubectl events` that works on current context's namespace diff --git a/examples/job_api.rs b/examples/job_api.rs index 6e980217e..f08e166a7 100644 --- a/examples/job_api.rs +++ b/examples/job_api.rs @@ -1,8 +1,8 @@ use k8s_openapi::api::batch::v1::Job; use kube::{ + Client, api::{Api, DeleteParams, PostParams}, runtime::wait::{await_condition, conditions}, - Client, }; use tracing::info; diff --git a/examples/kubectl.rs b/examples/kubectl.rs index bcb342881..efc7819b6 100644 --- a/examples/kubectl.rs +++ b/examples/kubectl.rs @@ -1,19 +1,20 @@ //! This is a simple imitation of the basic functionality of kubectl: //! kubectl {get, delete, apply, watch, edit} [name] //! with labels and namespace selectors supported. -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use futures::{StreamExt, TryStreamExt}; use k8s_openapi::{apimachinery::pkg::apis::meta::v1::Time, chrono::Utc}; use kube::{ + Client, api::{Api, DynamicObject, ListParams, Patch, PatchParams, ResourceExt}, config::KubeConfigOptions, core::GroupVersionKind, discovery::{ApiCapabilities, ApiResource, Discovery, Scope}, runtime::{ + WatchStreamExt, wait::{await_condition, conditions::is_deleted}, - watcher, WatchStreamExt, + watcher, }, - Client, }; use tracing::*; diff --git a/examples/log_stream.rs b/examples/log_stream.rs index d78047202..928bedcb2 100644 --- a/examples/log_stream.rs +++ b/examples/log_stream.rs @@ -4,8 +4,8 @@ use k8s_openapi::{ chrono::{DateTime, Utc}, }; use kube::{ - api::{Api, LogParams}, Client, + api::{Api, LogParams}, }; use tracing::*; diff --git a/examples/multi_watcher.rs b/examples/multi_watcher.rs index 9311a24ae..4b6a4f4bd 100644 --- a/examples/multi_watcher.rs +++ b/examples/multi_watcher.rs @@ -1,12 +1,12 @@ -use futures::{stream, StreamExt, TryStreamExt}; +use futures::{StreamExt, TryStreamExt, stream}; use k8s_openapi::api::{ apps::v1::Deployment, core::v1::{ConfigMap, Secret}, }; use kube::{ - api::{Api, ResourceExt}, - runtime::{watcher, WatchStreamExt}, Client, + api::{Api, ResourceExt}, + runtime::{WatchStreamExt, watcher}, }; use tracing::*; diff --git a/examples/node_reflector.rs b/examples/node_reflector.rs index 6859d8749..a101b81ae 100644 --- a/examples/node_reflector.rs +++ b/examples/node_reflector.rs @@ -3,9 +3,9 @@ use std::pin::pin; use futures::TryStreamExt; use k8s_openapi::api::core::v1::Node; use kube::{ - api::{Api, ResourceExt}, - runtime::{predicates, reflector, watcher, Predicate, WatchStreamExt}, Client, + api::{Api, ResourceExt}, + runtime::{Predicate, WatchStreamExt, predicates, reflector, watcher}, }; use tracing::*; diff --git a/examples/node_watcher.rs b/examples/node_watcher.rs index 4ed4c0d2e..d43bc616e 100644 --- a/examples/node_watcher.rs +++ b/examples/node_watcher.rs @@ -4,8 +4,8 @@ use futures::TryStreamExt; use k8s_openapi::api::core::v1::{Event, Node}; use kube::{ api::{Api, ListParams, ResourceExt}, - client::{scope, Client}, - runtime::{watcher, WatchStreamExt}, + client::{Client, scope}, + runtime::{WatchStreamExt, watcher}, }; use tracing::*; diff --git a/examples/pod_api.rs b/examples/pod_api.rs index b7c3db67e..4b3564d00 100644 --- a/examples/pod_api.rs +++ b/examples/pod_api.rs @@ -3,9 +3,9 @@ use serde_json::json; use tracing::*; use kube::{ + Client, api::{Api, DeleteParams, ListParams, Patch, PatchParams, PostParams, ResourceExt}, runtime::wait::{await_condition, conditions::is_pod_running}, - Client, }; #[tokio::main] diff --git a/examples/pod_attach.rs b/examples/pod_attach.rs index cb23b52d4..a08d4f632 100644 --- a/examples/pod_attach.rs +++ b/examples/pod_attach.rs @@ -1,14 +1,14 @@ use std::io::Write; use tracing::*; -use futures::{join, stream, StreamExt, TryStreamExt}; +use futures::{StreamExt, TryStreamExt, join, stream}; use k8s_openapi::api::core::v1::Pod; use kube::{ + Client, api::{ Api, AttachParams, AttachedProcess, DeleteParams, PostParams, ResourceExt, WatchEvent, WatchParams, }, - Client, }; #[tokio::main] diff --git a/examples/pod_cp.rs b/examples/pod_cp.rs index ee3bed75e..5cb3c65f3 100644 --- a/examples/pod_cp.rs +++ b/examples/pod_cp.rs @@ -3,8 +3,8 @@ use k8s_openapi::api::core::v1::Pod; use tracing::*; use kube::{ - api::{Api, AttachParams, DeleteParams, PostParams, ResourceExt, WatchEvent, WatchParams}, Client, + api::{Api, AttachParams, DeleteParams, PostParams, ResourceExt, WatchEvent, WatchParams}, }; use tokio::io::AsyncWriteExt; diff --git a/examples/pod_evict.rs b/examples/pod_evict.rs index 02be47fc1..0f2bdc454 100644 --- a/examples/pod_evict.rs +++ b/examples/pod_evict.rs @@ -4,8 +4,8 @@ use serde_json::json; use tracing::*; use kube::{ - api::{Api, EvictParams, PostParams, ResourceExt, WatchEvent, WatchParams}, Client, + api::{Api, EvictParams, PostParams, ResourceExt, WatchEvent, WatchParams}, }; #[tokio::main] diff --git a/examples/pod_exec.rs b/examples/pod_exec.rs index a671cbb01..90188a3ce 100644 --- a/examples/pod_exec.rs +++ b/examples/pod_exec.rs @@ -3,10 +3,10 @@ use k8s_openapi::api::core::v1::Pod; use tracing::*; use kube::{ + Client, api::{ Api, AttachParams, AttachedProcess, DeleteParams, PostParams, ResourceExt, WatchEvent, WatchParams, }, - Client, }; use tokio::io::AsyncWriteExt; diff --git a/examples/pod_log_kubelet_debug.rs b/examples/pod_log_kubelet_debug.rs index 3925dabb9..6928634ca 100644 --- a/examples/pod_log_kubelet_debug.rs +++ b/examples/pod_log_kubelet_debug.rs @@ -5,9 +5,9 @@ use tracing::*; use futures::AsyncBufReadExt; use hyper::Uri; use kube::{ + Client, Config, api::{Api, DeleteParams, ResourceExt}, core::{kubelet_debug::KubeletDebugParams, subresource::LogParams}, - Client, Config, }; use serde_json::json; diff --git a/examples/pod_paged.rs b/examples/pod_paged.rs index 1f5107ac2..e2893115b 100644 --- a/examples/pod_paged.rs +++ b/examples/pod_paged.rs @@ -1,7 +1,7 @@ use k8s_openapi::api::core::v1::Pod; use kube::{ - api::{Api, ListParams, ResourceExt}, Client, + api::{Api, ListParams, ResourceExt}, }; use tracing::*; diff --git a/examples/pod_portforward.rs b/examples/pod_portforward.rs index c4e751ce8..4d94bb36f 100644 --- a/examples/pod_portforward.rs +++ b/examples/pod_portforward.rs @@ -3,9 +3,9 @@ use k8s_openapi::api::core::v1::Pod; use tracing::*; use kube::{ + Client, ResourceExt, api::{Api, DeleteParams, PostParams}, runtime::wait::{await_condition, conditions::is_pod_running}, - Client, ResourceExt, }; use tokio::io::AsyncWriteExt; diff --git a/examples/pod_portforward_bind.rs b/examples/pod_portforward_bind.rs index e950a14d9..12cbf2128 100644 --- a/examples/pod_portforward_bind.rs +++ b/examples/pod_portforward_bind.rs @@ -12,9 +12,9 @@ use tracing::*; use k8s_openapi::api::core::v1::Pod; use kube::{ + Client, ResourceExt, api::{Api, DeleteParams, PostParams}, runtime::wait::{await_condition, conditions::is_pod_running}, - Client, ResourceExt, }; #[tokio::main] diff --git a/examples/pod_portforward_hyper_http.rs b/examples/pod_portforward_hyper_http.rs index 64cf9aa1f..b831c087d 100644 --- a/examples/pod_portforward_hyper_http.rs +++ b/examples/pod_portforward_hyper_http.rs @@ -2,9 +2,9 @@ use bytes::Bytes; use hyper_util::rt::TokioIo; use k8s_openapi::api::core::v1::Pod; use kube::{ + Client, ResourceExt, api::{Api, DeleteParams, PostParams}, runtime::wait::{await_condition, conditions::is_pod_running}, - Client, ResourceExt, }; use tracing::*; diff --git a/examples/pod_reflector.rs b/examples/pod_reflector.rs index 21a564c56..bff24137b 100644 --- a/examples/pod_reflector.rs +++ b/examples/pod_reflector.rs @@ -3,9 +3,9 @@ use std::pin::pin; use futures::TryStreamExt; use k8s_openapi::api::core::v1::Pod; use kube::{ - api::Api, - runtime::{predicates, reflector, watcher, WatchStreamExt}, Client, ResourceExt, + api::Api, + runtime::{WatchStreamExt, predicates, reflector, watcher}, }; use tracing::*; diff --git a/examples/pod_shell.rs b/examples/pod_shell.rs index 3f7a3e79a..df5cad2fd 100644 --- a/examples/pod_shell.rs +++ b/examples/pod_shell.rs @@ -3,8 +3,8 @@ use k8s_openapi::api::core::v1::Pod; use tracing::*; use kube::{ - api::{Api, AttachParams, DeleteParams, PostParams, ResourceExt, WatchEvent, WatchParams}, Client, + api::{Api, AttachParams, DeleteParams, PostParams, ResourceExt, WatchEvent, WatchParams}, }; #[tokio::main] diff --git a/examples/pod_shell_crossterm.rs b/examples/pod_shell_crossterm.rs index 4283603db..2cc14da40 100644 --- a/examples/pod_shell_crossterm.rs +++ b/examples/pod_shell_crossterm.rs @@ -1,10 +1,10 @@ -use futures::{channel::mpsc::Sender, SinkExt, StreamExt}; +use futures::{SinkExt, StreamExt, channel::mpsc::Sender}; use k8s_openapi::api::core::v1::Pod; use kube::{ + Client, api::{Api, AttachParams, AttachedProcess, DeleteParams, PostParams, ResourceExt, TerminalSize}, runtime::wait::{await_condition, conditions::is_pod_running}, - Client, }; #[cfg(unix)] use tokio::signal; use tokio::{io::AsyncWriteExt, select}; diff --git a/examples/pod_watcher.rs b/examples/pod_watcher.rs index 7a1f2dcc0..af7ea087c 100644 --- a/examples/pod_watcher.rs +++ b/examples/pod_watcher.rs @@ -1,9 +1,9 @@ use futures::prelude::*; use k8s_openapi::api::core::v1::Pod; use kube::{ - api::{Api, ResourceExt}, - runtime::{watcher, WatchStreamExt}, Client, + api::{Api, ResourceExt}, + runtime::{WatchStreamExt, watcher}, }; use tracing::*; diff --git a/examples/request_raw.rs b/examples/request_raw.rs index 7a534ff74..b1f39873c 100644 --- a/examples/request_raw.rs +++ b/examples/request_raw.rs @@ -7,7 +7,7 @@ //! kubelet. The kubelet itself supports statistics access through CRI, or //! through cAdvisor. use k8s_openapi::{api::core::v1::Node, apimachinery::pkg::api::resource::Quantity}; -use kube::{api::ListParams, Api, ResourceExt}; +use kube::{Api, ResourceExt, api::ListParams}; use serde::Deserialize; #[tokio::main] @@ -111,8 +111,8 @@ fn print_table(summaries: Vec) { }; println!( - "{NAME:w_name$} {USED_MEM:w_used_mem$} {PERCENT_MEM:w_percent_mem$} {USED_CPU:w_used_cpu$} {PERCENT_CPU:w_percent_cpu$}" - ); + "{NAME:w_name$} {USED_MEM:w_used_mem$} {PERCENT_MEM:w_percent_mem$} {USED_CPU:w_used_cpu$} {PERCENT_CPU:w_percent_cpu$}" + ); for summary in summaries { // Get Node memory allocatable and trim measurement suffix. let mem_total = summary @@ -136,7 +136,9 @@ fn print_table(summaries: Vec) { let (percent_mem, used_mem) = summary.metrics.memory.convert_to_stat(mem_total); let (percent_cpu, used_cpu) = summary.metrics.cpu.convert_to_stat(cpu_total); - println!("{name:w_name$} {used_mem: Api { /// Gets a given object's "slot" on the Kubernetes API, designed for "get-or-create" and "get-and-modify" patterns @@ -260,7 +260,9 @@ pub enum CommitError { /// Pre-commit validation errors pub enum CommitValidationError { /// `ObjectMeta::name` does not match the name passed to [`Api::entry`] - #[error(".metadata.name does not match the name passed to Api::entry (got: {object_name:?}, expected: {expected:?})")] + #[error( + ".metadata.name does not match the name passed to Api::entry (got: {object_name:?}, expected: {expected:?})" + )] NameMismatch { /// The name of the object (`ObjectMeta::name`) object_name: String, @@ -268,7 +270,9 @@ pub enum CommitValidationError { expected: String, }, /// `ObjectMeta::namespace` does not match the namespace of the [`Api`] - #[error(".metadata.namespace does not match the namespace of the Api (got: {object_namespace:?}, expected: {expected:?})")] + #[error( + ".metadata.namespace does not match the namespace of the Api (got: {object_namespace:?}, expected: {expected:?})" + )] NamespaceMismatch { /// The name of the object (`ObjectMeta::namespace`) object_namespace: Option, @@ -316,13 +320,13 @@ mod tests { use k8s_openapi::api::core::v1::ConfigMap; use kube_core::{ - params::{DeleteParams, PostParams}, ErrorResponse, ObjectMeta, + params::{DeleteParams, PostParams}, }; use crate::{ - api::entry::{CommitError, Entry}, Api, Client, Error, + api::entry::{CommitError, Entry}, }; #[tokio::test] diff --git a/kube-client/src/api/mod.rs b/kube-client/src/api/mod.rs index bb659d80f..b1c7d7cc5 100644 --- a/kube-client/src/api/mod.rs +++ b/kube-client/src/api/mod.rs @@ -23,16 +23,16 @@ pub mod entry; #[cfg_attr(docsrs, doc(cfg(feature = "admission")))] pub use kube_core::admission; pub(crate) use kube_core::params; +use kube_core::{DynamicResourceScope, NamespaceResourceScope}; pub use kube_core::{ + Resource, ResourceExt, dynamic::{ApiResource, DynamicObject}, gvk::{GroupVersionKind, GroupVersionResource}, metadata::{ListMeta, ObjectMeta, PartialObjectMeta, PartialObjectMetaExt, TypeMeta}, object::{NotUsed, Object, ObjectList}, request::Request, watch::WatchEvent, - Resource, ResourceExt, }; -use kube_core::{DynamicResourceScope, NamespaceResourceScope}; pub use params::{ DeleteParams, GetParams, ListParams, Patch, PatchParams, PostParams, Preconditions, PropagationPolicy, ValidationDirective, VersionMatch, WatchParams, @@ -252,7 +252,7 @@ impl Debug for Api { /// Sanity test on scope restrictions #[cfg(test)] mod test { - use crate::{client::Body, Api, Client}; + use crate::{Api, Client, client::Body}; use k8s_openapi::api::core::v1 as corev1; use http::{Request, Response}; diff --git a/kube-client/src/api/portforward.rs b/kube-client/src/api/portforward.rs index 94a740cd3..bffe5568c 100644 --- a/kube-client/src/api/portforward.rs +++ b/kube-client/src/api/portforward.rs @@ -2,12 +2,13 @@ use std::{collections::HashMap, future::Future}; use bytes::{Buf, Bytes}; use futures::{ + FutureExt, SinkExt, StreamExt, channel::{mpsc, oneshot}, - future, FutureExt, SinkExt, StreamExt, + future, }; use thiserror::Error; use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, DuplexStream}; -use tokio_tungstenite::{tungstenite as ws, WebSocketStream}; +use tokio_tungstenite::{WebSocketStream, tungstenite as ws}; use tokio_util::io::ReaderStream; /// Errors from Portforwarder. diff --git a/kube-client/src/api/remote_command.rs b/kube-client/src/api/remote_command.rs index 63e2aea4a..b48f501ba 100644 --- a/kube-client/src/api/remote_command.rs +++ b/kube-client/src/api/remote_command.rs @@ -3,8 +3,8 @@ use std::future::Future; use k8s_openapi::apimachinery::pkg::apis::meta::v1::Status; use futures::{ - channel::{mpsc, oneshot}, FutureExt, SinkExt, StreamExt, + channel::{mpsc, oneshot}, }; use serde::{Deserialize, Serialize}; use thiserror::Error; diff --git a/kube-client/src/api/subresource.rs b/kube-client/src/api/subresource.rs index cc6b2bdf1..374b46371 100644 --- a/kube-client/src/api/subresource.rs +++ b/kube-client/src/api/subresource.rs @@ -1,10 +1,10 @@ use futures::AsyncBufRead; -use serde::{de::DeserializeOwned, Serialize}; +use serde::{Serialize, de::DeserializeOwned}; use std::fmt::Debug; use crate::{ - api::{Api, Patch, PatchParams, PostParams}, Error, Result, + api::{Api, Patch, PatchParams, PostParams}, }; use kube_core::response::Status; diff --git a/kube-client/src/api/util/csr.rs b/kube-client/src/api/util/csr.rs index 279e3946e..8734a5fc4 100644 --- a/kube-client/src/api/util/csr.rs +++ b/kube-client/src/api/util/csr.rs @@ -1,4 +1,4 @@ -use crate::{api::Api, Error, Result}; +use crate::{Error, Result, api::Api}; use k8s_openapi::api::certificates::v1::CertificateSigningRequest; use kube_core::params::{Patch, PatchParams}; diff --git a/kube-client/src/api/util/mod.rs b/kube-client/src/api/util/mod.rs index 06923a0d6..49638653d 100644 --- a/kube-client/src/api/util/mod.rs +++ b/kube-client/src/api/util/mod.rs @@ -1,6 +1,6 @@ use crate::{ - api::{Api, Resource}, Error, Result, + api::{Api, Resource}, }; use k8s_openapi::api::{ authentication::v1::TokenRequest, @@ -63,8 +63,8 @@ impl Api { #[cfg(feature = "client")] mod test { use crate::{ - api::{Api, DeleteParams, ListParams, PostParams}, Client, + api::{Api, DeleteParams, ListParams, PostParams}, }; use k8s_openapi::api::{ authentication::v1::{TokenRequest, TokenRequestSpec, TokenReview, TokenReviewSpec}, diff --git a/kube-client/src/client/auth/mod.rs b/kube-client/src/client/auth/mod.rs index 9885ea476..a77abbaa6 100644 --- a/kube-client/src/client/auth/mod.rs +++ b/kube-client/src/client/auth/mod.rs @@ -7,15 +7,15 @@ use std::{ use chrono::{DateTime, Duration, Utc}; use futures::future::BoxFuture; use http::{ - header::{InvalidHeaderValue, AUTHORIZATION}, HeaderValue, Request, + header::{AUTHORIZATION, InvalidHeaderValue}, }; use jsonpath_rust::JsonPath; use secrecy::{ExposeSecret, SecretString}; use serde::{Deserialize, Serialize}; use thiserror::Error; use tokio::sync::{Mutex, RwLock}; -use tower::{filter::AsyncPredicate, BoxError}; +use tower::{BoxError, filter::AsyncPredicate}; use crate::config::{AuthInfo, AuthProviderConfig, ExecAuthCluster, ExecConfig, ExecInteractiveMode}; @@ -356,7 +356,6 @@ impl TryFrom<&AuthInfo> for Auth { .transpose() .map_err(Error::MalformedTokenExpirationDate)?; - if let (Some(client_certificate_data), Some(client_key_data)) = (status.client_certificate_data, status.client_key_data) { @@ -431,14 +430,14 @@ fn token_from_gcp_provider(provider: &AuthProviderConfig) -> Result>() - .map_err(Error::MalformedTokenExpirationDate)?; - if Utc::now() + SIXTY_SEC < expiry_date { - return Ok(ProviderToken::GcpCommand(access_token.clone(), Some(expiry_date))); - } + if let Some(access_token) = provider.config.get("access-token") + && let Some(expiry) = provider.config.get("expiry") + { + let expiry_date = expiry + .parse::>() + .map_err(Error::MalformedTokenExpirationDate)?; + if Utc::now() + SIXTY_SEC < expiry_date { + return Ok(ProviderToken::GcpCommand(access_token.clone(), Some(expiry_date))); } } diff --git a/kube-client/src/client/auth/oauth.rs b/kube-client/src/client/auth/oauth.rs index f0fb0d29b..36971e4b7 100644 --- a/kube-client/src/client/auth/oauth.rs +++ b/kube-client/src/client/auth/oauth.rs @@ -1,8 +1,8 @@ use http_body_util::BodyExt; use hyper_util::rt::TokioExecutor; use tame_oauth::{ - gcp::{TokenOrRequest, TokenProvider, TokenProviderWrapper}, Token, + gcp::{TokenOrRequest, TokenProvider, TokenProviderWrapper}, }; use thiserror::Error; diff --git a/kube-client/src/client/auth/oidc.rs b/kube-client/src/client/auth/oidc.rs index 06a136c6a..7c03aa57c 100644 --- a/kube-client/src/client/auth/oidc.rs +++ b/kube-client/src/client/auth/oidc.rs @@ -4,12 +4,12 @@ use super::TEN_SEC; use chrono::{TimeZone, Utc}; use form_urlencoded::Serializer; use http::{ - header::{HeaderValue, AUTHORIZATION, CONTENT_TYPE}, Method, Request, Uri, Version, + header::{AUTHORIZATION, CONTENT_TYPE, HeaderValue}, }; use http_body_util::BodyExt; use hyper_util::{ - client::legacy::{connect::HttpConnector, Client}, + client::legacy::{Client, connect::HttpConnector}, rt::TokioExecutor, }; use secrecy::{ExposeSecret, SecretString}; @@ -19,7 +19,7 @@ use serde_json::Number; /// Possible errors when handling OIDC authentication. pub mod errors { use super::Oidc; - use http::{uri::InvalidUri, StatusCode}; + use http::{StatusCode, uri::InvalidUri}; use thiserror::Error; /// Possible errors when extracting expiration time from an ID token. diff --git a/kube-client/src/client/body.rs b/kube-client/src/client/body.rs index 5997218d8..ec3947f8e 100644 --- a/kube-client/src/client/body.rs +++ b/kube-client/src/client/body.rs @@ -1,13 +1,13 @@ use std::{ error::Error as StdError, fmt, - pin::{pin, Pin}, + pin::{Pin, pin}, task::{Context, Poll}, }; use bytes::Bytes; use http_body::{Body as HttpBody, Frame, SizeHint}; -use http_body_util::{combinators::UnsyncBoxBody, BodyExt}; +use http_body_util::{BodyExt, combinators::UnsyncBoxBody}; /// A request body. pub struct Body { diff --git a/kube-client/src/client/builder.rs b/kube-client/src/client/builder.rs index e9baa4e8d..2eda93c66 100644 --- a/kube-client/src/client/builder.rs +++ b/kube-client/src/client/builder.rs @@ -1,6 +1,6 @@ use bytes::Bytes; use chrono::{DateTime, Utc}; -use http::{header::HeaderMap, Request, Response}; +use http::{Request, Response, header::HeaderMap}; use hyper::{ body::Incoming, rt::{Read, Write}, @@ -13,14 +13,14 @@ use hyper_util::{ }; use std::time::Duration; -use tower::{util::BoxService, BoxError, Layer, Service, ServiceBuilder}; +use tower::{BoxError, Layer, Service, ServiceBuilder, util::BoxService}; use tower_http::{ classify::ServerErrorsFailureClass, map_response_body::MapResponseBodyLayer, trace::TraceLayer, }; use tracing::Span; use super::body::Body; -use crate::{client::ConfigExt, Client, Config, Error, Result}; +use crate::{Client, Config, Error, Result, client::ConfigExt}; /// HTTP body of a dynamic backing type. /// @@ -279,8 +279,8 @@ mod tests { #[cfg(feature = "gzip")] #[tokio::test] - async fn test_no_accept_encoding_header_sent_when_compression_disabled( - ) -> Result<(), Box> { + async fn test_no_accept_encoding_header_sent_when_compression_disabled() + -> Result<(), Box> { use http::Uri; use std::net::SocketAddr; use tokio::net::{TcpListener, TcpStream}; diff --git a/kube-client/src/client/client_ext.rs b/kube-client/src/client/client_ext.rs index ced2df626..6fd1aa1ca 100644 --- a/kube-client/src/client/client_ext.rs +++ b/kube-client/src/client/client_ext.rs @@ -4,12 +4,12 @@ use k8s_openapi::{ apimachinery::pkg::apis::meta::v1::OwnerReference, }; use kube_core::{ + ApiResource, ClusterResourceScope, DynamicResourceScope, NamespaceResourceScope, Resource, object::ObjectList, params::{GetParams, ListParams}, request::Request, - ApiResource, ClusterResourceScope, DynamicResourceScope, NamespaceResourceScope, Resource, }; -use serde::{de::DeserializeOwned, Serialize}; +use serde::{Serialize, de::DeserializeOwned}; use std::fmt::Debug; /// A marker trait to indicate cluster-wide operations are available @@ -404,11 +404,11 @@ fn url_path(r: &ApiResource, namespace: Option) -> String { #[cfg(test)] mod test { use crate::{ + Client, client::{ client_ext::NamespacedRef as _, scope::{Cluster, Namespace}, }, - Client, }; use super::ListParams; diff --git a/kube-client/src/client/config_ext.rs b/kube-client/src/client/config_ext.rs index ccdb3f600..fb9e96f5b 100644 --- a/kube-client/src/client/config_ext.rs +++ b/kube-client/src/client/config_ext.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use chrono::{DateTime, Utc}; -use http::{header::HeaderName, HeaderValue}; +use http::{HeaderValue, header::HeaderName}; #[cfg(feature = "openssl-tls")] use hyper::rt::{Read, Write}; use hyper_util::client::legacy::connect::HttpConnector; use secrecy::ExposeSecret; @@ -105,7 +105,7 @@ pub trait ConfigExt: private::Sealed { #[cfg_attr(docsrs, doc(cfg(feature = "openssl-tls")))] #[cfg(feature = "openssl-tls")] fn openssl_https_connector(&self) - -> Result>; + -> Result>; /// Create [`hyper_openssl::HttpsConnector`] based on config and `connector`. /// # Example diff --git a/kube-client/src/client/kubelet_debug.rs b/kube-client/src/client/kubelet_debug.rs index 6c0458d98..84d4a2074 100644 --- a/kube-client/src/client/kubelet_debug.rs +++ b/kube-client/src/client/kubelet_debug.rs @@ -1,9 +1,9 @@ use crate::{ + Client, Error, Result, api::{AttachParams, AttachedProcess, LogParams, Portforwarder}, client::AsyncBufRead, - Client, Error, Result, }; -use kube_core::{kubelet_debug::KubeletDebugParams, Request}; +use kube_core::{Request, kubelet_debug::KubeletDebugParams}; use std::fmt::Debug; /// Methods to access debug endpoints directly on `kubelet` diff --git a/kube-client/src/client/middleware/base_uri.rs b/kube-client/src/client/middleware/base_uri.rs index 005cd415c..ef3824a46 100644 --- a/kube-client/src/client/middleware/base_uri.rs +++ b/kube-client/src/client/middleware/base_uri.rs @@ -1,5 +1,5 @@ //! Set base URI of requests. -use http::{uri, Request}; +use http::{Request, uri}; use tower::{Layer, Service}; /// Layer that applies [`BaseUri`] which makes all requests relative to the URI. diff --git a/kube-client/src/client/middleware/extra_headers.rs b/kube-client/src/client/middleware/extra_headers.rs index cf6925eeb..33c368c99 100644 --- a/kube-client/src/client/middleware/extra_headers.rs +++ b/kube-client/src/client/middleware/extra_headers.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use http::{header::HeaderName, request::Request, HeaderValue}; +use http::{HeaderValue, header::HeaderName, request::Request}; use tower::{Layer, Service}; #[derive(Clone)] diff --git a/kube-client/src/client/middleware/mod.rs b/kube-client/src/client/middleware/mod.rs index e6ef1bbe4..7c3ba3a7c 100644 --- a/kube-client/src/client/middleware/mod.rs +++ b/kube-client/src/client/middleware/mod.rs @@ -1,5 +1,5 @@ //! Middleware types returned from `ConfigExt` methods. -use tower::{filter::AsyncFilterLayer, util::Either, Layer}; +use tower::{Layer, filter::AsyncFilterLayer, util::Either}; pub(crate) use tower_http::auth::AddAuthorizationLayer; mod base_uri; @@ -30,7 +30,7 @@ mod tests { use std::{matches, pin::pin, sync::Arc}; use chrono::{Duration, Utc}; - use http::{header::AUTHORIZATION, HeaderValue, Request, Response}; + use http::{HeaderValue, Request, Response, header::AUTHORIZATION}; use secrecy::SecretString; use tokio::sync::Mutex; use tokio_test::assert_ready_ok; diff --git a/kube-client/src/client/mod.rs b/kube-client/src/client/mod.rs index 9f0bfe7b9..7d903ecf2 100644 --- a/kube-client/src/client/mod.rs +++ b/kube-client/src/client/mod.rs @@ -9,7 +9,7 @@ //! retrieve the resources served by the kubernetes API. use chrono::{DateTime, Utc}; use either::{Either, Left, Right}; -use futures::{future::BoxFuture, AsyncBufRead, StreamExt, TryStream, TryStreamExt}; +use futures::{AsyncBufRead, StreamExt, TryStream, TryStreamExt, future::BoxFuture}; use http::{self, Request, Response}; use http_body_util::BodyExt; #[cfg(feature = "ws")] use hyper_util::rt::TokioIo; @@ -18,16 +18,16 @@ pub use kube_core::response::Status; use serde::de::DeserializeOwned; use serde_json::{self, Value}; #[cfg(feature = "ws")] -use tokio_tungstenite::{tungstenite as ws, WebSocketStream}; +use tokio_tungstenite::{WebSocketStream, tungstenite as ws}; use tokio_util::{ codec::{FramedRead, LinesCodec, LinesCodecError}, io::StreamReader, }; -use tower::{buffer::Buffer, util::BoxService, BoxError, Layer, Service, ServiceExt}; +use tower::{BoxError, Layer, Service, ServiceExt, buffer::Buffer, util::BoxService}; use tower_http::map_response_body::MapResponseBodyLayer; pub use self::body::Body; -use crate::{api::WatchEvent, error::ErrorResponse, Config, Error, Result}; +use crate::{Config, Error, Result, api::WatchEvent, error::ErrorResponse}; mod auth; mod body; @@ -523,7 +523,7 @@ impl TryFrom for Client { mod tests { use std::pin::pin; - use crate::{client::Body, Api, Client}; + use crate::{Api, Client, client::Body}; use http::{Request, Response}; use k8s_openapi::api::core::v1::Pod; diff --git a/kube-client/src/client/tls.rs b/kube-client/src/client/tls.rs index c264f5a95..058d5b86b 100644 --- a/kube-client/src/client/tls.rs +++ b/kube-client/src/client/tls.rs @@ -2,10 +2,9 @@ pub mod rustls_tls { use hyper_rustls::ConfigBuilderExt; use rustls::{ - self, + self, ClientConfig, DigitallySignedStruct, client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier}, pki_types::{CertificateDer, InvalidDnsNameError, PrivateKeyDer, ServerName}, - ClientConfig, DigitallySignedStruct, }; use thiserror::Error; diff --git a/kube-client/src/client/upgrade.rs b/kube-client/src/client/upgrade.rs index a9378df6c..4de96c2d3 100644 --- a/kube-client/src/client/upgrade.rs +++ b/kube-client/src/client/upgrade.rs @@ -2,7 +2,7 @@ use http::{self, HeaderValue, Response, StatusCode}; use thiserror::Error; use tokio_tungstenite::tungstenite as ws; -use crate::{client::Body, Error, Result}; +use crate::{Error, Result, client::Body}; #[derive(Debug)] pub enum StreamProtocol { diff --git a/kube-client/src/config/file_config.rs b/kube-client/src/config/file_config.rs index af1ba688e..59104873f 100644 --- a/kube-client/src/config/file_config.rs +++ b/kube-client/src/config/file_config.rs @@ -695,7 +695,7 @@ mod tests { use crate::config::file_loader::ConfigLoader; use super::*; - use serde_json::{json, Value}; + use serde_json::{Value, json}; #[test] fn kubeconfig_merge() { diff --git a/kube-client/src/config/file_loader.rs b/kube-client/src/config/file_loader.rs index 3e18b25d9..6bb5f046d 100644 --- a/kube-client/src/config/file_loader.rs +++ b/kube-client/src/config/file_loader.rs @@ -1,6 +1,6 @@ use super::{ - file_config::{AuthInfo, Cluster, Context, Kubeconfig}, KubeconfigError, + file_config::{AuthInfo, Cluster, Context, Kubeconfig}, }; /// KubeConfigOptions stores options used when loading kubeconfig file. diff --git a/kube-client/src/discovery/apigroup.rs b/kube-client/src/discovery/apigroup.rs index d7a7557a3..dbb9d2b37 100644 --- a/kube-client/src/discovery/apigroup.rs +++ b/kube-client/src/discovery/apigroup.rs @@ -1,10 +1,10 @@ use super::parse::{self, GroupVersionData}; -use crate::{error::DiscoveryError, Client, Error, Result}; +use crate::{Client, Error, Result, error::DiscoveryError}; use k8s_openapi::apimachinery::pkg::apis::meta::v1::{APIGroup, APIVersions}; pub use kube_core::discovery::{ApiCapabilities, ApiResource}; use kube_core::{ - gvk::{GroupVersion, GroupVersionKind, ParseGroupVersionError}, Version, + gvk::{GroupVersion, GroupVersionKind, ParseGroupVersionError}, }; use std::{cmp::Reverse, collections::HashMap, iter::Iterator}; diff --git a/kube-client/src/discovery/mod.rs b/kube-client/src/discovery/mod.rs index 0807e6d30..10478c97c 100644 --- a/kube-client/src/discovery/mod.rs +++ b/kube-client/src/discovery/mod.rs @@ -1,7 +1,7 @@ //! High-level utilities for runtime API discovery. use crate::{Client, Result}; -pub use kube_core::discovery::{verbs, ApiCapabilities, ApiResource, Scope}; +pub use kube_core::discovery::{ApiCapabilities, ApiResource, Scope, verbs}; use kube_core::gvk::GroupVersionKind; use std::collections::HashMap; mod apigroup; diff --git a/kube-client/src/discovery/oneshot.rs b/kube-client/src/discovery/oneshot.rs index 942f013fd..ad952c40b 100644 --- a/kube-client/src/discovery/oneshot.rs +++ b/kube-client/src/discovery/oneshot.rs @@ -12,7 +12,7 @@ //! [`oneshot::pinned_kind`]: crate::discovery::pinned_kind use super::ApiGroup; -use crate::{error::DiscoveryError, Client, Error, Result}; +use crate::{Client, Error, Result, error::DiscoveryError}; use kube_core::{ discovery::{ApiCapabilities, ApiResource}, gvk::{GroupVersion, GroupVersionKind}, diff --git a/kube-client/src/discovery/parse.rs b/kube-client/src/discovery/parse.rs index 39f0ce58a..0bc7919e4 100644 --- a/kube-client/src/discovery/parse.rs +++ b/kube-client/src/discovery/parse.rs @@ -1,5 +1,5 @@ //! Abstractions on top of k8s_openapi::apimachinery::pkg::apis::meta::v1 -use crate::{error::DiscoveryError, Error, Result}; +use crate::{Error, Result, error::DiscoveryError}; use k8s_openapi::apimachinery::pkg::apis::meta::v1::{APIResource, APIResourceList}; use kube_core::{ discovery::{ApiCapabilities, ApiResource, Scope}, diff --git a/kube-client/src/lib.rs b/kube-client/src/lib.rs index 218ba7884..44a8f32ae 100644 --- a/kube-client/src/lib.rs +++ b/kube-client/src/lib.rs @@ -130,9 +130,9 @@ pub use kube_core as core; #[allow(unused_imports)] // varying test imports depending on feature mod test { use crate::{ + Api, Client, Config, ResourceExt, api::{AttachParams, AttachedProcess}, client::ConfigExt, - Api, Client, Config, ResourceExt, }; use futures::{AsyncBufRead, AsyncBufReadExt, StreamExt, TryStreamExt}; use hyper::Uri; diff --git a/kube-core/src/admission.rs b/kube-core/src/admission.rs index f9def073b..a31aebdd0 100644 --- a/kube-core/src/admission.rs +++ b/kube-core/src/admission.rs @@ -6,11 +6,11 @@ //! use crate::{ + Status, dynamic::DynamicObject, gvk::{GroupVersionKind, GroupVersionResource}, metadata::TypeMeta, resource::Resource, - Status, }; use std::collections::HashMap; @@ -353,8 +353,8 @@ mod test { const WEBHOOK_BODY: &str = r#"{"kind":"AdmissionReview","apiVersion":"admission.k8s.io/v1","request":{"uid":"0c9a8d74-9cb7-44dd-b98e-09fd62def2f4","kind":{"group":"","version":"v1","kind":"Pod"},"resource":{"group":"","version":"v1","resource":"pods"},"requestKind":{"group":"","version":"v1","kind":"Pod"},"requestResource":{"group":"","version":"v1","resource":"pods"},"name":"echo-pod","namespace":"colin-coder","operation":"CREATE","userInfo":{"username":"colin@coder.com","groups":["system:authenticated"],"extra":{"iam.gke.io/user-assertion":["REDACTED"],"user-assertion.cloud.google.com":["REDACTED"]}},"object":{"kind":"Pod","apiVersion":"v1","metadata":{"name":"echo-pod","namespace":"colin-coder","creationTimestamp":null,"labels":{"app":"echo-server"},"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Pod\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"echo-server\"},\"name\":\"echo-pod\",\"namespace\":\"colin-coder\"},\"spec\":{\"containers\":[{\"image\":\"jmalloc/echo-server\",\"name\":\"echo-server\",\"ports\":[{\"containerPort\":8080,\"name\":\"http-port\"}]}]}}\n"},"managedFields":[{"manager":"kubectl","operation":"Update","apiVersion":"v1","time":"2021-03-29T23:02:16Z","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"f:kubectl.kubernetes.io/last-applied-configuration":{}},"f:labels":{".":{},"f:app":{}}},"f:spec":{"f:containers":{"k:{\"name\":\"echo-server\"}":{".":{},"f:image":{},"f:imagePullPolicy":{},"f:name":{},"f:ports":{".":{},"k:{\"containerPort\":8080,\"protocol\":\"TCP\"}":{".":{},"f:containerPort":{},"f:name":{},"f:protocol":{}}},"f:resources":{},"f:terminationMessagePath":{},"f:terminationMessagePolicy":{}}},"f:dnsPolicy":{},"f:enableServiceLinks":{},"f:restartPolicy":{},"f:schedulerName":{},"f:securityContext":{},"f:terminationGracePeriodSeconds":{}}}}]},"spec":{"volumes":[{"name":"default-token-rxbqq","secret":{"secretName":"default-token-rxbqq"}}],"containers":[{"name":"echo-server","image":"jmalloc/echo-server","ports":[{"name":"http-port","containerPort":8080,"protocol":"TCP"}],"resources":{},"volumeMounts":[{"name":"default-token-rxbqq","readOnly":true,"mountPath":"/var/run/secrets/kubernetes.io/serviceaccount"}],"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"Always"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","serviceAccountName":"default","serviceAccount":"default","securityContext":{},"schedulerName":"default-scheduler","tolerations":[{"key":"node.kubernetes.io/not-ready","operator":"Exists","effect":"NoExecute","tolerationSeconds":300},{"key":"node.kubernetes.io/unreachable","operator":"Exists","effect":"NoExecute","tolerationSeconds":300}],"priority":0,"enableServiceLinks":true},"status":{}},"oldObject":null,"dryRun":false,"options":{"kind":"CreateOptions","apiVersion":"meta.k8s.io/v1"}}}"#; use crate::{ - admission::{AdmissionResponse, AdmissionReview, ConvertAdmissionReviewError}, DynamicObject, + admission::{AdmissionResponse, AdmissionReview, ConvertAdmissionReviewError}, }; #[test] diff --git a/kube-core/src/crd.rs b/kube-core/src/crd.rs index 376e3d632..113cdd905 100644 --- a/kube-core/src/crd.rs +++ b/kube-core/src/crd.rs @@ -141,7 +141,7 @@ pub mod v1 { mod tests { #[test] fn crd_merge() { - use super::{merge_crds, Crd}; + use super::{Crd, merge_crds}; let crd1 = r#" apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -235,4 +235,4 @@ pub mod v1 { } // re-export current latest (v1) -pub use v1::{merge_crds, CustomResourceExt, MergeError}; +pub use v1::{CustomResourceExt, MergeError, merge_crds}; diff --git a/kube-core/src/duration.rs b/kube-core/src/duration.rs index 274ea7f82..99161aee7 100644 --- a/kube-core/src/duration.rs +++ b/kube-core/src/duration.rs @@ -1,5 +1,5 @@ //! Kubernetes [`Duration`]s. -use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; +use serde::{Deserialize, Deserializer, Serialize, Serializer, de}; #[cfg(feature = "schema")] use std::borrow::Cow; use std::{cmp::Ordering, fmt, str::FromStr, time}; diff --git a/kube-core/src/kubelet_debug.rs b/kube-core/src/kubelet_debug.rs index cbb3a24c3..75745daac 100644 --- a/kube-core/src/kubelet_debug.rs +++ b/kube-core/src/kubelet_debug.rs @@ -1,8 +1,8 @@ //! Node proxy methods use crate::{ + Request, request::Error, subresource::{AttachParams, LogParams}, - Request, }; use std::fmt::Debug; @@ -163,9 +163,9 @@ impl Request { #[cfg(test)] mod test { use crate::{ + Request, kubelet_debug::KubeletDebugParams, subresource::{AttachParams, LogParams}, - Request, }; #[test] fn node_attach_test() { diff --git a/kube-core/src/lib.rs b/kube-core/src/lib.rs index 4815ec5f0..95b5727c2 100644 --- a/kube-core/src/lib.rs +++ b/kube-core/src/lib.rs @@ -51,8 +51,8 @@ pub use request::Request; mod resource; pub use resource::{ - api_version_from_group_version, ClusterResourceScope, DynamicResourceScope, NamespaceResourceScope, - Resource, ResourceExt, ResourceScope, SubResourceScope, + ClusterResourceScope, DynamicResourceScope, NamespaceResourceScope, Resource, ResourceExt, ResourceScope, + SubResourceScope, api_version_from_group_version, }; pub mod response; diff --git a/kube-core/src/params.rs b/kube-core/src/params.rs index fa508dc4e..7c5dabda2 100644 --- a/kube-core/src/params.rs +++ b/kube-core/src/params.rs @@ -1,5 +1,5 @@ //! A port of request parameter *Optionals from apimachinery/types.go -use crate::{request::Error, Selector}; +use crate::{Selector, request::Error}; use serde::Serialize; /// Controls how the resource version parameter is applied for list calls @@ -876,7 +876,7 @@ where } #[cfg(test)] mod test { - use crate::{params::WatchParams, Expression, Selector}; + use crate::{Expression, Selector, params::WatchParams}; use super::{DeleteParams, ListParams, PatchParams}; #[test] diff --git a/kube-core/src/schema.rs b/kube-core/src/schema.rs index 479918a8e..51dbeeaf2 100644 --- a/kube-core/src/schema.rs +++ b/kube-core/src/schema.rs @@ -5,10 +5,10 @@ // Used in docs #[allow(unused_imports)] use schemars::generate::SchemaSettings; -use schemars::{transform::Transform, JsonSchema}; +use schemars::{JsonSchema, transform::Transform}; use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::collections::{btree_map::Entry, BTreeMap, BTreeSet}; +use std::collections::{BTreeMap, BTreeSet, btree_map::Entry}; /// schemars [`Visitor`] that rewrites a [`Schema`] to conform to Kubernetes' "structural schema" rules /// @@ -381,10 +381,12 @@ fn hoist_subschema_properties( } Entry::Occupied(entry) => { if &property != entry.get() { - panic!("Property {:?} has the schema {:?} but was already defined as {:?} in another subschema. The schemas for a property used in multiple subschemas must be identical", - entry.key(), - &property, - entry.get()); + panic!( + "Property {:?} has the schema {:?} but was already defined as {:?} in another subschema. The schemas for a property used in multiple subschemas must be identical", + entry.key(), + &property, + entry.get() + ); } } } diff --git a/kube-core/src/subresource.rs b/kube-core/src/subresource.rs index d4dddce4e..6ec9d87b0 100644 --- a/kube-core/src/subresource.rs +++ b/kube-core/src/subresource.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use crate::{ params::{DeleteParams, PostParams}, - request::{Error, Request, JSON_MIME}, + request::{Error, JSON_MIME, Request}, }; pub use k8s_openapi::api::autoscaling::v1::{Scale, ScaleSpec, ScaleStatus}; @@ -434,7 +434,10 @@ mod test { timestamps: true, }; let req = Request::new(url).logs("mypod", &lp).unwrap(); - assert_eq!(req.uri(), "/api/v1/namespaces/ns/pods/mypod/log?&container=nginx&follow=true&limitBytes=10485760&pretty=true&previous=true&sinceSeconds=3600&tailLines=4096×tamps=true"); + assert_eq!( + req.uri(), + "/api/v1/namespaces/ns/pods/mypod/log?&container=nginx&follow=true&limitBytes=10485760&pretty=true&previous=true&sinceSeconds=3600&tailLines=4096×tamps=true" + ); } #[test] diff --git a/kube-core/src/util.rs b/kube-core/src/util.rs index 7f45e5500..4c3fe0db0 100644 --- a/kube-core/src/util.rs +++ b/kube-core/src/util.rs @@ -1,8 +1,9 @@ //! Utils and helpers use crate::{ + Request, params::{Patch, PatchParams}, - request, Request, + request, }; use chrono::Utc; use k8s_openapi::api::apps::v1::{DaemonSet, Deployment, ReplicaSet, StatefulSet}; diff --git a/kube-derive/src/cel_schema.rs b/kube-derive/src/cel_schema.rs index a0cfec0af..3c1f7f221 100644 --- a/kube-derive/src/cel_schema.rs +++ b/kube-derive/src/cel_schema.rs @@ -1,9 +1,9 @@ use darling::{ - util::{parse_expr, IdentString}, FromDeriveInput, FromField, FromMeta, + util::{IdentString, parse_expr}, }; use proc_macro2::TokenStream; -use syn::{parse_quote, Attribute, DeriveInput, Expr, Ident, Path}; +use syn::{Attribute, DeriveInput, Expr, Ident, Path, parse_quote}; #[derive(FromField)] #[darling(attributes(x_kube))] diff --git a/kube-derive/src/custom_resource.rs b/kube-derive/src/custom_resource.rs index 443653576..e04c122bb 100644 --- a/kube-derive/src/custom_resource.rs +++ b/kube-derive/src/custom_resource.rs @@ -1,13 +1,13 @@ // Generated by darling macros, out of our control #![allow(clippy::manual_unwrap_or_default)] use darling::{ - util::{parse_expr, Override}, FromDeriveInput, FromMeta, + util::{Override, parse_expr}, }; use proc_macro2::{Ident, Literal, Span, TokenStream}; use quote::{ToTokens, TokenStreamExt as _}; use serde::Deserialize; -use syn::{parse_quote, Data, DeriveInput, Expr, Path, Visibility}; +use syn::{Data, DeriveInput, Expr, Path, Visibility, parse_quote}; /// Values we can parse from #[kube(attrs)] #[derive(Debug, FromDeriveInput)] @@ -335,7 +335,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea &derive_input.ident, r#"Unions can not #[derive(CustomResource)]"#, ) - .to_compile_error() + .to_compile_error(); } } diff --git a/kube-derive/src/resource.rs b/kube-derive/src/resource.rs index 69b1929a6..be35300b4 100644 --- a/kube-derive/src/resource.rs +++ b/kube-derive/src/resource.rs @@ -2,7 +2,7 @@ #![allow(clippy::manual_unwrap_or_default)] use darling::{FromDeriveInput, FromMeta}; -use syn::{parse_quote, Data, DeriveInput, Path}; +use syn::{Data, DeriveInput, Path, parse_quote}; /// Values we can parse from #[kube(attrs)] #[derive(Debug, FromDeriveInput)] @@ -49,7 +49,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea Data::Struct(_) | Data::Enum(_) => {} _ => { return syn::Error::new_spanned(&derive_input.ident, r#"Unions can not #[derive(Resource)]"#) - .to_compile_error() + .to_compile_error(); } } let kube_attrs = match InheritAttrs::from_derive_input(&derive_input) { diff --git a/kube-derive/tests/resource.rs b/kube-derive/tests/resource.rs index 4bfb89703..a4e4c8aa3 100644 --- a/kube-derive/tests/resource.rs +++ b/kube-derive/tests/resource.rs @@ -1,8 +1,8 @@ #![allow(missing_docs)] use k8s_openapi::{ - api::core::v1::{ConfigMap, Secret}, ByteString, + api::core::v1::{ConfigMap, Secret}, }; use kube::api::ObjectMeta; use kube_derive::Resource; diff --git a/kube-runtime/src/controller/future_hash_map.rs b/kube-runtime/src/controller/future_hash_map.rs index e3382dad6..f0d7d10fd 100644 --- a/kube-runtime/src/controller/future_hash_map.rs +++ b/kube-runtime/src/controller/future_hash_map.rs @@ -80,7 +80,7 @@ mod tests { use std::{future, task::Poll}; use super::FutureHashMap; - use futures::{channel::mpsc, poll, StreamExt}; + use futures::{StreamExt, channel::mpsc, poll}; #[tokio::test] async fn fhm_should_forward_all_values_and_shut_down() { diff --git a/kube-runtime/src/controller/mod.rs b/kube-runtime/src/controller/mod.rs index 1d57a40ae..c814ac7d9 100644 --- a/kube-runtime/src/controller/mod.rs +++ b/kube-runtime/src/controller/mod.rs @@ -3,21 +3,20 @@ use self::runner::Runner; use crate::{ reflector::{ - self, reflector, + self, ObjectRef, reflector, store::{Store, Writer}, - ObjectRef, }, - scheduler::{debounced_scheduler, ScheduleRequest}, + scheduler::{ScheduleRequest, debounced_scheduler}, utils::{ - trystream_try_via, Backoff, CancelableJoinHandle, KubeRuntimeStreamExt, StreamBackoff, WatchStreamExt, + Backoff, CancelableJoinHandle, KubeRuntimeStreamExt, StreamBackoff, WatchStreamExt, trystream_try_via, }, - watcher::{self, metadata_watcher, watcher, DefaultBackoff}, + watcher::{self, DefaultBackoff, metadata_watcher, watcher}, }; use educe::Educe; use futures::{ - channel, + FutureExt, Stream, StreamExt, TryFuture, TryFutureExt, TryStream, TryStreamExt, channel, future::{self, BoxFuture}, - stream, FutureExt, Stream, StreamExt, TryFuture, TryFutureExt, TryStream, TryStreamExt, + stream, }; use kube_client::api::{Api, DynamicObject, Resource}; use pin_project::pin_project; @@ -27,13 +26,13 @@ use std::{ future::Future, hash::Hash, sync::Arc, - task::{ready, Poll}, + task::{Poll, ready}, time::Duration, }; use stream::BoxStream; use thiserror::Error; use tokio::{runtime::Handle, time::Instant}; -use tracing::{info_span, Instrument}; +use tracing::{Instrument, info_span}; mod future_hash_map; mod runner; @@ -1680,16 +1679,15 @@ where mod tests { use std::{convert::Infallible, pin::pin, sync::Arc, time::Duration}; - use super::{Action, APPLIER_REQUEUE_BUF_SIZE}; + use super::{APPLIER_REQUEUE_BUF_SIZE, Action}; use crate::{ - applier, + Config, Controller, applier, reflector::{self, ObjectRef}, - watcher::{self, metadata_watcher, watcher, Event}, - Config, Controller, + watcher::{self, Event, metadata_watcher, watcher}, }; use futures::{Stream, StreamExt, TryStreamExt}; use k8s_openapi::api::core::v1::ConfigMap; - use kube_client::{core::ObjectMeta, Api, Resource}; + use kube_client::{Api, Resource, core::ObjectMeta}; use serde::de::DeserializeOwned; use tokio::time::timeout; diff --git a/kube-runtime/src/controller/runner.rs b/kube-runtime/src/controller/runner.rs index 697460763..a71b3612e 100644 --- a/kube-runtime/src/controller/runner.rs +++ b/kube-runtime/src/controller/runner.rs @@ -159,12 +159,13 @@ where mod tests { use super::{Error, Runner}; use crate::{ - scheduler::{scheduler, ScheduleRequest}, + scheduler::{ScheduleRequest, scheduler}, utils::delayed_init::{self, DelayedInit}, }; use futures::{ + Future, SinkExt, StreamExt, TryStreamExt, channel::{mpsc, oneshot}, - future, poll, stream, Future, SinkExt, StreamExt, TryStreamExt, + future, poll, stream, }; use std::{ cell::RefCell, @@ -177,7 +178,7 @@ mod tests { use tokio::{ runtime::Handle, task::yield_now, - time::{advance, pause, sleep, timeout, Instant}, + time::{Instant, advance, pause, sleep, timeout}, }; #[tokio::test] @@ -323,15 +324,17 @@ mod tests { *is_ready.lock().unwrap() = true; delayed_init.init(()); let mut message_counts = HashMap::new(); - assert!(timeout( - Duration::from_secs(1), - runner.try_for_each(|msg| { - *message_counts.entry(msg).or_default() += 1; - async { Ok(()) } - }) - ) - .await - .is_err()); + assert!( + timeout( + Duration::from_secs(1), + runner.try_for_each(|msg| { + *message_counts.entry(msg).or_default() += 1; + async { Ok(()) } + }) + ) + .await + .is_err() + ); assert_eq!(message_counts, HashMap::from([('a', 1), ('b', 1)])); } diff --git a/kube-runtime/src/events.rs b/kube-runtime/src/events.rs index 19c683dbf..b39ed8334 100644 --- a/kube-runtime/src/events.rs +++ b/kube-runtime/src/events.rs @@ -14,8 +14,8 @@ use k8s_openapi::{ chrono::{Duration, Utc}, }; use kube_client::{ - api::{Api, Patch, PatchParams, PostParams}, Client, ResourceExt, + api::{Api, Patch, PatchParams, PostParams}, }; use tokio::sync::RwLock; diff --git a/kube-runtime/src/finalizer.rs b/kube-runtime/src/finalizer.rs index 490838e59..749794dfa 100644 --- a/kube-runtime/src/finalizer.rs +++ b/kube-runtime/src/finalizer.rs @@ -1,13 +1,13 @@ //! Finalizer helper for [`Controller`](crate::Controller) reconcilers use crate::controller::Action; use futures::{TryFuture, TryFutureExt}; -use json_patch::{jsonptr::PointerBuf, AddOperation, PatchOperation, RemoveOperation, TestOperation}; +use json_patch::{AddOperation, PatchOperation, RemoveOperation, TestOperation, jsonptr::PointerBuf}; use kube_client::{ - api::{Patch, PatchParams}, Api, Resource, ResourceExt, + api::{Patch, PatchParams}, }; -use serde::{de::DeserializeOwned, Serialize}; +use serde::{Serialize, de::DeserializeOwned}; use std::{error::Error as StdError, fmt::Debug, str::FromStr, sync::Arc}; use thiserror::Error; diff --git a/kube-runtime/src/lib.rs b/kube-runtime/src/lib.rs index 7d0d8512c..b79f13e61 100644 --- a/kube-runtime/src/lib.rs +++ b/kube-runtime/src/lib.rs @@ -30,12 +30,12 @@ pub mod utils; pub mod wait; pub mod watcher; -pub use controller::{applier, Config, Controller}; +pub use controller::{Config, Controller, applier}; pub use finalizer::finalizer; pub use reflector::reflector; pub use scheduler::scheduler; pub use utils::WatchStreamExt; pub use watcher::{metadata_watcher, watcher}; -pub use utils::{predicates, Predicate}; +pub use utils::{Predicate, predicates}; pub use wait::conditions; diff --git a/kube-runtime/src/reflector/dispatcher.rs b/kube-runtime/src/reflector/dispatcher.rs index 1060dab2b..5dcb1cbf5 100644 --- a/kube-runtime/src/reflector/dispatcher.rs +++ b/kube-runtime/src/reflector/dispatcher.rs @@ -145,13 +145,13 @@ where #[cfg(test)] pub(crate) mod test { use crate::{ - watcher::{Error, Event}, WatchStreamExt, + watcher::{Error, Event}, }; use std::{pin::pin, sync::Arc, task::Poll}; use crate::reflector; - use futures::{poll, stream, StreamExt}; + use futures::{StreamExt, poll, stream}; use k8s_openapi::api::core::v1::Pod; fn testpod(name: &str) -> Pod { diff --git a/kube-runtime/src/reflector/mod.rs b/kube-runtime/src/reflector/mod.rs index 112fcc889..9a749074b 100644 --- a/kube-runtime/src/reflector/mod.rs +++ b/kube-runtime/src/reflector/mod.rs @@ -13,7 +13,7 @@ use async_stream::stream; use futures::{Stream, StreamExt}; use std::hash::Hash; #[cfg(feature = "unstable-runtime-subscribe")] pub use store::store_shared; -pub use store::{store, Store}; +pub use store::{Store, store}; /// Cache objects from a [`watcher()`] stream into a local [`Store`] /// @@ -136,13 +136,13 @@ where #[cfg(test)] mod tests { - use super::{reflector, store, ObjectRef}; + use super::{ObjectRef, reflector, store}; use crate::watcher; - use futures::{stream, StreamExt, TryStreamExt}; + use futures::{StreamExt, TryStreamExt, stream}; use k8s_openapi::{api::core::v1::ConfigMap, apimachinery::pkg::apis::meta::v1::ObjectMeta}; use rand::{ - distr::{Bernoulli, Uniform}, Rng, + distr::{Bernoulli, Uniform}, }; use std::collections::{BTreeMap, HashMap}; diff --git a/kube-runtime/src/reflector/store.rs b/kube-runtime/src/reflector/store.rs index 5f6c4727a..9067a7743 100644 --- a/kube-runtime/src/reflector/store.rs +++ b/kube-runtime/src/reflector/store.rs @@ -1,4 +1,4 @@ -use super::{dispatcher::Dispatcher, Lookup, ObjectRef}; +use super::{Lookup, ObjectRef, dispatcher::Dispatcher}; #[cfg(feature = "unstable-runtime-subscribe")] use crate::reflector::ReflectHandle; use crate::{ @@ -307,7 +307,7 @@ where #[cfg(test)] mod tests { - use super::{store, Writer}; + use super::{Writer, store}; use crate::{reflector::ObjectRef, watcher}; use k8s_openapi::api::core::v1::ConfigMap; use kube_client::api::ObjectMeta; diff --git a/kube-runtime/src/scheduler.rs b/kube-runtime/src/scheduler.rs index 85175dcf1..9704aeec5 100644 --- a/kube-runtime/src/scheduler.rs +++ b/kube-runtime/src/scheduler.rs @@ -1,7 +1,7 @@ //! Delays and deduplicates [`Stream`](futures::stream::Stream) items -use futures::{stream::Fuse, Stream, StreamExt}; -use hashbrown::{hash_map::RawEntryMut, HashMap}; +use futures::{Stream, StreamExt, stream::Fuse}; +use hashbrown::{HashMap, hash_map::RawEntryMut}; use pin_project::pin_project; use std::{ collections::HashSet, @@ -296,11 +296,11 @@ pub(crate) fn max_schedule_time() -> Instant { mod tests { use crate::utils::KubeRuntimeStreamExt; - use super::{debounced_scheduler, scheduler, ScheduleRequest}; + use super::{ScheduleRequest, debounced_scheduler, scheduler}; use educe::Educe; - use futures::{channel::mpsc, future, poll, stream, FutureExt, SinkExt, StreamExt}; + use futures::{FutureExt, SinkExt, StreamExt, channel::mpsc, future, poll, stream}; use std::{pin::pin, task::Poll}; - use tokio::time::{advance, pause, sleep, Duration, Instant}; + use tokio::time::{Duration, Instant, advance, pause, sleep}; fn unwrap_poll(poll: Poll) -> T { if let Poll::Ready(x) = poll { diff --git a/kube-runtime/src/utils/delayed_init.rs b/kube-runtime/src/utils/delayed_init.rs index a80f8f8fa..38e6c32a7 100644 --- a/kube-runtime/src/utils/delayed_init.rs +++ b/kube-runtime/src/utils/delayed_init.rs @@ -1,6 +1,6 @@ use std::{fmt::Debug, sync::Mutex, task::Poll}; -use futures::{channel, Future, FutureExt}; +use futures::{Future, FutureExt, channel}; use thiserror::Error; use tracing::trace; diff --git a/kube-runtime/src/utils/event_decode.rs b/kube-runtime/src/utils/event_decode.rs index 2a0085120..1b9cae341 100644 --- a/kube-runtime/src/utils/event_decode.rs +++ b/kube-runtime/src/utils/event_decode.rs @@ -1,7 +1,7 @@ use crate::watcher::{Error, Event}; use core::{ pin::Pin, - task::{ready, Context, Poll}, + task::{Context, Poll, ready}, }; use futures::{Stream, TryStream}; use pin_project::pin_project; @@ -51,7 +51,7 @@ pub(crate) mod tests { use std::{pin::pin, task::Poll}; use super::{Error, Event, EventDecode}; - use futures::{poll, stream, StreamExt}; + use futures::{StreamExt, poll, stream}; #[tokio::test] async fn watches_applies_uses_correct_stream() { diff --git a/kube-runtime/src/utils/event_modify.rs b/kube-runtime/src/utils/event_modify.rs index 39a2ec909..053df60cb 100644 --- a/kube-runtime/src/utils/event_modify.rs +++ b/kube-runtime/src/utils/event_modify.rs @@ -49,7 +49,7 @@ pub(crate) mod test { use std::{pin::pin, task::Poll}; use super::{Error, Event, EventModify}; - use futures::{poll, stream, StreamExt}; + use futures::{StreamExt, poll, stream}; #[tokio::test] async fn eventmodify_modifies_innner_value_of_event() { diff --git a/kube-runtime/src/utils/mod.rs b/kube-runtime/src/utils/mod.rs index e2722b0fa..261b57f9d 100644 --- a/kube-runtime/src/utils/mod.rs +++ b/kube-runtime/src/utils/mod.rs @@ -9,28 +9,28 @@ mod reflect; mod stream_backoff; mod watch_ext; -pub use backoff_reset_timer::{Backoff, ResetTimerBackoff}; -pub use event_decode::EventDecode; -pub use event_modify::EventModify; -pub use predicate::{predicates, Predicate, PredicateFilter}; -pub use reflect::Reflect; -pub use stream_backoff::StreamBackoff; -pub use watch_ext::WatchStreamExt; /// Deprecated type alias for `EventDecode` #[deprecated( since = "0.96.0", note = "renamed to by `EventDecode`. This alias will be removed in 0.100.0." )] pub use EventDecode as EventFlatten; +pub use backoff_reset_timer::{Backoff, ResetTimerBackoff}; +pub use event_decode::EventDecode; +pub use event_modify::EventModify; +pub use predicate::{Predicate, PredicateFilter, predicates}; +pub use reflect::Reflect; +pub use stream_backoff::StreamBackoff; +pub use watch_ext::WatchStreamExt; use futures::{ - stream::{self, Peekable}, Future, FutureExt, Stream, StreamExt, TryStream, TryStreamExt, + stream::{self, Peekable}, }; use pin_project::pin_project; use std::{ fmt::Debug, - pin::{pin, Pin}, + pin::{Pin, pin}, sync::{Arc, Mutex}, task::Poll, }; diff --git a/kube-runtime/src/utils/predicate.rs b/kube-runtime/src/utils/predicate.rs index 179ba8d80..e11d33fc7 100644 --- a/kube-runtime/src/utils/predicate.rs +++ b/kube-runtime/src/utils/predicate.rs @@ -1,13 +1,13 @@ use crate::{reflector::ObjectRef, watcher::Error}; use core::{ pin::Pin, - task::{ready, Context, Poll}, + task::{Context, Poll, ready}, }; use futures::Stream; use kube_client::Resource; use pin_project::pin_project; use std::{ - collections::{hash_map::DefaultHasher, HashMap}, + collections::{HashMap, hash_map::DefaultHasher}, hash::{Hash, Hasher}, }; @@ -202,8 +202,8 @@ pub mod predicates { pub(crate) mod tests { use std::{pin::pin, task::Poll}; - use super::{predicates, Error, PredicateFilter}; - use futures::{poll, stream, FutureExt, StreamExt}; + use super::{Error, PredicateFilter, predicates}; + use futures::{FutureExt, StreamExt, poll, stream}; use kube_client::Resource; use serde_json::json; diff --git a/kube-runtime/src/utils/reflect.rs b/kube-runtime/src/utils/reflect.rs index e93354202..030dfd1df 100644 --- a/kube-runtime/src/utils/reflect.rs +++ b/kube-runtime/src/utils/reflect.rs @@ -58,7 +58,7 @@ pub(crate) mod test { use super::{Error, Event, Reflect}; use crate::reflector; - use futures::{poll, stream, StreamExt}; + use futures::{StreamExt, poll, stream}; use k8s_openapi::api::core::v1::Pod; fn testpod(name: &str) -> Pod { diff --git a/kube-runtime/src/utils/stream_backoff.rs b/kube-runtime/src/utils/stream_backoff.rs index a23a3461e..b44ca9275 100644 --- a/kube-runtime/src/utils/stream_backoff.rs +++ b/kube-runtime/src/utils/stream_backoff.rs @@ -2,7 +2,7 @@ use std::{future::Future, pin::Pin, task::Poll}; use futures::{Stream, TryStream}; use pin_project::pin_project; -use tokio::time::{sleep, Instant, Sleep}; +use tokio::time::{Instant, Sleep, sleep}; use crate::utils::Backoff; @@ -103,7 +103,7 @@ pub(crate) mod tests { use super::StreamBackoff; use backon::BackoffBuilder; - use futures::{channel::mpsc, poll, stream, StreamExt}; + use futures::{StreamExt, channel::mpsc, poll, stream}; pub struct ConstantBackoff { inner: backon::ConstantBackoff, diff --git a/kube-runtime/src/utils/watch_ext.rs b/kube-runtime/src/utils/watch_ext.rs index 241871837..58d0c9b28 100644 --- a/kube-runtime/src/utils/watch_ext.rs +++ b/kube-runtime/src/utils/watch_ext.rs @@ -279,7 +279,7 @@ impl WatchStreamExt for St where St: Stream {} #[cfg(test)] pub(crate) mod tests { use super::watcher; - use crate::{predicates, WatchStreamExt as _}; + use crate::{WatchStreamExt as _, predicates}; use futures::prelude::*; use k8s_openapi::api::core::v1::Pod; use kube_client::{Api, Resource}; diff --git a/kube-runtime/src/wait.rs b/kube-runtime/src/wait.rs index 04ea84aa5..5e8eb625a 100644 --- a/kube-runtime/src/wait.rs +++ b/kube-runtime/src/wait.rs @@ -79,14 +79,12 @@ where /// use k8s_openapi::api::core::v1::Pod; /// fn my_custom_condition(my_cond: &str) -> impl Condition + '_ { /// move |obj: Option<&Pod>| { -/// if let Some(pod) = &obj { -/// if let Some(status) = &pod.status { -/// if let Some(conds) = &status.conditions { -/// if let Some(pcond) = conds.iter().find(|c| c.type_ == my_cond) { -/// return pcond.status == "True"; -/// } -/// } -/// } +/// if let Some(pod) = &obj +/// && let Some(status) = &pod.status +/// && let Some(conds) = &status.conditions +/// && let Some(pcond) = conds.iter().find(|c| c.type_ == my_cond) +/// { +/// return pcond.status == "True"; /// } /// false /// } @@ -196,14 +194,12 @@ pub mod conditions { #[must_use] pub fn is_crd_established() -> impl Condition { |obj: Option<&CustomResourceDefinition>| { - if let Some(o) = obj { - if let Some(s) = &o.status { - if let Some(conds) = &s.conditions { - if let Some(pcond) = conds.iter().find(|c| c.type_ == "Established") { - return pcond.status == "True"; - } - } - } + if let Some(o) = obj + && let Some(s) = &o.status + && let Some(conds) = &s.conditions + && let Some(pcond) = conds.iter().find(|c| c.type_ == "Established") + { + return pcond.status == "True"; } false } @@ -213,12 +209,11 @@ pub mod conditions { #[must_use] pub fn is_pod_running() -> impl Condition { |obj: Option<&Pod>| { - if let Some(pod) = &obj { - if let Some(status) = &pod.status { - if let Some(phase) = &status.phase { - return phase == "Running"; - } - } + if let Some(pod) = &obj + && let Some(status) = &pod.status + && let Some(phase) = &status.phase + { + return phase == "Running"; } false } @@ -228,14 +223,12 @@ pub mod conditions { #[must_use] pub fn is_job_completed() -> impl Condition { |obj: Option<&Job>| { - if let Some(job) = &obj { - if let Some(s) = &job.status { - if let Some(conds) = &s.conditions { - if let Some(pcond) = conds.iter().find(|c| c.type_ == "Complete") { - return pcond.status == "True"; - } - } - } + if let Some(job) = &obj + && let Some(s) = &job.status + && let Some(conds) = &s.conditions + && let Some(pcond) = conds.iter().find(|c| c.type_ == "Complete") + { + return pcond.status == "True"; } false } @@ -248,16 +241,14 @@ pub mod conditions { #[must_use] pub fn is_deployment_completed() -> impl Condition { |obj: Option<&Deployment>| { - if let Some(depl) = &obj { - if let Some(s) = &depl.status { - if let Some(conds) = &s.conditions { - if let Some(dcond) = conds.iter().find(|c| { - c.type_ == "Progressing" && c.reason == Some("NewReplicaSetAvailable".to_string()) - }) { - return dcond.status == "True"; - } - } - } + if let Some(depl) = &obj + && let Some(s) = &depl.status + && let Some(conds) = &s.conditions + && let Some(dcond) = conds.iter().find(|c| { + c.type_ == "Progressing" && c.reason == Some("NewReplicaSetAvailable".to_string()) + }) + { + return dcond.status == "True"; } false } @@ -267,20 +258,19 @@ pub mod conditions { #[must_use] pub fn is_service_loadbalancer_provisioned() -> impl Condition { |obj: Option<&Service>| { - if let Some(svc) = &obj { + if let Some(svc) = &obj + && let Some(spec) = &svc.spec + { // ignore services that are not type LoadBalancer (return true immediately) - if let Some(spec) = &svc.spec { - if spec.type_ != Some("LoadBalancer".to_string()) { - return true; - } - // carry on if this is a LoadBalancer service - if let Some(s) = &svc.status { - if let Some(lbs) = &s.load_balancer { - if let Some(ings) = &lbs.ingress { - return ings.iter().all(|ip| ip.ip.is_some() || ip.hostname.is_some()); - } - } - } + if spec.type_ != Some("LoadBalancer".to_string()) { + return true; + } + // carry on if this is a LoadBalancer service + if let Some(s) = &svc.status + && let Some(lbs) = &s.load_balancer + && let Some(ings) = &lbs.ingress + { + return ings.iter().all(|ip| ip.ip.is_some() || ip.hostname.is_some()); } } false @@ -291,14 +281,12 @@ pub mod conditions { #[must_use] pub fn is_ingress_provisioned() -> impl Condition { |obj: Option<&Ingress>| { - if let Some(ing) = &obj { - if let Some(s) = &ing.status { - if let Some(lbs) = &s.load_balancer { - if let Some(ings) = &lbs.ingress { - return ings.iter().all(|ip| ip.ip.is_some() || ip.hostname.is_some()); - } - } - } + if let Some(ing) = &obj + && let Some(s) = &ing.status + && let Some(lbs) = &s.load_balancer + && let Some(ings) = &lbs.ingress + { + return ings.iter().all(|ip| ip.ip.is_some() || ip.hostname.is_some()); } false } @@ -343,7 +331,7 @@ pub mod conditions { #[test] /// pass when CRD is established fn crd_established_ok() { - use super::{is_crd_established, Condition}; + use super::{Condition, is_crd_established}; let crd = r#" apiVersion: apiextensions.k8s.io/v1 @@ -396,7 +384,7 @@ pub mod conditions { #[test] /// fail when CRD is not yet ready fn crd_established_fail() { - use super::{is_crd_established, Condition}; + use super::{Condition, is_crd_established}; let crd = r#" apiVersion: apiextensions.k8s.io/v1 @@ -449,7 +437,7 @@ pub mod conditions { #[test] /// fail when CRD does not exist fn crd_established_missing() { - use super::{is_crd_established, Condition}; + use super::{Condition, is_crd_established}; assert!(!is_crd_established().matches_object(None)) } @@ -457,7 +445,7 @@ pub mod conditions { #[test] /// pass when pod is running fn pod_running_ok() { - use super::{is_pod_running, Condition}; + use super::{Condition, is_pod_running}; let pod = r#" apiVersion: v1 @@ -516,7 +504,7 @@ pub mod conditions { #[test] /// fail if pod is unschedulable fn pod_running_unschedulable() { - use super::{is_pod_running, Condition}; + use super::{Condition, is_pod_running}; let pod = r#" apiVersion: v1 @@ -550,7 +538,7 @@ pub mod conditions { #[test] /// fail if pod does not exist fn pod_running_missing() { - use super::{is_pod_running, Condition}; + use super::{Condition, is_pod_running}; assert!(!is_pod_running().matches_object(None)) } @@ -558,7 +546,7 @@ pub mod conditions { #[test] /// pass if job completed fn job_completed_ok() { - use super::{is_job_completed, Condition}; + use super::{Condition, is_job_completed}; let job = r#" apiVersion: batch/v1 @@ -607,7 +595,7 @@ pub mod conditions { #[test] /// fail if job is still in progress fn job_completed_running() { - use super::{is_job_completed, Condition}; + use super::{Condition, is_job_completed}; let job = r#" apiVersion: batch/v1 @@ -647,7 +635,7 @@ pub mod conditions { #[test] /// fail if job does not exist fn job_completed_missing() { - use super::{is_job_completed, Condition}; + use super::{Condition, is_job_completed}; assert!(!is_job_completed().matches_object(None)) } @@ -655,7 +643,7 @@ pub mod conditions { #[test] /// pass when deployment has been fully rolled out fn deployment_completed_ok() { - use super::{is_deployment_completed, Condition}; + use super::{Condition, is_deployment_completed}; let depl = r#" apiVersion: apps/v1 @@ -719,7 +707,7 @@ pub mod conditions { #[test] /// fail if deployment update is still rolling out fn deployment_completed_pending() { - use super::{is_deployment_completed, Condition}; + use super::{Condition, is_deployment_completed}; let depl = r#" apiVersion: apps/v1 @@ -782,7 +770,7 @@ pub mod conditions { #[test] /// fail if deployment does not exist fn deployment_completed_missing() { - use super::{is_deployment_completed, Condition}; + use super::{Condition, is_deployment_completed}; assert!(!is_deployment_completed().matches_object(None)) } @@ -790,7 +778,7 @@ pub mod conditions { #[test] /// pass if loadbalancer service has recieved a loadbalancer IP fn service_lb_provisioned_ok_ip() { - use super::{is_service_loadbalancer_provisioned, Condition}; + use super::{Condition, is_service_loadbalancer_provisioned}; let service = r" apiVersion: v1 @@ -819,7 +807,7 @@ pub mod conditions { #[test] /// pass if loadbalancer service has recieved a loadbalancer hostname fn service_lb_provisioned_ok_hostname() { - use super::{is_service_loadbalancer_provisioned, Condition}; + use super::{Condition, is_service_loadbalancer_provisioned}; let service = r" apiVersion: v1 @@ -848,7 +836,7 @@ pub mod conditions { #[test] /// fail if loadbalancer service is still waiting for a LB fn service_lb_provisioned_pending() { - use super::{is_service_loadbalancer_provisioned, Condition}; + use super::{Condition, is_service_loadbalancer_provisioned}; let service = r" apiVersion: v1 @@ -875,7 +863,7 @@ pub mod conditions { #[test] /// pass if service is not a loadbalancer fn service_lb_provisioned_not_loadbalancer() { - use super::{is_service_loadbalancer_provisioned, Condition}; + use super::{Condition, is_service_loadbalancer_provisioned}; let service = r" apiVersion: v1 @@ -901,7 +889,7 @@ pub mod conditions { #[test] /// fail if service does not exist fn service_lb_provisioned_missing() { - use super::{is_service_loadbalancer_provisioned, Condition}; + use super::{Condition, is_service_loadbalancer_provisioned}; assert!(!is_service_loadbalancer_provisioned().matches_object(None)) } @@ -909,7 +897,7 @@ pub mod conditions { #[test] /// pass when ingress has recieved a loadbalancer IP fn ingress_provisioned_ok_ip() { - use super::{is_ingress_provisioned, Condition}; + use super::{Condition, is_ingress_provisioned}; let ingress = r#" apiVersion: networking.k8s.io/v1 @@ -944,7 +932,7 @@ pub mod conditions { #[test] /// pass when ingress has recieved a loadbalancer hostname fn ingress_provisioned_ok_hostname() { - use super::{is_ingress_provisioned, Condition}; + use super::{Condition, is_ingress_provisioned}; let ingress = r#" apiVersion: networking.k8s.io/v1 @@ -979,7 +967,7 @@ pub mod conditions { #[test] /// fail if ingress is still waiting for a LB fn ingress_provisioned_pending() { - use super::{is_ingress_provisioned, Condition}; + use super::{Condition, is_ingress_provisioned}; let ingress = r#" apiVersion: networking.k8s.io/v1 @@ -1012,7 +1000,7 @@ pub mod conditions { #[test] /// fail if ingress does not exist fn ingress_provisioned_missing() { - use super::{is_ingress_provisioned, Condition}; + use super::{Condition, is_ingress_provisioned}; assert!(!is_ingress_provisioned().matches_object(None)) } @@ -1022,7 +1010,7 @@ pub mod conditions { /// Utilities for deleting objects pub mod delete { use super::{await_condition, conditions}; - use kube_client::{api::DeleteParams, Api, Resource}; + use kube_client::{Api, Resource, api::DeleteParams}; use serde::de::DeserializeOwned; use std::fmt::Debug; use thiserror::Error; diff --git a/kube-runtime/src/watcher.rs b/kube-runtime/src/watcher.rs index 03c0388a3..efcd59ce1 100644 --- a/kube-runtime/src/watcher.rs +++ b/kube-runtime/src/watcher.rs @@ -6,12 +6,12 @@ use crate::utils::{Backoff, ResetTimerBackoff}; use backon::BackoffBuilder; use educe::Educe; -use futures::{stream::BoxStream, Stream, StreamExt}; +use futures::{Stream, StreamExt, stream::BoxStream}; use kube_client::{ + Api, Error as ClientErr, api::{ListParams, Resource, ResourceExt, VersionMatch, WatchEvent, WatchParams}, - core::{metadata::PartialObjectMeta, ObjectList, Selector}, + core::{ObjectList, Selector, metadata::PartialObjectMeta}, error::ErrorResponse, - Api, Error as ClientErr, }; use serde::de::DeserializeOwned; use std::{clone::Clone, collections::VecDeque, fmt::Debug, future, time::Duration}; diff --git a/kube/src/lib.rs b/kube/src/lib.rs index 5c26e6497..df6490c51 100644 --- a/kube/src/lib.rs +++ b/kube/src/lib.rs @@ -206,7 +206,7 @@ pub mod prelude { #[allow(unreachable_pub)] pub use crate::core::PartialObjectMetaExt as _; #[allow(unreachable_pub)] pub use crate::core::SelectorExt as _; - pub use crate::{core::crd::CustomResourceExt as _, Resource as _, ResourceExt as _}; + pub use crate::{Resource as _, ResourceExt as _, core::crd::CustomResourceExt as _}; #[cfg(feature = "runtime")] pub use crate::runtime::utils::WatchStreamExt as _; } @@ -217,8 +217,8 @@ pub mod prelude { #[cfg(all(feature = "derive", feature = "client"))] mod test { use crate::{ - api::{DeleteParams, Patch, PatchParams}, Api, Client, CustomResourceExt, Resource, ResourceExt, + api::{DeleteParams, Patch, PatchParams}, }; use kube_derive::CustomResource; use schemars::JsonSchema; @@ -344,8 +344,8 @@ mod test { async fn custom_serialized_objects_are_queryable_and_iterable() -> Result<(), Box> { use crate::core::{ - object::{HasSpec, HasStatus, NotUsed, Object}, ApiResource, + object::{HasSpec, HasStatus, NotUsed, Object}, }; use k8s_openapi::api::core::v1::Pod; #[derive(Clone, Deserialize, Debug)] @@ -396,8 +396,8 @@ mod test { async fn derived_resources_discoverable() -> Result<(), Box> { use crate::{ core::{DynamicObject, GroupVersion, GroupVersionKind}, - discovery::{self, verbs, ApiGroup, Discovery, Scope}, - runtime::wait::{await_condition, conditions, Condition}, + discovery::{self, ApiGroup, Discovery, Scope, verbs}, + runtime::wait::{Condition, await_condition, conditions}, }; #[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)] @@ -471,9 +471,9 @@ mod test { #[cfg(feature = "runtime")] async fn pod_can_await_conditions() -> Result<(), Box> { use crate::{ - api::{DeleteParams, PostParams}, - runtime::wait::{await_condition, conditions, delete::delete_and_finalize, Condition}, Api, Client, + api::{DeleteParams, PostParams}, + runtime::wait::{Condition, await_condition, conditions, delete::delete_and_finalize}, }; use k8s_openapi::api::core::v1::Pod; use std::time::Duration; @@ -519,14 +519,12 @@ mod test { // TODO: remove these once we can write these functions generically fn is_each_container_ready() -> impl Condition { |obj: Option<&Pod>| { - if let Some(o) = obj { - if let Some(s) = &o.status { - if let Some(conds) = &s.conditions { - if let Some(pcond) = conds.iter().find(|c| c.type_ == "ContainersReady") { - return pcond.status == "True"; - } - } - } + if let Some(o) = obj + && let Some(s) = &o.status + && let Some(conds) = &s.conditions + && let Some(pcond) = conds.iter().find(|c| c.type_ == "ContainersReady") + { + return pcond.status == "True"; } false } diff --git a/kube/src/mock_tests.rs b/kube/src/mock_tests.rs index c651a885a..2c8e41b0f 100644 --- a/kube/src/mock_tests.rs +++ b/kube/src/mock_tests.rs @@ -1,12 +1,12 @@ use crate::{ + Api, Client, runtime::{ - watcher::{watcher, Config}, WatchStreamExt, + watcher::{Config, watcher}, }, - Api, Client, }; use anyhow::Result; -use futures::{poll, StreamExt, TryStreamExt}; +use futures::{StreamExt, TryStreamExt, poll}; use http::{Request, Response}; use kube_client::client::Body; use kube_derive::CustomResource;