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 method to apply strategic merge patch #13820

Merged
merged 1 commit into from
Oct 8, 2015

Conversation

jackgr
Copy link
Contributor

@jackgr jackgr commented Sep 10, 2015

This PR builds on #13007 by adding a method to apply a strategic merge patch created by taking the difference between the original and modified user configuration and applying it to the current live configuration. This method detects and by default will automatically resolve conflicts in favor of the user. However, per discussion on #13007, we may want to add another method that applies the modified user configuration, plus delete directives relative to the original user configuration as the patch. Also, per discussion on #13576, we may want to revisit the question of conflict detection and resolution. Pending the development of any additional methods based on the outcome of those discussions, the method added by this PR can be used to do the equivalent of a git rebase -s theirs.

@mikedanese
Copy link
Member

cc @kubernetes/goog-ux

@k8s-github-robot k8s-github-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Sep 13, 2015
@k8s-github-robot
Copy link

Labelling this PR as size/XXL

@mikedanese
Copy link
Member

Please ping or reassign when this is ready for review. cc @ghodss

@ghodss
Copy link
Contributor

ghodss commented Sep 14, 2015

The code looks good to me but I don't a use case for this method. As per #13007 (comment) and then #13007 (comment) I think all we need now is the delete-decorator method, and then we can reuse the StrategicMergePatch method with the resulting patch and be done with prerequisites for kubectl apply (i.e. #1702). The more urgent patchset currently needed is that delete-decorator method, but we can merge this as well if we think there's another use case that warrants the additional complexity.

@jackgr
Copy link
Contributor Author

jackgr commented Sep 25, 2015

Reimplemented the method using the semantics described by @ghodss above.

@mikedanese ready for review.

@jackgr jackgr changed the title WIP: Add method to apply strategic merge patch Add method to apply strategic merge patch Sep 25, 2015
@k8s-bot
Copy link

k8s-bot commented Sep 25, 2015

Unit, integration and GCE e2e build/test failed for commit 6b34700d47f7ce369c3b5d2eb797cb57ac7a76af.

@bgrant0607 bgrant0607 assigned ghodss and unassigned jackgr Sep 27, 2015
@bgrant0607
Copy link
Member

cc @kubernetes/kubectl

// of the documents is invalid, or if there are any preconditions that fail against the modified
// configuration, or, if force is false and there are conflicts between the modified and current
// configurations.
func CreateThreeWayMergePatch(original, modified, current []byte, dataStruct interface{}, force bool, fns ...PreconditionFunc) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that the "delete-decorator" method I was describing would take "patch" (the local config file given to kubectl apply) and "previous" (i.e. the content of the annotation) to produce a new strategic merge patch with delete directives for missing fields. That patch then gets sent directly to the server which applies it with the pre-existing StrategicMergePatch method. Why do we need a method that is creating its own patch from scratch using original and modified?

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 approach reuses existing proven code, instead of adding a whole new set of recursive methods, and has exactly the same semantics, except that the patch does not update fields that are already set correctly, making it smaller. Bottom line... less code and more efficient.

@jackgr jackgr force-pushed the apply_patch branch 3 times, most recently from 81545ea to 17bf288 Compare September 29, 2015 23:00
@k8s-bot
Copy link

k8s-bot commented Sep 29, 2015

Unit, integration and GCE e2e build/test failed for commit 17bf288438e359eab77789a58d60152e61599f5b.

@k8s-bot
Copy link

k8s-bot commented Sep 29, 2015

Unit, integration and GCE e2e test build/test passed for commit 46666b5225acf28f66fad6323e96532ea3ab4c4c.

@k8s-bot
Copy link

k8s-bot commented Oct 1, 2015

Unit, integration and GCE e2e test build/test passed for commit aa65108d6633ed3cafd4880d4463d6a5374395e7.

@smarterclayton
Copy link
Contributor

The precondition and other higher level code looks fine to me, I'll defer to Sam on the deeper flows because I haven't followed the SMR and 3way discussions for context.

