Skip to content

Commit

Permalink
refactor!: Replace unmaintained derivative create with educe (#907)
Browse files Browse the repository at this point in the history
* refactor!: Replace unmaintained derivative create with educe

* changelog

* changelog

* changelog

* Fix rust docs

* Fix uneeded trait bounds

* Update crates/stackable-operator/CHANGELOG.md

Co-authored-by: Siegfried Weber <mail@siegfriedweber.net>

---------

Co-authored-by: Siegfried Weber <mail@siegfriedweber.net>
  • Loading branch information
sbernauer and siegfriedweber authored Nov 28, 2024
1 parent 3e5b3ba commit 1b7de87
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 80 deletions.
13 changes: 1 addition & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const-oid = "0.9.6"
convert_case = "0.6.0"
darling = "0.20.10"
delegate = "0.13.0"
derivative = "2.2.0"
dockerfile-parser = "0.8.0"
ecdsa = { version = "0.16.9", features = ["digest", "pem"] }
educe = { version = "0.6.0", default-features = false, features = ["Clone", "Debug", "Default", "PartialEq"] }
either = "1.13.0"
futures = "0.3.30"
futures-util = "0.3.30"
Expand Down
6 changes: 6 additions & 0 deletions crates/stackable-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Changed

- Replace unmaintained `derivative` crate with `educe` ([#907]).

[#907]: https://github.com/stackabletech/operator-rs/pull/907

## [0.82.0] - 2024-11-23

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion crates/stackable-operator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ chrono.workspace = true
clap.workspace = true
const_format.workspace = true
delegate.workspace = true
derivative.workspace = true
dockerfile-parser.workspace = true
either.workspace = true
educe.workspace = true
futures.workspace = true
indexmap.workspace = true
json-patch.workspace = true
Expand Down
20 changes: 5 additions & 15 deletions crates/stackable-operator/src/commons/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ use crate::{
cpu::CpuQuantity,
memory::MemoryQuantity,
};
use derivative::Derivative;
use educe::Educe;
use k8s_openapi::api::core::v1::{
Container, PersistentVolumeClaim, PersistentVolumeClaimSpec, PodSpec, ResourceRequirements,
VolumeResourceRequirements,
Expand Down Expand Up @@ -133,13 +133,8 @@ pub enum Error {
path_overrides(fragment = "crate::config::fragment")
)]
#[fragment_attrs(
derive(Merge, Serialize, Deserialize, JsonSchema, Derivative),
derivative(
Default(bound = "T::Fragment: Default, K::Fragment: Default"),
Debug(bound = "T::Fragment: Debug, K::Fragment: Debug"),
Clone(bound = "T::Fragment: Clone, K::Fragment: Clone"),
PartialEq(bound = "T::Fragment: PartialEq, K::Fragment: PartialEq")
),
derive(Merge, Serialize, Deserialize, JsonSchema, Educe),
educe(Clone, Debug, Default, PartialEq),
merge(
bound = "T::Fragment: Merge, K::Fragment: Merge",
path_overrides(merge = "crate::config::merge")
Expand Down Expand Up @@ -172,13 +167,8 @@ pub struct Resources<T, K = NoRuntimeLimits> {
path_overrides(fragment = "crate::config::fragment")
)]
#[fragment_attrs(
derive(Merge, Serialize, Deserialize, JsonSchema, Derivative),
derivative(
Default(bound = "T::Fragment: Default"),
Debug(bound = "T::Fragment: Debug"),
Clone(bound = "T::Fragment: Clone"),
PartialEq(bound = "T::Fragment: PartialEq")
),
derive(Merge, Serialize, Deserialize, JsonSchema, Educe),
educe(Clone, Debug, Default, PartialEq),
merge(
bound = "T::Fragment: Merge",
path_overrides(merge = "crate::config::merge")
Expand Down
13 changes: 5 additions & 8 deletions crates/stackable-operator/src/crd.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
use std::marker::PhantomData;

use derivative::Derivative;
use educe::Educe;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// A reference to a product cluster (for example, a `ZookeeperCluster`)
///
/// `namespace`'s defaulting only applies when retrieved via [`ClusterRef::namespace_relative_from`]
#[derive(Deserialize, Serialize, JsonSchema, Derivative)]
#[derivative(
Default(bound = ""),
Clone(bound = ""),
Debug(bound = ""),
PartialEq(bound = "")
)]
#[derive(Deserialize, Serialize, JsonSchema, Educe)]
#[educe(Clone(bound()), Debug(bound()), Default(bound()), PartialEq(bound()))]
pub struct ClusterRef<K> {
/// The name of the cluster
pub name: Option<String>,

/// The namespace of the cluster
///
/// This field is optional, and will default to the namespace of the referring object.
#[serde(default)]
pub namespace: Option<String>,

#[serde(skip)]
_kind: PhantomData<K>,
}
Expand Down
32 changes: 17 additions & 15 deletions crates/stackable-operator/src/product_logging/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::config::{
merge::Merge,
};

use derivative::Derivative;
use educe::Educe;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -46,21 +46,21 @@ use serde::{Deserialize, Serialize};
///
/// let logging = product_logging::spec::default_logging::<Container>();
/// ```
#[derive(Clone, Debug, Derivative, Eq, Fragment, JsonSchema, PartialEq)]
#[derivative(Default(bound = ""))]
#[derive(Clone, Debug, Eq, Fragment, JsonSchema, PartialEq, Educe)]
#[educe(Default)]
#[fragment(path_overrides(fragment = "crate::config::fragment"))]
#[fragment_attrs(
derive(
Clone,
Debug,
Derivative,
Deserialize,
JsonSchema,
Merge,
PartialEq,
Serialize
Serialize,
Educe,
),
derivative(Default(bound = "")),
educe(Default),
merge(path_overrides(merge = "crate::config::merge")),
serde(
bound(serialize = "T: Serialize", deserialize = "T: Deserialize<'de>",),
Expand All @@ -75,6 +75,7 @@ where
{
/// Wether or not to deploy a container with the Vector log agent.
pub enable_vector_agent: bool,

/// Log configuration per container.
#[fragment_attrs(serde(default))]
pub containers: BTreeMap<T, ContainerLogConfig>,
Expand Down Expand Up @@ -119,25 +120,27 @@ pub struct ContainerLogConfig {
/// Custom or automatic log configuration
///
/// The custom log configuration takes precedence over the automatic one.
#[derive(Clone, Debug, Derivative, Eq, JsonSchema, PartialEq)]
#[derivative(Default)]
#[derive(Clone, Debug, Eq, JsonSchema, PartialEq, Educe)]
#[educe(Default)]
pub enum ContainerLogConfigChoice {
/// Custom log configuration provided in a ConfigMap
Custom(CustomContainerLogConfig),

/// Automatic log configuration according to the given values
#[derivative(Default)]
#[educe(Default)]
Automatic(AutomaticContainerLogConfig),
}

#[derive(Clone, Debug, Derivative, Deserialize, JsonSchema, Merge, PartialEq, Serialize)]
#[derivative(Default)]
#[derive(Clone, Debug, Deserialize, JsonSchema, Merge, PartialEq, Serialize, Educe)]
#[educe(Default)]
#[merge(path_overrides(merge = "crate::config::merge"))]
#[serde(untagged)]
pub enum ContainerLogConfigChoiceFragment {
/// Custom log configuration provided in a ConfigMap
Custom(CustomContainerLogConfigFragment),
#[derivative(Default)]

/// Automatic log configuration according to the given values
#[educe(Default)]
Automatic(AutomaticContainerLogConfigFragment),
}

Expand Down Expand Up @@ -306,7 +309,7 @@ pub struct AppenderConfig {
Clone,
Copy,
Debug,
Derivative,
Default,
Deserialize,
Eq,
JsonSchema,
Expand All @@ -316,11 +319,10 @@ pub struct AppenderConfig {
Serialize,
strum::Display,
)]
#[derivative(Default)]
pub enum LogLevel {
TRACE,
DEBUG,
#[derivative(Default)]
#[default]
INFO,
WARN,
ERROR,
Expand Down
9 changes: 3 additions & 6 deletions crates/stackable-operator/src/role_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ use crate::{
product_config_utils::Configuration,
utils::crds::raw_object_schema,
};
use derivative::Derivative;
use educe::Educe;
use k8s_openapi::api::core::v1::PodTemplateSpec;
use kube::{runtime::reflector::ObjectRef, Resource};
use schemars::JsonSchema;
Expand Down Expand Up @@ -274,11 +274,8 @@ impl<T> RoleGroup<T> {
}

/// A reference to a named role group of a given cluster object
#[derive(Derivative)]
#[derivative(
Debug(bound = "K::DynamicType: Debug"),
Clone(bound = "K::DynamicType: Clone")
)]
#[derive(Educe)]
#[educe(Clone, Debug)]
pub struct RoleGroupRef<K: Resource> {
pub cluster: ObjectRef<K>,
pub role: String,
Expand Down
8 changes: 3 additions & 5 deletions crates/stackable-operator/src/time/duration.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! This module contains a common [`Duration`] struct which is able to parse
//! human-readable duration formats, like `5s`, `24h`, `2y2h20m42s` or`15d2m2s`. It
//! additionally implements many required traits, like [`Derivative`],
//! [`JsonSchema`], [`Deserialize`][serde::Deserialize], and
//! [`Serialize`][serde::Serialize].
//! additionally implements many required traits, like [`JsonSchema`],
//! [`Deserialize`][serde::Deserialize], and [`Serialize`][serde::Serialize].
//!
//! Furthermore, it implements [`Deref`], which enables us to use all associated
//! functions of [`std::time::Duration`] without re-implementing the public
Expand All @@ -20,7 +19,6 @@ use std::{
str::FromStr,
};

use derivative::Derivative;
use schemars::JsonSchema;
use snafu::{OptionExt, ResultExt, Snafu};
use strum::IntoEnumIterator;
Expand Down Expand Up @@ -63,7 +61,7 @@ pub enum DurationParseError {
/// A common [`Duration`] struct which is able to parse human-readable duration
/// formats, like `5s`, `24h`, `2y2h20m42s` or`15d2m2s`. It additionally
/// implements many required traits (for CRD deserialization and serialization).
#[derive(Clone, Copy, Debug, Derivative, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Duration(std::time::Duration);

impl FromStr for Duration {
Expand Down
30 changes: 13 additions & 17 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[graph]
targets = [
{ triple = "x86_64-unknown-linux-gnu" },
{ triple = "aarch64-unknown-linux-gnu" },
Expand All @@ -7,49 +8,44 @@ targets = [
]

[advisories]
vulnerability = "warn"
unmaintained = "allow"
unsound = "warn"
yanked = "warn"
notice = "warn"
yanked = "deny"

[bans]
multiple-versions = "allow"

[[bans.deny]]
name = "time"
version = "0.1"

[licenses]
unlicensed = "deny"
copyleft = "deny"
allow-osi-fsf-free = "neither"
default = "deny"
unused-allowed-license = "allow"
confidence-threshold = 1.0
allow = [
"Apache-2.0",
"BSD-2-Clause",
"BSD-3-Clause",
"CC0-1.0",
"ISC",
"LicenseRef-ring",
"LicenseRef-webpki",
"MIT",
"MPL-2.0",
"Unicode-3.0",
"Unicode-DFS-2016",
"Zlib",
"Unlicense",
"OpenSSL",
"Unicode-3.0",
]
private = { ignore = true }

[[licenses.clarify]]
name = "ring"
expression = "LicenseRef-ring"
license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]
license-files = [
{ path = "LICENSE", hash = 0xbd0eed23 },
]

[[licenses.clarify]]
name = "webpki"
expression = "LicenseRef-webpki"
license-files = [{ path = "LICENSE", hash = 0x001c7e6c }]
license-files = [
{ path = "LICENSE", hash = 0x001c7e6c },
]

[sources]
unknown-registry = "deny"
Expand Down

0 comments on commit 1b7de87

Please sign in to comment.