Merge pull request #46127 from liggitt/list-unwatchable

Automatic merge from submit-queue (batch tested with PRs 45518, 46127, 46146, 45932, 45003)

Return MethodNotSupported when accessing unwatcheable resource with ?watch=true

Currently, if a RESTStorage does not implement Watch(), accessing the list endpoint with ?watch=true will call List, with ListOptions.Watch=true. It should return a MethodNotSupported error.
This commit is contained in:
Kubernetes Submit Queue 2017-05-25 11:46:01 -07:00 committed by GitHub
commit 6a8ea80ecb

View File

@ -301,7 +301,11 @@ func ListResource(r rest.Lister, rw rest.Watcher, scope RequestScope, forceWatch
opts.FieldSelector = nameSelector
}
if (opts.Watch || forceWatch) && rw != nil {
if opts.Watch || forceWatch {
if rw == nil {
scope.err(errors.NewMethodNotSupported(scope.Resource.GroupResource(), "watch"), w, req)
return
}
// TODO: Currently we explicitly ignore ?timeout= and use only ?timeoutSeconds=.
timeout := time.Duration(0)
if opts.TimeoutSeconds != nil {