Commit 31fc19ef authored by Clayton Coleman's avatar Clayton Coleman

Watching on invalid label/field selectors should error

parent c8244cd1
...@@ -54,17 +54,21 @@ func (h *WatchHandler) setSelfLinkAddName(obj runtime.Object, req *http.Request) ...@@ -54,17 +54,21 @@ func (h *WatchHandler) setSelfLinkAddName(obj runtime.Object, req *http.Request)
return h.selfLinker.SetSelfLink(obj, newURL.String()) return h.selfLinker.SetSelfLink(obj, newURL.String())
} }
func getWatchParams(query url.Values) (label, field labels.Selector, resourceVersion string) { func getWatchParams(query url.Values) (label, field labels.Selector, resourceVersion string, err error) {
if s, err := labels.ParseSelector(query.Get("labels")); err != nil { s, perr := labels.ParseSelector(query.Get("labels"))
label = labels.Everything() if perr != nil {
} else { err = perr
label = s return
} }
if s, err := labels.ParseSelector(query.Get("fields")); err != nil { label = s
field = labels.Everything()
} else { s, perr = labels.ParseSelector(query.Get("fields"))
field = s if perr != nil {
err = perr
return
} }
field = s
resourceVersion = query.Get("resourceVersion") resourceVersion = query.Get("resourceVersion")
return return
} }
...@@ -95,7 +99,11 @@ func (h *WatchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { ...@@ -95,7 +99,11 @@ func (h *WatchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return return
} }
if watcher, ok := storage.(ResourceWatcher); ok { if watcher, ok := storage.(ResourceWatcher); ok {
label, field, resourceVersion := getWatchParams(req.URL.Query()) label, field, resourceVersion, err := getWatchParams(req.URL.Query())
if err != nil {
errorJSON(err, h.codec, w)
return
}
watching, err := watcher.Watch(ctx, label, field, resourceVersion) watching, err := watcher.Watch(ctx, label, field, resourceVersion)
if err != nil { if err != nil {
errorJSON(err, h.codec, w) errorJSON(err, h.codec, w)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment