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

✨ Add conditions patch utils #3102

Merged

Conversation

fabriziopandini
Copy link
Member

What this PR does / why we need it:
This PR implements a set of utils for handling patching of conditions, mostly designed for supporting the handling of concurrent changes to the same list of conditions

/assign @vincepri
/cc @benmoss
/cc @detiber

@k8s-ci-robot k8s-ci-robot requested review from benmoss and detiber May 27, 2020 14:35
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 27, 2020
Copy link

@seh seh left a comment

Choose a reason for hiding this comment

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

Here are some copyediting suggestions for the comments.

util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
if sourceCondition := get(source, conditionPatch.Target.Type); sourceCondition != nil {
// if source and target agree on the change, then it is a conflict
if !hasSameState(sourceCondition, conditionPatch.Target) {
return nil, errors.Errorf("error patching conditions: The condition %q on was modified by a different process and this caused a merge conflict", conditionPatch.Target.Type)
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we should consider LastTransitionTime for the condition we are attempting to patch and allow updating the condition if our LastTransitionTime is newer than the LastTransitionTime from the source conditions?

Copy link
Member Author

Choose a reason for hiding this comment

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

I struggled a little bit around the same problem and then I chose to not block for a small difference on LastTransitionTime while doing concurrent changes. Instead if there are changes in any other condition property, we are blocking.
Also, I opted for preserving the first LastTransitionTime stored in etcd, so we avoid flickering of conditions value for a matter of ms.

util/conditions/patch.go Outdated Show resolved Hide resolved
// the target state corresponds. If not this is a conflict
if !reflect.DeepEqual(sourceCondition, conditionPatch.Base) {
if !hasSameState(sourceCondition, conditionPatch.Target) {
return nil, errors.Errorf("error patching conditions: The condition %q on was modified by a different process and this caused a merge conflict", conditionPatch.Target.Type)
Copy link
Member

Choose a reason for hiding this comment

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

Similar to above, if we have a newer LastTransitionTime than the associated condition in the source conditions, should we still allow updating the condition?

Copy link
Member Author

Choose a reason for hiding this comment

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

As above, I don't think a small difference on LastTransitionTime while doing concurrent changes requires raising an error.

util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch_test.go Outdated Show resolved Hide resolved
util/conditions/patch_test.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
util/conditions/patch.go Outdated Show resolved Hide resolved
@fabriziopandini fabriziopandini force-pushed the conditions-patch-utils branch from e0ebd69 to 06f6f80 Compare May 28, 2020 17:31
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 28, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini, vincepri

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:
  • OWNERS [fabriziopandini,vincepri]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vincepri
Copy link
Member

/milestone v0.3.7

@k8s-ci-robot k8s-ci-robot added this to the v0.3.7 milestone May 28, 2020
@k8s-ci-robot k8s-ci-robot merged commit 70a6230 into kubernetes-sigs:master May 28, 2020
@fabriziopandini fabriziopandini deleted the conditions-patch-utils branch June 4, 2020 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants