-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
✨ Add client.StrategicMergeFrom #1406
✨ Add client.StrategicMergeFrom #1406
Conversation
Hi @timebertt. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
Is there any way to refactor this so it's not quite as much copy-paste from MergeFrom? It feels like a lot of duplication. |
f3bea56
to
c2f0e7d
Compare
@coderanger Yes, you're right. It turned out to be very much the same like |
pkg/client/patch.go
Outdated
} | ||
|
||
// StrategicMergeFromWithOptions creates a Patch that patches using the strategic-merge-patch strategy with the given object as base. | ||
func StrategicMergeFromWithOptions(obj runtime.Object, opts ...MergeFromOption) Patch { |
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.
Is it appropriate to use MergeFromOption
here? My concern is that merge-patch
and strategic-merge-patch
could diverge in the options they take in the future.
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 was contemplating about the same, glad you bring it up here.
The reason I chose this way, is that if options specific to either patch type will be added in the future, we could simply add another interface StrategicMergeFromOption
, implement both interfaces in the options that we already have and just switch the parameter type in StrategicMergeFrom
. This way, folks using the options wouldn't get any compile tim error when upgrading.
And as it's not required to differentiate right now, I chose to reuse MergeFromOption
for simplicity's sake.
Let me know, if you have any concerns with this approach.
c2f0e7d
to
48c6ba2
Compare
pkg/client/patch.go
Outdated
} | ||
|
||
// StrategicMergeFrom creates a Patch that patches using the strategic-merge-patch strategy with the given object as base. | ||
func StrategicMergeFrom(obj runtime.Object, opts ...MergeFromOption) Patch { |
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.
Can you please add godocs here and to MergeFrom
that explain how StrategicMergePatch and MergePatch differ and when to use which?
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.
Sure, good idea. Done.
WDYT now?
48c6ba2
to
4adf325
Compare
4adf325
to
bdd93c0
Compare
Done. |
I see a failure now:
|
bdd93c0
to
9b99e55
Compare
/ok-to-test |
/lgtm thank you! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, timebertt The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixes #1375
This PR adds
client.StrategicMergeFrom
.The function is similar to
client.{MergeFrom,MergeFromWithOptions}
, but it creates astrategic-merge-patch
instead of amerge-patch
. See doc strings for more details about the differences of the two patch types and to figure out when to use which one.Note, that strategic merge patches are not supported by CRDs.