-
Notifications
You must be signed in to change notification settings - Fork 71
add extended remove method for typed values #133
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
Conversation
3c49fc4 to
28e231e
Compare
|
/retest |
b1a49df to
24c650a
Compare
968020e to
5151f1a
Compare
apelisse
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the tests Kevin! They are extremely useful
typed/remove_test.go
Outdated
| object: `{"a": "value", "b":{"c":"value"}}`, | ||
| remove: fieldpath.NewSet(fieldpath.MakePathOrDie("b")), | ||
| deep: false, | ||
| // TODO: this seems to behave differently with a non deduced schema: {"a": "value", "b":{"c":"value"}} which is the reason for this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jennybuckley probably knows, I suspect it's because we treat deduced fields as map fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking about adding a second test that defines the schema for all the tests above to verify.
If the behavior differs, we can at least be sure we want it to do.
Probably tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think this is because deduced schema would see "b":{"c":"value"} as a map item, and so it would be removable, but if you defined a schema which has the fields named, then it would be seen as a struct field, and I don't think we expect to remove those with RemoveItems, since this function was created to remove list/map items that no appliers owns anymore, a behavior which doesn't apply to struct fields (since we didn't want removing replicas from a config and reapplying to reset replicas to 1)
|
/retest |
|
/test pull-structured-merge-diff-test |
37509fd to
bf5b0dc
Compare
|
@apelisse i pushed my current state including the failing tests. The |
apelisse
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at merge/update.go yet and how prune will be broken with this. We can do that later.
fieldpath/element.go
Outdated
| } | ||
|
|
||
| // NewIndexPathElement creates a PathElement with the given index | ||
| func NewIndexPathElement(index int) PathElement { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not using the method above, but you're using this one. We really shouldn't depend on this. Let's see ...
| } | ||
|
|
||
| // PrintState is an Operation printing the current state to help with debugging tests | ||
| type PrintState struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are good suggestions. I had thought about some version of this but thought that it was equally simple to have multiple tests:
Test 1: do a
Test 2: do a and b
Test 3: do a, b and c
if you really care about intermediate state, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, multiple tests would solve that as well.
While creating (and debugging) the remove tests, it was already getting less comfortable working with them due to the amount of tests. Also because of my unfortunate decision not to name them...
For now I only wanted to understand and debug the broken tests that already exist.
Pulling them apart into multiple tests would have been something for another PR and then still might cause more clutter while the Print and Expect Operations would allow for the same result in the existing test fixture thing.
| Object: ` | ||
| mapOfMapsRecursive: | ||
| a: | ||
| a: {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little unfortunate :-/ but I think that's fine.
apelisse
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, the code looked OK to me, and I don't see anything wrong with the tests either. I suspect we can try a few more corner-cases though.
internal/fixture/state.go
Outdated
| return fmt.Errorf("failed to compare live with config: %v", err) | ||
| } | ||
| if !comparison.IsSame() { | ||
| config, err := state.Parser.Type(string(op.APIVersion)).FromYAML(FixTabsOrDie(op.Object)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move this code to a separate function since it's done twice and is hard to read.
typed/remove_test.go
Outdated
| }, | ||
| { | ||
| object: `{"a": "value", "b": ["c", "d"]}`, | ||
| remove: _NS(_P("b", _I(1))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a test that removes by value, do we have one? Maybe below, but I suspect it belongs here
| l := w.value.AsListUsing(w.allocator) | ||
| defer w.allocator.Free(l) | ||
| // If list is null, empty, or atomic just return | ||
| if l == nil || l.Length() == 0 || t.ElementRelationship == schema.Atomic { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jennybuckley Do you remember why we had the atomic check here? Would it be a problem to remove it?
apelisse
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I think this is good, @jennybuckley would you mind looking at this?
|
/assign |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: kwiesmueller The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
821eea9 to
0548f89
Compare
|
@jennybuckley did you have time to look at this? |
|
Can you please squash? Thanks |
0548f89 to
fb8f1b2
Compare
fb8f1b2 to
0856fcb
Compare
|
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
|
@kwiesmueller: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
I think that's been replaced. |
While working on an implementation of kubernetes/enhancements#1123
i discovered that removing fields is not behaving like I expected.
Provided an original fieldSet like:
and a fieldSet to be removed:
The current Difference and Intersect methods for fieldSets do not match all child paths when a parent path is defined, because
.status!=.status.phase.For most cases, this seems reasonable (like ownership).
But to define a set of fields that should be removed from the object, it is impractical.
To avoid a user has to define every deep path to be removed (for status wiping),
a second Remove method is added to value.TypedValue that removes a fieldpath once found.
It extends the already available RemoveItems behavior to also remove from maps.