Skip to content
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

feat: support targeting the root of an object where source is a subtree; tests #36

Merged
merged 5 commits into from
Jul 14, 2023

Conversation

lukebond
Copy link
Contributor

@lukebond lukebond commented Jul 14, 2023

fixes #34

this PR also improves the tests by adding controller test cases for all the types of ResourceSyncs that we use this project for, including this new type that is now supported.

previously, only the from_field_path field of the Mapping was optional, so you could copy an entire resource into a target subtree but you couldn't copy a source subtree into the root of a target resource.

in a previous PR i thought i was implementing this by allowing an empty string as the mapping's target path, however there were two things wrong with that:

  • it didn't work, because that case wasn't handled in the code. this PR fixes that
  • it created a weird situation where the from field was an option but the target was required, yet the code handled the special case of the string being empty. this is very un-rusty. this PR fixes that by making both fields optional, yet erroring if you set neither.

this is a dependency for https://github.com/influxdata/tubernetes/issues/752

@lukebond lukebond requested a review from mkmik July 14, 2023 12:00
@@ -185,26 +185,124 @@ fn apply_mappings(
debug!(%dbg, "before");

debug!(?subtree, ?mapping.to_field_path, "to field path");
if mapping.to_field_path.starts_with("metadata.") {
Copy link
Contributor Author

@lukebond lukebond Jul 14, 2023

Choose a reason for hiding this comment

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

this block is preserved, just moved down to the last match pattern

Mapping {
from_field_path: Some(_),
to_field_path: None,
} => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this block is the bulk of the change to be reviewed, and the supporting functions it calls

src/controller.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@mkmik mkmik left a comment

Choose a reason for hiding this comment

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

thanks for the tests!

@lukebond lukebond enabled auto-merge July 14, 2023 12:19
@lukebond lukebond merged commit 1cf2d5c into main Jul 14, 2023
@lukebond lukebond deleted the feat/issue-34 branch July 14, 2023 12:20
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.

support targeting the root of an object where source is a subtree
2 participants