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

improve replaceKeys proposal #620

Merged
merged 1 commit into from
Jun 19, 2017

Conversation

mengqiy
Copy link
Member

@mengqiy mengqiy commented May 13, 2017

When implementing #278 (PR is kubernetes/kubernetes#44597),
@pwittrock and I found we can do it more efficiently when patching a list with replace patch strategy and still keep backward compatibility.

This is very similar to what we have in #278.

cc: @liggitt

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 13, 2017
@mengqiy
Copy link
Member Author

mengqiy commented May 13, 2017

/assign @pwittrock

- All of the missing fields will be cleared when patching.
- All fields in the `$replaceKeys` list must be a superset or the same as the fields present in the patch.

An new patch will have same content as old patch and an additional new directive.
Copy link
Contributor

Choose a reason for hiding this comment

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

-An new patch will have same content as old patch and an additional new directive.
+A new patch will have the same content as the old patch and an additional new directive.

I'm not sure how carefully you want this to be proofread. There are some minor syntax issues I'm happy to fix if you think that would be useful.

Copy link
Member Author

Choose a reason for hiding this comment

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

That will be great. Thanks!

@mengqiy mengqiy force-pushed the update_replaceKeys_proposal branch from 1bfef0d to 5339586 Compare May 19, 2017 01:10
Add tags `patchStrategy:"replaceKeys"`.
For a given type that has the tag, all keys/fields missing
from the request will be cleared when patching the object.
For a field presents in the request, it will be merged with the live config.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd replace this line with:

Each field present in the request will be merged with the live config.


## Analysis

There are 2 reasons of not choosing this logic:
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace of not choosing with to avoid

Reason is that `$patch` has been used in early releases.
If we add new value to this directive,
the old server will reject the new patch due to not knowing the new value.
- The patch have to include the entire the struct to hold the place in a list with `replace` patch strategy,
Copy link
Contributor

Choose a reason for hiding this comment

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

s/the entire the struct/the entire struct

If we add new value to this directive,
the old server will reject the new patch due to not knowing the new value.
- The patch have to include the entire the struct to hold the place in a list with `replace` patch strategy,
even though there maybe no changes at all.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/maybe/may be

the old server will reject the new patch due to not knowing the new value.
- The patch have to include the entire the struct to hold the place in a list with `replace` patch strategy,
even though there maybe no changes at all.
This is less efficient comparing with the approach above.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/comparing with/compared to

@@ -224,8 +270,8 @@ Changes about how to generate the patch rely on package Strategic Merge Patch.
Strategic Merge Patch is a package used by both client and server. A typical usage is that a client
calls the function to calculate the patch and the API server calls another function to merge the patch.

We need to make sure the client always sends a patch that includes all of the fields that it wants to keep.
When merging, auto clear missing fields of a patch if the patch has a directive `$patch: replaceKeys`
We need to make sure the new client always sends a patch with `$replaceKeys` directive.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/sends a patch with/sends its patches with the

@mengqiy mengqiy force-pushed the update_replaceKeys_proposal branch from 5339586 to c914c7b Compare May 19, 2017 18:06
@mengqiy
Copy link
Member Author

mengqiy commented May 19, 2017

Updated.
@alexandercampbell Thanks for proofreading.

@alexandercampbell
Copy link
Contributor

no problem!

k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this pull request May 27, 2017
Automatic merge from submit-queue (batch tested with PRs 46302, 44597, 44742, 46554)

support replaceKeys patch strategy

Implementing according to [this proposal](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/add-new-patchStrategy-to-clear-fields-not-present-in-patch.md).
The revision is in kubernetes/community#620.

```release-note
support replaceKeys patch strategy and directive for strategic merge patch
```
@mengqiy mengqiy force-pushed the update_replaceKeys_proposal branch from c914c7b to 588ce36 Compare June 15, 2017 22:23
@mengqiy
Copy link
Member Author

mengqiy commented Jun 15, 2017

@pwittrock Can we merge this?

bar: x
```

#### When the `$retainKeys` list has fields that not present in the patch
Copy link
Member

Choose a reason for hiding this comment

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

that not present in the patch

that are not present in the patch

There are 2 reasons of avoiding this logic:
- Using `$patch` as directive key will break backward compatibility.
But can easily fixed by using a different key, e.g. `retainKeys: true`.
Reason is that `$patch` has been used in early releases.
Copy link
Member

Choose a reason for hiding this comment

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

early releases

earlier releases

Reason is that `$patch` has been used in early releases.
If we add new value to this directive,
the old server will reject the new patch due to not knowing the new value.
- The patch have to include the entire struct to hold the place in a list with `replace` patch strategy,
Copy link
Member

Choose a reason for hiding this comment

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

The patch have

The patch has

the old server will reject the new patch due to not knowing the new value.
- The patch have to include the entire struct to hold the place in a list with `replace` patch strategy,
even though there may be no changes at all.
This is less efficient comparing to the approach above.
Copy link
Member

Choose a reason for hiding this comment

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

efficient comparing

efficient compared

@pwittrock
Copy link
Member

Minor updates. Otherwise LGTM

@mengqiy mengqiy force-pushed the update_replaceKeys_proposal branch from 588ce36 to edcb7c5 Compare June 16, 2017 00:13
@mengqiy
Copy link
Member Author

mengqiy commented Jun 16, 2017

Updated. PTAL

@pwittrock pwittrock merged commit 0cb56c1 into kubernetes:master Jun 19, 2017
@mengqiy mengqiy deleted the update_replaceKeys_proposal branch June 19, 2017 19:51
MadhavJivrajani pushed a commit to MadhavJivrajani/community that referenced this pull request Nov 30, 2021
akhilerm pushed a commit to akhilerm/apimachinery that referenced this pull request Sep 20, 2022
Automatic merge from submit-queue (batch tested with PRs 46302, 44597, 44742, 46554)

support replaceKeys patch strategy

Implementing according to [this proposal](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/add-new-patchStrategy-to-clear-fields-not-present-in-patch.md).
The revision is in kubernetes/community#620.

```release-note
support replaceKeys patch strategy and directive for strategic merge patch
```

Kubernetes-commit: 6927e7061b129f88b718a5d78dfa8ce7233f384c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants