Skip to content

Merge typed role and role group configs #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1dad930
moved merge macro to its own module
maltesander Jun 13, 2022
024cdb4
started with config macro
maltesander Jun 13, 2022
41f8e00
added example test case
maltesander Jun 13, 2022
ef14f7b
added atomic for vec
maltesander Jun 14, 2022
de87006
some tests working
maltesander Jun 14, 2022
5b3e22f
changed default_impl field to path
maltesander Jun 14, 2022
d9d9b64
error handling
maltesander Jun 14, 2022
bb386a0
more tests
maltesander Jun 14, 2022
8dba2da
renamed Config derive to Optional
maltesander Jun 14, 2022
678793f
comments and adaptation
maltesander Jun 14, 2022
1410c80
comments and adaptation
maltesander Jun 14, 2022
7e58667
wip
maltesander Jun 14, 2022
789fd3c
wip
maltesander Jun 17, 2022
db11ce7
wip
maltesander Jun 20, 2022
cfc6a17
wip
maltesander Jun 21, 2022
2b10642
wip
maltesander Jun 21, 2022
3cba75e
first working version
maltesander Jun 21, 2022
2472c18
fixed erase
maltesander Jun 21, 2022
19eda1e
all compiling
maltesander Jun 21, 2022
d67c245
wip
maltesander Jun 21, 2022
509e378
wip
maltesander Jun 22, 2022
d95f752
fixed tests
maltesander Jun 22, 2022
52da1dd
wip
maltesander Jun 23, 2022
52d4636
extended comments
maltesander Jun 23, 2022
83cceff
wip
maltesander Jun 23, 2022
22cef10
more docs
maltesander Jun 23, 2022
5e6c2cb
adapted changelog
maltesander Jun 23, 2022
62d5f84
fix linters
maltesander Jun 23, 2022
cddcc99
added complex type to merge optional non-atomic structs
maltesander Jun 24, 2022
4b60896
fix clippy
maltesander Jun 24, 2022
a4b0c8d
fix clippy #2
maltesander Jun 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- An `Optional` macro to derive a struct with only optional parameters and the Merge trait for merging ([#425]).
- BREAKING: `role_utils::Role<O, M` now takes 2 parameters. One OptionalFooConfig (derived by the `Optional` macro) and the original FooConfig ([#425]).

### Changed

- BREAKING: Bump to k8s 1.24 and kube 0.73.1 ([#408]).
- BREAKING: The CommonConfiguration of the Role and RoleGroup now have to retrieved via a get() method ([#425]).

### Fixed

- Correctly propagate storage class in `PVCConfig::build_pvc()` ([#412]).

[#408]: https://github.com/stackabletech/operator-rs/pull/408
[#412]: https://github.com/stackabletech/operator-rs/pull/412
[#425]: https://github.com/stackabletech/operator-rs/pull/425

## [0.21.1] - 2022-05-22

Expand Down
3 changes: 3 additions & 0 deletions src/config/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
hash::Hash,
};

use crate::commons::resources::Resources;
pub use stackable_operator_derive::Merge;

/// A type that can be merged with itself
Expand Down Expand Up @@ -134,6 +135,8 @@ impl Atomic for String {}
impl Atomic for Quantity {}
impl<'a> Atomic for &'a str {}
impl Atomic for LabelSelector {}
impl<T: Clone> Atomic for Vec<T> {}
impl<T: Clone + Default + Merge> Atomic for Resources<T> {}

impl<T: Atomic> Merge for Option<T> {
fn merge(&mut self, defaults: &Self) {
Expand Down
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod merge;
pub mod optional;
28 changes: 28 additions & 0 deletions src/config/optional.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::config::merge::Merge;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

pub use stackable_operator_derive::Optional;

#[derive(Clone, Debug, Default, Deserialize, JsonSchema, PartialEq, Serialize)]
#[serde(transparent)]
pub struct Complex<T>(Option<T>);

impl<T> Complex<T> {
pub fn get(self) -> Option<T> {
self.0
}
}

impl<T: Clone + Merge> Merge for Complex<T> {
fn merge(&mut self, defaults: &Self) {
match (&mut self.0, &defaults.0) {
(Some(s), Some(d)) => s.merge(d),
(None, Some(d)) => self.0 = Some(d).cloned(),
(_, _) => {}
}
}
}

#[cfg(test)]
mod tests {}
Loading