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

Remove layers of indirection between apiinstaller and resthandler #4263

Merged
merged 5 commits into from
Feb 12, 2015

Conversation

smarterclayton
Copy link
Contributor

Make the RESTHandler feel more go-restful, set the stage for adding
new types of subresource collections.

Extracted from #4248 (which is about status)

@smarterclayton smarterclayton force-pushed the simplify_apiserver branch 2 times, most recently from 0bc79c9 to 56dd906 Compare February 9, 2015 23:35
@mbforbes
Copy link
Contributor

@smarterclayton thoughts on who might be good to review?

@smarterclayton
Copy link
Contributor Author

Nikhil or anyone who wants to get more involved in the api server, @davidopp maybe

On Feb 9, 2015, at 7:04 PM, Maxwell Forbes notifications@github.com wrote:

@smarterclayton thoughts on who might be good to review?


Reply to this email directly or view it on GitHub.

@mbforbes
Copy link
Contributor

Nikhil for now, feel free to reassign---thanks!

@smarterclayton
Copy link
Contributor Author

I've got another commit coming to this pull to remove <-chan apiserver.RESTResult. Will make it so that we can reuse the REST storage in many contexts without having to have async behavior. In the future, if we want to do cancellation we'll be doing it through the api.Context stuff.

@smarterclayton
Copy link
Contributor Author

@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.

@bgrant0607
Copy link
Member

Awesome. Thanks. Will take a look, though I'm in meetings all day, so don't block on me.

@smarterclayton
Copy link
Contributor Author

Rest will look a lot like the client interface again.

On Feb 10, 2015, at 11:39 AM, Brian Grant notifications@github.com wrote:

Awesome. Thanks. Will take a look, though I'm in meetings all day, so don't block on me.


Reply to this email directly or view it on GitHub.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

@bgrant0607
Copy link
Member

Lots of good stuff here. LGTM.

@nikhiljindal Any comments?

@smarterclayton
Copy link
Contributor Author

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.

@nikhiljindal
Copy link
Contributor

I am out of office till Thursday.
Please do not wait for me.
On Feb 10, 2015 10:04 AM, "Clayton Coleman" notifications@github.com
wrote:

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.


Reply to this email directly or view it on GitHub
#4263 (comment)
.

@smarterclayton smarterclayton force-pushed the simplify_apiserver branch 3 times, most recently from 587ba38 to 69397eb Compare February 10, 2015 21:26
@smarterclayton
Copy link
Contributor Author

I've got a mostly clean e2e run, trying to figure out whether the e2e one is a flake or not

@smarterclayton smarterclayton force-pushed the simplify_apiserver branch 2 times, most recently from 92741b6 to eb15a81 Compare February 10, 2015 22:21
@smarterclayton
Copy link
Contributor Author

I have seen all of the different tests in e2e pass, just not in one run.

@smarterclayton smarterclayton deleted the simplify_apiserver branch February 11, 2015 02:21
@smarterclayton smarterclayton restored the simplify_apiserver branch February 11, 2015 21:20
@smarterclayton
Copy link
Contributor Author

@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.
@bgrant0607
Copy link
Member

Thanks @smarterclayton. Looking at this now.

canonicalPrefix: a.restHandler.canonicalPrefix,
selfLinker: a.restHandler.selfLinker,
apiRequestInfoResolver: a.restHandler.apiRequestInfoResolver,
storage: a.group.storage,
Copy link
Member

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?

Copy link
Contributor Author

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,
    
  •   storage: a.group.storage,
    
    Why doesn't it make sense to just pass a.group, as opposed to the individual fields? Because they're all private, currently?


Reply to this email directly or view it on GitHub.

@nikhiljindal
Copy link
Contributor

Lgtm thanks!

@nikhiljindal nikhiljindal added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 12, 2015
@@ -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
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 still a Go newbie, I guess. What does this do? I don't see a definition of namespace.

Copy link
Contributor Author

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) {
    
  •       return
    
    I'm still a Go newbie, I guess. What does this do? I don't see a definition of namespace.


Reply to this email directly or view it on GitHub.

Copy link
Contributor

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

Copy link
Contributor Author

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 RESTStorage

    itemPath := 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

Copy link
Contributor

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.

@bgrant0607
Copy link
Member

LGTM, also.
Note: This fixes #2031.

@smarterclayton
Copy link
Contributor Author

Pushed one more commit to clearly return an error if name is empty.

smarterclayton added a commit that referenced this pull request Feb 12, 2015
Remove layers of indirection between apiinstaller and resthandler
@smarterclayton smarterclayton merged commit 0a2d713 into kubernetes:master Feb 12, 2015
@smarterclayton
Copy link
Contributor Author

@nikhiljindal opened #4387 to handle rename of "TryAgainLater" to "ServerTimeout" (as distinct from RequestTimeout and GatewayTimeout)

@smarterclayton
Copy link
Contributor Author

This broke cross namespace queries (for which we apparently have zero test cases). Fix incoming...

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants