-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Remove layers of indirection between apiinstaller and resthandler #4263
Remove layers of indirection between apiinstaller and resthandler #4263
Conversation
0bc79c9
to
56dd906
Compare
@smarterclayton thoughts on who might be good to review? |
Nikhil or anyone who wants to get more involved in the api server, @davidopp maybe
|
Nikhil for now, feel free to reassign---thanks! |
56dd906
to
60f596b
Compare
I've got another commit coming to this pull to remove |
@bgrant0607 the combination of this change (and the proposed) will dramatically simplify the generic code path - in my other pull I have pods mostly refactored, and the amount of custom code is dropping fast. |
Awesome. Thanks. Will take a look, though I'm in meetings all day, so don't block on me. |
Rest will look a lot like the client interface again.
|
@@ -961,7 +1068,7 @@ func TestCreateTimeout(t *testing.T) { | |||
|
|||
simple := &Simple{Other: "foo"} | |||
data, _ := codec.Encode(simple) | |||
itemOut := expectApiStatus(t, "POST", server.URL+"/prefix/version/foo?timeout=4ms", data, http.StatusAccepted) | |||
itemOut := expectApiStatus(t, "POST", server.URL+"/prefix/version/foo?timeout=4ms", data, 504) |
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.
Could you please define a constant for 504 here:
https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/api/errors/errors.go#L30
Lots of good stuff here. LGTM. @nikhiljindal Any comments? |
60f596b
to
8fe356e
Compare
Ok, this is ready for review (running e2e now). This completely removes the RESTStorage interfaces from having to know about asynchronous behavior, which means those APIs now look like client apis, which means that we can much more cleanly substitute registry for client APIs again. This sets the stage for generic registries which can now service RESTStorage requests directly without having to wrap async behavior. |
I am out of office till Thursday.
|
587ba38
to
69397eb
Compare
I've got a mostly clean e2e run, trying to figure out whether the e2e one is a flake or not |
92741b6
to
eb15a81
Compare
I have seen all of the different tests in e2e pass, just not in one run. |
@brendandburns if you have time to review I would appreciate it - this cleanup is important for getting to a single etcd / registry / rest implementation. |
Make the RESTHandler feel more go-restful, set the stage for adding new types of subresource collections.
Also make sure all POST operations return 201 by default. Removes the remainder of the asych logic in RESTStorage and leaves it up to the API server to expose that behavior.
eb15a81
to
26f08b7
Compare
Thanks @smarterclayton. Looking at this now. |
canonicalPrefix: a.restHandler.canonicalPrefix, | ||
selfLinker: a.restHandler.selfLinker, | ||
apiRequestInfoResolver: a.restHandler.apiRequestInfoResolver, | ||
storage: a.group.storage, |
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.
Why doesn't it make sense to just pass a.group, as opposed to the individual fields? Because they're all private, currently?
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.
Yeah, I think I'd like to refactor watch and redirect like the other methods, at which point group can be refactored out as well.
On Feb 11, 2015, at 7:34 PM, Brian Grant notifications@github.com wrote:
In pkg/apiserver/api_installer.go:
@@ -49,16 +53,16 @@ func (a *APIInstaller) Install() (ws *restful.WebService, errors []error) {
// Initialize the custom handlers. watchHandler := (&WatchHandler{
storage: a.restHandler.storage,
codec: a.restHandler.codec,
canonicalPrefix: a.restHandler.canonicalPrefix,
selfLinker: a.restHandler.selfLinker,
apiRequestInfoResolver: a.restHandler.apiRequestInfoResolver,
Why doesn't it make sense to just pass a.group, as opposed to the individual fields? Because they're all private, currently?storage: a.group.storage,
—
Reply to this email directly or view it on GitHub.
Lgtm thanks! |
@@ -148,6 +171,19 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage | |||
|
|||
itemPath := path + "/{name}" | |||
nameParams := append(params, nameParam) | |||
namespaceFn = func(req *restful.Request) (namespace string, err error) { | |||
return |
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'm still a Go newbie, I guess. What does this do? I don't see a definition of namespace.
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.
Its a named return parameter, which have zero values to start.
However, this made me realize that empty names and namespaces (for namespaced scopes) must be rejected with an error. Will fix that.
On Feb 12, 2015, at 5:15 AM, Brian Grant notifications@github.com wrote:
In pkg/apiserver/api_installer.go:
@@ -148,6 +171,19 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
itemPath := path + "/{name}" nameParams := append(params, nameParam)
namespaceFn = func(req *restful.Request) (namespace string, err error) {
I'm still a Go newbie, I guess. What does this do? I don't see a definition of namespace.return
—
Reply to this email directly or view it on GitHub.
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.
Yuck. Naked returns in the middle of a large function are incredibly hard to read. See https://code.google.com/p/go-wiki/wiki/CodeReviewComments#Named_Result_Parameters
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.
Naked returns are okay if the function is a handful of lines.
I think these functions can be moved to static functions, they don't need to be closures. Will do that in a follow up.
----- Original Message -----
@@ -148,6 +171,19 @@ func (a *APIInstaller) registerResourceHandlers(path
string, storage RESTStorageitemPath := path + "/{name}" nameParams := append(params, nameParam)
namespaceFn = func(req *restful.Request) (namespace string, err error) {
return
Yuck. Naked returns in the middle of a large function are incredibly hard to
read. See
https://code.google.com/p/go-wiki/wiki/CodeReviewComments#Named_Result_Parameters
Reply to this email directly or view it on GitHub:
https://github.com/GoogleCloudPlatform/kubernetes/pull/4263/files#r24597352
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.
Right. It's difficult to tell at first glance that most (or all?) of the naked returns are inside tiny functions here.
LGTM, also. |
Pushed one more commit to clearly return an error if name is empty. |
Remove layers of indirection between apiinstaller and resthandler
@nikhiljindal opened #4387 to handle rename of "TryAgainLater" to "ServerTimeout" (as distinct from RequestTimeout and GatewayTimeout) |
This broke cross namespace queries (for which we apparently have zero test cases). Fix incoming... |
Make the RESTHandler feel more go-restful, set the stage for adding
new types of subresource collections.
Extracted from #4248 (which is about status)