Skip to content

[Merged by Bors] - Config fragment/validation #445

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 29 commits into from

Conversation

nightkr
Copy link
Member

@nightkr nightkr commented Jul 26, 2022

Description

This is an alternate take on #425. Essentially, we define a new macro Fragment, which creates a "parallel fragment universe" where everything is optional. For example, given the following types:

#[derive(Fragment)]
struct Outer {
    foo: u32,
    inner: Inner,
}

#[derive(Fragment)]
struct Inner {
    required: String,
    optional: Option<String>,
}

we generate the following fragment variants:

struct OuterFragment {
    foo: Option<u32>,
    inner: InnerFragment, // not an atomic type, so make every subfield optional instead
}

struct InnerFragment {
    required: Option<String>, // was non-optional, so make it optional
    optional: Option<String>, // was already optional, so preserve the type
}

as well as validation functions that turn OuterFragment into Result<Outer> (and an equivalent for Inner), while giving us the full context when a validation error occurs.

This allows us to safely deserialize and merge the fragment variants, and only afterwards validate that all required options are present in the final merged configuration.

This is a pretty big and breaking change, since it moves all Serialize and Deserialize impls on the resources into the fragment variants.

Review Checklist

  • Code contains useful comments
  • (Integration-)Test cases added (or not applicable)
  • Documentation added (or not applicable)
  • Changelog updated (or not applicable)
  • Cargo.toml only contains references to git tags (not specific commits or branches)

Once the review is done, comment bors r+ (or bors merge) to merge. Further information

@nightkr
Copy link
Member Author

nightkr commented Jul 26, 2022

There is an example conversion of zookeeper-operator: stackabletech/zookeeper-operator#530

@nightkr nightkr self-assigned this Jul 26, 2022
@nightkr nightkr changed the title Feature/config fragment Config fragment/validation Jul 27, 2022
@nightkr nightkr requested a review from a team August 2, 2022 08:51
@nightkr nightkr marked this pull request as ready for review August 2, 2022 08:52
@adwk67 adwk67 self-requested a review August 4, 2022 14:08
Copy link
Member

@adwk67 adwk67 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments/questions aimed at clarifying things.

@nightkr
Copy link
Member Author

nightkr commented Aug 16, 2022

This depends on GREsau/schemars#167

@nightkr nightkr requested a review from adwk67 August 16, 2022 12:16
Copy link
Member

@adwk67 adwk67 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.
(q: should we refer to a tag rather than a branch - feature/custom-bound - for schemars_derive? Or is that going to remain static until the change is merged upstream?)

@nightkr
Copy link
Member Author

nightkr commented Aug 16, 2022

(q: should we refer to a tag rather than a branch - feature/custom-bound - for schemars_derive?)

No, we should probably hold off on merging this until their branch is merged and released.

@adwk67
Copy link
Member

adwk67 commented Aug 16, 2022

(q: should we refer to a tag rather than a branch - feature/custom-bound - for schemars_derive?)

No, we should probably hold off on merging this until their branch is merged and released.

OK.

@nightkr
Copy link
Member Author

nightkr commented Oct 13, 2022

@adwk67 Are we ok merging this now?

@adwk67
Copy link
Member

adwk67 commented Oct 17, 2022

@adwk67 Are we ok merging this now?

yes, fine by me.

@nightkr
Copy link
Member Author

nightkr commented Oct 17, 2022

bors r+

bors bot pushed a commit that referenced this pull request Oct 17, 2022
## Description

This is an alternate take on #425. Essentially, we define a new macro `Fragment`, which creates a "parallel fragment universe" where everything is optional. For example, given the following types:

```rust
#[derive(Fragment)]
struct Outer {
    foo: u32,
    inner: Inner,
}

#[derive(Fragment)]
struct Inner {
    required: String,
    optional: Option<String>,
}
```

we generate the following fragment variants:

```rust
struct OuterFragment {
    foo: Option<u32>,
    inner: InnerFragment, // not an atomic type, so make every subfield optional instead
}

struct InnerFragment {
    required: Option<String>, // was non-optional, so make it optional
    optional: Option<String>, // was already optional, so preserve the type
}
```

as well as validation functions that turn `OuterFragment` into `Result<Outer>` (and an equivalent for `Inner`), while giving us the full context when a validation error occurs.

This allows us to safely deserialize and merge the fragment variants, and only afterwards validate that all required options are present in the final merged configuration.

This is a pretty big and breaking change, since it moves all `Serialize` and `Deserialize` impls on the resources into the fragment variants.



Co-authored-by: Teo Klestrup Röijezon <[email protected]>
@bors
Copy link
Contributor

bors bot commented Oct 17, 2022

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Config fragment/validation [Merged by Bors] - Config fragment/validation Oct 17, 2022
@bors bors bot closed this Oct 17, 2022
@bors bors bot deleted the feature/config-fragment branch October 17, 2022 12:50
nightkr added a commit that referenced this pull request Oct 17, 2022
Looks like the merge went slightly awry...
bors bot pushed a commit that referenced this pull request Oct 17, 2022

## Description

Looks like the merge went slightly awry...



Co-authored-by: Teo Klestrup Röijezon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge typed role and rolegroup configs before converting to product-config maps
3 participants