Skip to content

Commit

Permalink
replace derivative dependency with educe (#1585)
Browse files Browse the repository at this point in the history
Replace the unmaintained `derivative` dependency with `educe`.
See also #1583.

Signed-off-by: Robert Rose <[email protected]>
  • Loading branch information
rorosen authored Sep 22, 2024
1 parent edd384e commit c0fe0c8
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ base64 = "0.22.0"
bytes = "1.1.0"
chrono = { version = "0.4.34", default-features = false }
darling = "0.20.3"
derivative = "2.1.1"
educe = { version = "0.6.0", default-features = false }
either = "1.6.1"
form_urlencoded = "1.2.0"
futures = { version = "0.3.17", default-features = false }
Expand Down
5 changes: 0 additions & 5 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ multiple-versions = "deny"
[[bans.skip]]
name = "rustls-native-certs"

[[bans.skip]]
# We need to replace derivative to get rid of syn 1
# https://github.com/kube-rs/kube/issues/1583
name = "syn"

[[bans.skip]]
# base64 did some annoying breaking changes
name = "base64"
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ rust.unsafe_code = "forbid"
[dependencies]
futures = { workspace = true, features = ["async-await"] }
kube-client = { path = "../kube-client", version = "=0.95.0", default-features = false, features = ["jsonpatch", "client"] }
derivative.workspace = true
educe = { workspace = true, features = ["Clone", "Debug", "Hash", "PartialEq"] }
serde.workspace = true
ahash.workspace = true
parking_lot.workspace = true
Expand Down
19 changes: 10 additions & 9 deletions kube-runtime/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
watcher::{self, metadata_watcher, watcher, DefaultBackoff},
};
use backoff::backoff::Backoff;
use derivative::Derivative;
use educe::Educe;
use futures::{
channel,
future::{self, BoxFuture},
Expand Down Expand Up @@ -267,20 +267,21 @@ where
/// NOTE: The reason is ignored for comparison purposes. This means that, for example,
/// an object can only occupy one scheduler slot, even if it has been scheduled for multiple reasons.
/// In this case, only *the first* reason is stored.
#[derive(Derivative)]
#[derivative(
Debug(bound = "K::DynamicType: Debug"),
Clone(bound = "K::DynamicType: Clone"),
PartialEq(bound = "K::DynamicType: PartialEq"),
Eq(bound = "K::DynamicType: Eq"),
Hash(bound = "K::DynamicType: Hash")
#[derive(Educe)]
#[educe(
Debug(bound("K::DynamicType: Debug")),
Clone(bound("K::DynamicType: Clone")),
PartialEq(bound("K::DynamicType: PartialEq")),
Hash(bound("K::DynamicType: Hash"))
)]
pub struct ReconcileRequest<K: Resource> {
pub obj_ref: ObjectRef<K>,
#[derivative(PartialEq = "ignore", Hash = "ignore")]
#[educe(PartialEq(ignore), Hash(ignore))]
pub reason: ReconcileReason,
}

impl<K: Resource> Eq for ReconcileRequest<K> where K::DynamicType: Eq {}

impl<K: Resource> From<ObjectRef<K>> for ReconcileRequest<K> {
fn from(obj_ref: ObjectRef<K>) -> Self {
ReconcileRequest {
Expand Down
4 changes: 3 additions & 1 deletion kube-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

#![deny(clippy::all)]
#![deny(clippy::pedantic)]
// Triggered by many derive macros (kube-derive, derivative)
// Triggered by many derive macros (kube-derive, educe)
#![allow(clippy::default_trait_access)]
#![allow(clippy::type_repetition_in_bounds)]
// Triggered by educe derives on enums
#![allow(clippy::used_underscore_binding)]
// Triggered by Tokio macros
#![allow(clippy::semicolon_if_nothing_returned)]
// Triggered by nightly clippy on idiomatic code
Expand Down
6 changes: 3 additions & 3 deletions kube-runtime/src/reflector/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::{
};
use std::{fmt::Debug, sync::Arc};

use derivative::Derivative;
use educe::Educe;
use futures::Stream;
use pin_project::pin_project;
use std::task::ready;
Expand All @@ -14,8 +14,8 @@ use async_broadcast::{InactiveReceiver, Receiver, Sender};

use super::Lookup;

#[derive(Derivative)]
#[derivative(Debug(bound = "K: Debug, K::DynamicType: Debug"), Clone)]
#[derive(Educe)]
#[educe(Debug(bound("K: Debug, K::DynamicType: Debug")), Clone)]
// A helper type that holds a broadcast transmitter and a broadcast receiver,
// used to fan-out events from a root stream to multiple listeners.
pub(crate) struct Dispatcher<K>
Expand Down
19 changes: 10 additions & 9 deletions kube-runtime/src/reflector/object_ref.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use derivative::Derivative;
use educe::Educe;
use k8s_openapi::{api::core::v1::ObjectReference, apimachinery::pkg::apis::meta::v1::OwnerReference};
#[cfg(doc)] use kube_client::core::ObjectMeta;
use kube_client::{
Expand Down Expand Up @@ -98,13 +98,12 @@ impl<K: Resource> Lookup for K {
}
}

#[derive(Derivative)]
#[derivative(
Debug(bound = "K::DynamicType: Debug"),
PartialEq(bound = "K::DynamicType: PartialEq"),
Eq(bound = "K::DynamicType: Eq"),
Hash(bound = "K::DynamicType: Hash"),
Clone(bound = "K::DynamicType: Clone")
#[derive(Educe)]
#[educe(
Debug(bound("K::DynamicType: Debug")),
PartialEq(bound("K::DynamicType: PartialEq")),
Hash(bound("K::DynamicType: Hash")),
Clone(bound("K::DynamicType: Clone"))
)]
/// A typed and namedspaced (if relevant) reference to a Kubernetes object
///
Expand Down Expand Up @@ -141,10 +140,12 @@ pub struct ObjectRef<K: Lookup + ?Sized> {
///
/// This is *not* considered when comparing objects, but may be used when converting to and from other representations,
/// such as [`OwnerReference`] or [`ObjectReference`].
#[derivative(Hash = "ignore", PartialEq = "ignore")]
#[educe(Hash(ignore), PartialEq(ignore))]
pub extra: Extra,
}

impl<K: Lookup + ?Sized> Eq for ObjectRef<K> where K::DynamicType: Eq {}

/// Non-vital information about an object being referred to
///
/// See [`ObjectRef::extra`].
Expand Down
6 changes: 3 additions & 3 deletions kube-runtime/src/reflector/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
watcher,
};
use ahash::AHashMap;
use derivative::Derivative;
use educe::Educe;
use parking_lot::RwLock;
use std::{fmt::Debug, hash::Hash, sync::Arc};
use thiserror::Error;
Expand Down Expand Up @@ -179,8 +179,8 @@ where
///
/// Cannot be constructed directly since one writer handle is required,
/// use `Writer::as_reader()` instead.
#[derive(Derivative)]
#[derivative(Debug(bound = "K: Debug, K::DynamicType: Debug"), Clone)]
#[derive(Educe)]
#[educe(Debug(bound("K: Debug, K::DynamicType: Debug")), Clone)]
pub struct Store<K: 'static + Lookup>
where
K::DynamicType: Hash + Eq,
Expand Down
8 changes: 4 additions & 4 deletions kube-runtime/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ mod tests {
use crate::utils::KubeRuntimeStreamExt;

use super::{debounced_scheduler, scheduler, ScheduleRequest};
use derivative::Derivative;
use educe::Educe;
use futures::{channel::mpsc, future, poll, stream, FutureExt, SinkExt, StreamExt};
use std::{pin::pin, task::Poll};
use tokio::time::{advance, pause, sleep, Duration, Instant};
Expand All @@ -309,9 +309,9 @@ mod tests {
}

/// Message type that is always considered equal to itself
#[derive(Derivative, Eq, Clone, Debug)]
#[derivative(PartialEq, Hash)]
struct SingletonMessage(#[derivative(PartialEq = "ignore", Hash = "ignore")] u8);
#[derive(Educe, Eq, Clone, Debug)]
#[educe(PartialEq, Hash)]
struct SingletonMessage(#[educe(PartialEq(ignore), Hash(ignore))] u8);

#[tokio::test]
async fn scheduler_should_hold_and_release_items() {
Expand Down
4 changes: 1 addition & 3 deletions kube-runtime/src/utils/delayed_init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{fmt::Debug, sync::Mutex, task::Poll};

use derivative::Derivative;
use futures::{channel, Future, FutureExt};
use thiserror::Error;
use tracing::trace;
Expand All @@ -26,8 +25,7 @@ impl<T> Debug for Initializer<T> {
///
/// Can be considered equivalent to a [`channel::oneshot`] channel, except for that
/// the value produced is retained for subsequent calls to [`Self::get`].
#[derive(Derivative)]
#[derivative(Debug)]
#[derive(Debug)]
pub struct DelayedInit<T> {
state: Mutex<ReceiverState<T>>,
}
Expand Down
10 changes: 5 additions & 5 deletions kube-runtime/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::utils::ResetTimerBackoff;
use async_trait::async_trait;
use backoff::{backoff::Backoff, ExponentialBackoff};
use derivative::Derivative;
use educe::Educe;
use futures::{stream::BoxStream, Stream, StreamExt};
use kube_client::{
api::{ListParams, Resource, ResourceExt, VersionMatch, WatchEvent, WatchParams},
Expand Down Expand Up @@ -121,8 +121,8 @@ impl<K> Event<K> {
}
}

#[derive(Derivative, Default)]
#[derivative(Debug)]
#[derive(Educe, Default)]
#[educe(Debug)]
/// The internal finite state machine driving the [`watcher`]
enum State<K> {
/// The Watcher is empty, and the next [`poll`](Stream::poll_next) will start the initial LIST to get all existing objects
Expand All @@ -137,7 +137,7 @@ enum State<K> {
/// Kubernetes 1.27 Streaming Lists
/// The initial watch is in progress
InitialWatch {
#[derivative(Debug = "ignore")]
#[educe(Debug(ignore))]
stream: BoxStream<'static, kube_client::Result<WatchEvent<K>>>,
},
/// The initial LIST was successful, so we should move on to starting the actual watch.
Expand All @@ -150,7 +150,7 @@ enum State<K> {
/// with `Empty`.
Watching {
resource_version: String,
#[derivative(Debug = "ignore")]
#[educe(Debug(ignore))]
stream: BoxStream<'static, kube_client::Result<WatchEvent<K>>>,
},
}
Expand Down

0 comments on commit c0fe0c8

Please sign in to comment.