Change:
is always using the cross namespace context. This needs to be fixed to support scoped watches.

Discussion:
created *Simple // These are set when Watch is called <del> fakeWatch                *watch.FakeWatcher requestedLabelSelector   labels.Selector requestedFieldSelector   labels.Selector requestedResourceVersion string </del> <ins> fakeWatch                  *watch.FakeWatcher requestedLabelSelector     labels.Selector requestedFieldSelector     labels.Selector requestedResourceVersion   string requestedResourceNamespace string </ins> // The id requested, and location to return for ResourceLocation requestedResourceLocationID string

storage.requestedLabelSelector = label storage.requestedFieldSelector = field storage.requestedResourceVersion = resourceVersion <ins> storage.requestedResourceNamespace = api.Namespace(ctx) </ins> if err := storage.errors["watch"]; err != nil { return nil, err }

// Implement Redirector. func (storage *SimpleRESTStorage) ResourceLocation(ctx api.Context, id string) (string, error) { // validate that the namespace context on the request matches the expected input <del> requestedResourceNamespace := api.Namespace(ctx) if storage.expectedResourceNamespace != requestedResourceNamespace { return "", fmt.Errorf("Expected request namespace %s, but got namespace %s", storage.expectedResourceNamespace, requestedResourceNamespace) </del> <ins> storage.requestedResourceNamespace = api.Namespace(ctx) if storage.expectedResourceNamespace != storage.requestedResourceNamespace { return "", fmt.Errorf("Expected request namespace %s, but got namespace %s", storage.expectedResourceNamespace, storage.requestedResourceNamespace) </ins> } storage.requestedResourceLocationID = id if err := storage.errors["resourceLocation"]; err != nil {

// ServeHTTP processes watch requests. func (h *WatchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { ctx := api.NewContext() <ins> namespace := req.URL.Query().Get("namespace") if len(namespace) > 0 { ctx = api.WithNamespace(ctx, namespace) } </ins> parts := splitPath(req.URL.Path) if len(parts) < 1 || req.Method != "GET" { notFound(w, req)

"testing" "code.google.com/p/go.net/websocket" <ins> "github.com/GoogleCloudPlatform/kubernetes/pkg/api" </ins> "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/watch" )

resourceVersion string labelSelector   string fieldSelector   string <ins> namespace       string </ins> }{ { rawQuery:        "resourceVersion=1234", resourceVersion: "1234", labelSelector:   "", fieldSelector:   "", <ins> namespace:       api.NamespaceAll, </ins> }, { <del> rawQuery:        "resourceVersion=314159&fields=Host%3D&labels=name%3Dfoo", </del> <ins> rawQuery:        "namespace=default&resourceVersion=314159&fields=Host%3D&labels=name%3Dfoo", </ins> resourceVersion: "314159", labelSelector:   "name=foo", fieldSelector:   "Host=", <ins> namespace:       api.NamespaceDefault, </ins> }, { <del> rawQuery:        "fields=ID%3dfoo&resourceVersion=1492", </del> <ins> rawQuery:        "namespace=watchother&fields=ID%3dfoo&resourceVersion=1492", </ins> resourceVersion: "1492", labelSelector:   "", fieldSelector:   "ID=foo", <ins> namespace:       "watchother", </ins> }, { rawQuery:        "", resourceVersion: "", labelSelector:   "", fieldSelector:   "", <ins> namespace:       api.NamespaceAll, </ins> }, }

simpleStorage.requestedLabelSelector = nil simpleStorage.requestedFieldSelector = nil simpleStorage.requestedResourceVersion = "5" // Prove this is set in all cases <ins> simpleStorage.requestedResourceNamespace = "" </ins> dest.RawQuery = item.rawQuery resp, err := http.Get(dest.String()) if err != nil {

continue } resp.Body.Close() <ins> if e, a := item.namespace, simpleStorage.requestedResourceNamespace; e != a { t.Errorf("%v: expected %v, got %v", item.rawQuery, e, a) } </ins> if e, a := item.resourceVersion, simpleStorage.requestedResourceVersion; e != a { t.Errorf("%v: expected %v, got %v", item.rawQuery, e, a) }