// IsPreconditionFailed returns true if the provided error indicates
// a Delta precondition did not succeed.
func IsPreconditionFailed(err error) bool {
return err == ErrPreconditionFailed
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fragile, as it's effectively string comparison on a fixed error string. Better to make ErrPreconditionFailed and ErrConflict structs that implement error and do a type comparison. Added bonus, you can print a more useful error message, i.e. the actual conflicting diff or failed precondition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed this issue a couple of commits ago.

@k8s-bot
Copy link

k8s-bot commented Oct 2, 2015

Unit, integration and GCE e2e test build/test passed for commit e75ee184b82a96468d1a4a62e54484f884ec938e.

@jackgr
Copy link
Contributor Author

jackgr commented Oct 2, 2015

@jlowdermilk Done. PTAL.

}

func newErrConflict(patch, current []byte) errConflict {
s := fmt.Sprintf("patch:\n%v\nconflicts with current:\n%v\n", patch, current)
Copy link
Contributor

Choose a reason for hiding this comment

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

Either use %s in the format string, or convert byte arrays to string (i.e. string(patch)). Otherwise you get illegible output that looks like patch: [123 34 102 111 111 34 58 34 ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@j3ffml
Copy link
Contributor

j3ffml commented Oct 2, 2015

LGTM. Thanks for your patience @jackgr. Let's get it in!

@j3ffml j3ffml added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 2, 2015
@k8s-bot
Copy link

k8s-bot commented Oct 2, 2015

Unit, integration and GCE e2e test build/test passed for commit 05fde753e85a343e575c2ceee2ff97bd93d53cea.

@a-robinson
Copy link
Contributor

Needs a rebase before it can be merged

@a-robinson a-robinson added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 5, 2015
@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented Oct 6, 2015

GCE e2e test build/test passed for commit 05fde753e85a343e575c2ceee2ff97bd93d53cea.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 7, 2015
@k8s-bot
Copy link

k8s-bot commented Oct 7, 2015

GCE e2e test build/test passed for commit 9ff2e43e9a61b7d1bab762f03cfb4ecc72c88fee.

@k8s-github-robot
Copy link

LGTM was before last commit, removing LGTM

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 7, 2015
@j3ffml j3ffml added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 7, 2015
@jackgr
Copy link
Contributor Author

jackgr commented Oct 7, 2015

@jlowdermilk This PR has been stuck on a Shippable build break for over a day. The offending logs are as follows:

Testing api version:
error: server version (version.Info{Major:"1", Minor:"2+", GitVersion:"v1.2.0-alpha.1.581+2f40f36e97ae46-dirty", GitCommit:"2f40f36e97ae460193fdef745f646cbcfad5e2df", GitTreeState:"dirty"}) differs from client version (version.Info{Major:"1", Minor:"2+", GitVersion:"v1.2.0-alpha.1.581+2f40f36e97ae46", GitCommit:"2f40f36e97ae460193fdef745f646cbcfad5e2df", GitTreeState:"clean"})!
!!! Error in ./hack/test-cmd.sh:165
'[ "$(kubectl get nodes -o go-template='{{ .apiVersion }}' "${kube_flags[@]}")" == "v1" ]' exited with status 1
Call stack:
1: ./hack/test-cmd.sh:165 runTests(...)
2: ./hack/test-cmd.sh:909 main(...)
Exiting with status 1

Unless I'm mistaken, this test failure is not related to this PR. Does anyone have any insight as to how to get past it?

@j3ffml
Copy link
Contributor

j3ffml commented Oct 7, 2015

@jackgr shippable was broken at head for awhile, you probably picked up the bad change. Rebasing (yet again, sorry) should fix.

@k8s-bot
Copy link

k8s-bot commented Oct 8, 2015

GCE e2e test build/test passed for commit ddda379.

@piosz
Copy link
Member

piosz commented Oct 8, 2015

Removing LGTM since there was a change after LGTM was granted. @jlowdermilk could you please take a look?

@piosz piosz removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 8, 2015
@j3ffml j3ffml added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 8, 2015
roberthbailey added a commit that referenced this pull request Oct 8, 2015
Add method to apply strategic merge patch
@roberthbailey roberthbailey merged commit f9364da into kubernetes:master Oct 8, 2015
@jackgr jackgr deleted the apply_patch branch October 26, 2015 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.