From 5e01c804fd01f76c29ec6ce109f65b811e6aef1a Mon Sep 17 00:00:00 2001 From: derekwaynecarr Date: Fri, 17 Oct 2014 15:08:24 -0400 Subject: [PATCH] Fixup apiserver proxy to be namespace aware --- docs/namespaces.md | 2 ++ pkg/apiserver/proxy.go | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/namespaces.md b/docs/namespaces.md index 6dc9729fb5..b80c68259d 100644 --- a/docs/namespaces.md +++ b/docs/namespaces.md @@ -116,6 +116,8 @@ The k8s API server will associate a resource with a *Namespace* if not populated of the incoming request. If the *Namespace* of the resource being created, or updated does not match the *Namespace* on the request, then the k8s API server will reject the request. +TODO: Update to discuss k8s api server proxy patterns + ## k8s storage A namespace provides a unique identifier space and therefore must be in the storage path of a resource. diff --git a/pkg/apiserver/proxy.go b/pkg/apiserver/proxy.go index 51e3a51866..a8abe07826 100644 --- a/pkg/apiserver/proxy.go +++ b/pkg/apiserver/proxy.go @@ -77,7 +77,14 @@ type ProxyHandler struct { } func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - ctx := api.NewContext() + // use the default namespace to address the service + ctx := api.NewDefaultContext() + // if not in default namespace, provide the query parameter + // TODO this will need to go in the path in the future and not as a query parameter + namespace := req.URL.Query().Get("namespace") + if len(namespace) > 0 { + ctx = api.WithNamespace(ctx, namespace) + } parts := strings.SplitN(req.URL.Path, "/", 3) if len(parts) < 2 { notFound(w, req)