Skip to content

Commit

Permalink
Merge branch 'main' into fix/hoist-enum-values
Browse files Browse the repository at this point in the history
Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
  • Loading branch information
nightkr committed Oct 14, 2022
2 parents d2f90fb + 0b12c6a commit 0faf86a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 18 deletions.
7 changes: 5 additions & 2 deletions examples/configmapgen_controller.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Nightly clippy (0.1.64) considers Drop a side effect, see https://github.com/rust-lang/rust-clippy/issues/9608
#![allow(clippy::unnecessary_lazy_evaluations)]

use anyhow::Result;
use futures::StreamExt;
use k8s_openapi::api::core::v1::ConfigMap;
Expand Down Expand Up @@ -50,14 +53,14 @@ async fn reconcile(generator: Arc<ConfigMapGenerator>, ctx: Arc<Data>) -> Result
.metadata
.namespace
.as_ref()
.ok_or(Error::MissingObjectKey(".metadata.namespace"))?,
.ok_or_else(|| Error::MissingObjectKey(".metadata.namespace"))?,
);
cm_api
.patch(
cm.metadata
.name
.as_ref()
.ok_or(Error::MissingObjectKey(".metadata.name"))?,
.ok_or_else(|| Error::MissingObjectKey(".metadata.name"))?,
&PatchParams::apply("configmapgenerator.kube-rt.nullable.se"),
&Patch::Apply(&cm),
)
Expand Down
4 changes: 2 additions & 2 deletions kube-client/src/api/portforward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ where
match msg {
Message::FromPod(ch, mut bytes) => {
let ch = ch as usize;
let channel = chan_state.get_mut(ch).ok_or(Error::InvalidChannel(ch))?;
let channel = chan_state.get_mut(ch).ok_or_else(|| Error::InvalidChannel(ch))?;

let port_index = ch / 2;
// Initialization
Expand Down Expand Up @@ -327,7 +327,7 @@ where
}
Message::ToPodClose(ch) => {
let ch = ch as usize;
let channel = chan_state.get_mut(ch).ok_or(Error::InvalidChannel(ch))?;
let channel = chan_state.get_mut(ch).ok_or_else(|| Error::InvalidChannel(ch))?;
let port_index = ch / 2;

if !channel.shutdown {
Expand Down
2 changes: 1 addition & 1 deletion kube-client/src/config/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ fn load_from_base64_or_file<P: AsRef<Path>>(
let data = value
.map(load_from_base64)
.or_else(|| file.as_ref().map(load_from_file))
.unwrap_or(Err(LoadDataError::NoBase64DataOrFile))?;
.unwrap_or_else(|| Err(LoadDataError::NoBase64DataOrFile))?;
Ok(ensure_trailing_newline(data))
}

Expand Down
2 changes: 2 additions & 0 deletions kube-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(missing_docs)]
#![forbid(unsafe_code)]
// Nightly clippy (0.1.64) considers Drop a side effect, see https://github.com/rust-lang/rust-clippy/issues/9608
#![allow(clippy::unnecessary_lazy_evaluations)]

macro_rules! cfg_client {
($($item:item)*) => {
Expand Down
11 changes: 5 additions & 6 deletions kube-core/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
//!
//! [`CustomResourceDefinition`]: `k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinition`

use std::collections::btree_map::Entry;

// Used in docs
#[allow(unused_imports)] use schemars::gen::SchemaSettings;

use schemars::{
schema::{InstanceType, Metadata, ObjectValidation, Schema, SchemaObject, SingleOrVec},
visit::Visitor,
MapEntry,
};

/// schemars [`Visitor`] that rewrites a [`Schema`] to conform to Kubernetes' "structural schema" rules
Expand Down Expand Up @@ -118,7 +117,7 @@ fn hoist_subschema_properties(
..
}) = variant
{
let common_obj = common_obj.get_or_insert_with(|| Box::new(ObjectValidation::default()));
let common_obj = common_obj.get_or_insert_with(Box::<ObjectValidation>::default);

if let Some(variant_metadata) = variant_metadata {
// Move enum variant description from oneOf clause to its corresponding property
Expand All @@ -128,7 +127,7 @@ fn hoist_subschema_properties(
{
let metadata = variant_object
.metadata
.get_or_insert_with(|| Box::new(Metadata::default()));
.get_or_insert_with(Box::<Metadata>::default);
metadata.description = Some(description);
}
}
Expand All @@ -138,10 +137,10 @@ fn hoist_subschema_properties(
let variant_properties = std::mem::take(&mut variant_obj.properties);
for (property_name, property) in variant_properties {
match common_obj.properties.entry(property_name) {
Entry::Vacant(entry) => {
MapEntry::Vacant(entry) => {
entry.insert(property);
}
Entry::Occupied(entry) => {
MapEntry::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(),
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl Display for ReconcileReason {
ReconcileReason::Unknown => f.write_str("unknown"),
ReconcileReason::ObjectUpdated => f.write_str("object updated"),
ReconcileReason::RelatedObjectUpdated { obj_ref: object } => {
f.write_fmt(format_args!("related object updated: {}", object))
f.write_fmt(format_args!("related object updated: {object}"))
}
ReconcileReason::BulkReconcile => f.write_str("bulk reconcile requested"),
ReconcileReason::ReconcilerRequestedRetry => f.write_str("reconciler requested retry"),
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/src/finalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
// Short-circuit, so that we keep the finalizer if cleanup fails
.map_err(Error::CleanupFailed)?;
// Cleanup was successful, remove the finalizer so that deletion can continue
let finalizer_path = format!("/metadata/finalizers/{}", finalizer_i);
let finalizer_path = format!("/metadata/finalizers/{finalizer_i}");
api.patch::<K>(
&name,
&PatchParams::default(),
Expand Down
8 changes: 4 additions & 4 deletions kube-runtime/src/reflector/object_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<K: Resource> Display for ObjectRef<K> {
self.name
)?;
if let Some(namespace) = &self.namespace {
write!(f, ".{}", namespace)?;
write!(f, ".{namespace}")?;
}
Ok(())
}
Expand Down Expand Up @@ -251,11 +251,11 @@ mod tests {
#[test]
fn display_should_be_transparent_to_representation() {
let pod_ref = ObjectRef::<Pod>::new("my-pod").within("my-namespace");
assert_eq!(format!("{}", pod_ref), format!("{}", pod_ref.erase()));
assert_eq!(format!("{pod_ref}"), format!("{}", pod_ref.erase()));
let deploy_ref = ObjectRef::<Deployment>::new("my-deploy").within("my-namespace");
assert_eq!(format!("{}", deploy_ref), format!("{}", deploy_ref.erase()));
assert_eq!(format!("{deploy_ref}"), format!("{}", deploy_ref.erase()));
let node_ref = ObjectRef::<Node>::new("my-node");
assert_eq!(format!("{}", node_ref), format!("{}", node_ref.erase()));
assert_eq!(format!("{node_ref}"), format!("{}", node_ref.erase()));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub fn watch_object<K: Resource + Clone + DeserializeOwned + Debug + Send + 'sta
name: &str,
) -> impl Stream<Item = Result<Option<K>>> + Send {
watcher(api, ListParams {
field_selector: Some(format!("metadata.name={}", name)),
field_selector: Some(format!("metadata.name={name}")),
..Default::default()
})
.map(|event| match event? {
Expand Down

0 comments on commit 0faf86a

Please sign in to comment.