Skip to content

plumb Update resthandler to allow old/new comparisons in admission#25787

Merged
k8s-github-robot merged 1 commit intokubernetes:masterfrom
liggitt:update-admission
May 24, 2016
Merged

plumb Update resthandler to allow old/new comparisons in admission#25787
k8s-github-robot merged 1 commit intokubernetes:masterfrom
liggitt:update-admission

Conversation

@liggitt
Copy link
Copy Markdown
Member

@liggitt liggitt commented May 18, 2016

Rework how updated objects are passed to rest storage Update methods (first pass at #23928 (comment))

  • allows centralizing precondition checks (uid and resourceVersion)
  • allows admission to have the old and new objects on patch/update operations (sets us up for field level authorization, differential quota updates, etc)
  • allows patch operations to avoid double-GETting the object to apply the patch

Overview of important changes:

  • pkg/api/rest/rest.go
    • changes rest.Update interface to give rest storage an UpdatedObjectInfo interface instead of the object directly. To get the updated object, the storage must call UpdatedObject(), passing in the current object
  • pkg/api/rest/update.go
    • provides a default UpdatedObjectInfo impl
    • passes a copy of the updated object through any provided transforming functions and returns it when asked
    • builds UID preconditions from the updated object if they can be extracted
  • pkg/apiserver/resthandler.go
    • Reworks update and patch operations to give old objects to admission
  • pkg/registry/generic/registry/store.go
    • Calls UpdatedObject() inside GuaranteedUpdate so it can provide the old object

Todo:

  • Update rest.Update interface:
    • Given the name of the object being updated
    • To get the updated object data, the rest storage must pass the current object (fetched using the name) to an UpdatedObject(ctx, oldObject) (newObject, error) func. This is typically done inside a GuaranteedUpdate call.
  • Add old object to admission attributes interface
  • Update resthandler Update to move admission into the UpdatedObject() call
  • Update resthandler Patch to move the patch application and admission into the UpdatedObject() call
  • Add resttest tests to make sure oldObj is correctly passed to UpdatedObject(), and errors propagate back up

Follow-up:

  • populate oldObject in admission for delete operations?
  • update quota plugin to use GetOldObject() in admission attributes
  • admission plugin to gate ownerReference modification on delete permission
  • Decide how to handle preconditions (does that belong in the storage layer or in the resthander layer?)

@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels May 18, 2016
@liggitt liggitt force-pushed the update-admission branch from fa3386e to aca50af Compare May 19, 2016 04:17
@k8s-github-robot k8s-github-robot removed the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label May 19, 2016
@liggitt liggitt force-pushed the update-admission branch 4 times, most recently from e718eb0 to 91b5e04 Compare May 20, 2016 20:58
@liggitt
Copy link
Copy Markdown
Member Author

liggitt commented May 20, 2016

cc @deads2k @smarterclayton @lavalamp @caesarxuchao (related to discussion on plumbing for protecting ownerReferences)

@derekwaynecarr PTAL at admission-related bits
@deads2k PTAL at resthandler patch bits

@liggitt liggitt force-pushed the update-admission branch from 91b5e04 to 015d3ae Compare May 20, 2016 21:23
@k8s-github-robot k8s-github-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 20, 2016
@liggitt liggitt force-pushed the update-admission branch from 015d3ae to d8c78d6 Compare May 21, 2016 01:22
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This resolves a TODO inside the generic store that noted that all sorts of things in the updated object got mutated in BeforeCreate. It also exposed several tests that only passed because of side-effect modifications on the object passed to Update that made later DeepEqual comparisons pass.

@liggitt liggitt force-pushed the update-admission branch 3 times, most recently from 434f058 to 3f6c11c Compare May 21, 2016 20:58
@liggitt liggitt changed the title WIP - plumb Update resthandler to allow old/new comparisons in admission plumb Update resthandler to allow old/new comparisons in admission May 21, 2016
@liggitt liggitt added this to the v1.3 milestone May 21, 2016
@liggitt liggitt added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label May 21, 2016
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 21, 2016
@liggitt liggitt added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels May 22, 2016
@liggitt liggitt force-pushed the update-admission branch from 3f6c11c to cec2bd9 Compare May 22, 2016 01:09
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 22, 2016
@liggitt liggitt force-pushed the update-admission branch from cec2bd9 to ad659f9 Compare May 22, 2016 02:25
@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 23, 2016
@liggitt liggitt force-pushed the update-admission branch from 3884419 to 756c6ef Compare May 23, 2016 20:14
@liggitt liggitt added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 23, 2016
@liggitt
Copy link
Copy Markdown
Member Author

liggitt commented May 23, 2016

squashed

@lavalamp
Copy link
Copy Markdown
Contributor

This is a huge change which I'm just noticing now-- how important for 1.3 is this?

@caesarxuchao some of your change is overlapping this change. Can you look over this so at least someone from here will have read this closely?

@smarterclayton
Copy link
Copy Markdown
Contributor

smarterclayton commented May 23, 2016 via email

@caesarxuchao
Copy link
Copy Markdown
Contributor

Sure. I'm taking a look.

@smarterclayton
Copy link
Copy Markdown
Contributor

The change looks a lot worse than it is.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A unrelated question, does anyone know why the folder is called "controller" instead of "replicationcontroller"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

probably just cruft

@liggitt
Copy link
Copy Markdown
Member Author

liggitt commented May 24, 2016

@k8s-bot unit test this issue #23822

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you keep this logic out of the tryUpdate function? It doesn't need to be rerun in every retry. I think you can get the obj by objInfo.UpdatedObject(ctx, nil).

Copy link
Copy Markdown
Member Author

@liggitt liggitt May 24, 2016

Choose a reason for hiding this comment

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

no, this check is not expensive, and I definitely don't want to call UpdatedObject with a nil oldObj (or even call it multiple times unnecessarily). in Patch API calls, passing in the old object is how the new object is determined, and the admission chain now lives in that call as well.

There are unit tests in place in resttest.go to make sure the old object passed to UpdatedObject() is actually the old object from storage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@liggitt, I realized if obj is not available until calling into the storage layer, I don't know how to rebase my PR onto yours: https://github.com/kubernetes/kubernetes/pull/25599/files#diff-543310447bdc03ffceba5cf23a04be97R313

Do you have any suggestions?

@liggitt
Copy link
Copy Markdown
Member Author

liggitt commented May 24, 2016

@k8s-bot test this issue #22655

Add OldObject to admission attributes

Update resthandler Patch/Update admission plumbing
@liggitt liggitt force-pushed the update-admission branch from 756c6ef to 29252ac Compare May 24, 2016 01:11
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 24, 2016
@liggitt
Copy link
Copy Markdown
Member Author

liggitt commented May 24, 2016

added requested godoc

@liggitt liggitt added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 24, 2016
@k8s-bot
Copy link
Copy Markdown

k8s-bot commented May 24, 2016

GCE e2e build/test passed for commit 29252ac.

@k8s-github-robot
Copy link
Copy Markdown

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 5303794 into kubernetes:master May 24, 2016
@liggitt liggitt deleted the update-admission branch June 15, 2016 03:39
k8s-github-robot pushed a commit that referenced this pull request Jun 25, 2016
Automatic merge from submit-queue

Add WrapUpdatedObjectInfo helper

This makes it easier to attach checks/transformations to the updated object in storage Update functions, while still keeping the data flow intact (so admission, patch, and other injected checks continue to work as intended), without needing to do anything tricky to get the updated object out of the UpdatedObjectInfo introduced in #25787

This is especially useful when one storage is delegating to another, but wants its checks to be run in the heart of the eventual GuaranteedUpdate call.
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. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. 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.

8 participants