mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 13:42:02 +00:00
Move namespace from query param to path part
This commit is contained in:
@@ -78,35 +78,31 @@ type ProxyHandler struct {
|
||||
}
|
||||
|
||||
func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
// 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)
|
||||
namespace, kind, parts, err := KindAndNamespace(req)
|
||||
if err != nil {
|
||||
notFound(w, req)
|
||||
return
|
||||
}
|
||||
parts := strings.SplitN(req.URL.Path, "/", 3)
|
||||
ctx := api.WithNamespace(api.NewContext(), namespace)
|
||||
if len(parts) < 2 {
|
||||
notFound(w, req)
|
||||
return
|
||||
}
|
||||
resourceName := parts[0]
|
||||
id := parts[1]
|
||||
rest := ""
|
||||
if len(parts) == 3 {
|
||||
rest = parts[2]
|
||||
}
|
||||
storage, ok := r.storage[resourceName]
|
||||
storage, ok := r.storage[kind]
|
||||
if !ok {
|
||||
httplog.LogOf(req, w).Addf("'%v' has no storage object", resourceName)
|
||||
httplog.LogOf(req, w).Addf("'%v' has no storage object", kind)
|
||||
notFound(w, req)
|
||||
return
|
||||
}
|
||||
|
||||
redirector, ok := storage.(Redirector)
|
||||
if !ok {
|
||||
httplog.LogOf(req, w).Addf("'%v' is not a redirector", resourceName)
|
||||
httplog.LogOf(req, w).Addf("'%v' is not a redirector", kind)
|
||||
notFound(w, req)
|
||||
return
|
||||
}
|
||||
@@ -150,7 +146,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
proxy.Transport = &proxyTransport{
|
||||
proxyScheme: req.URL.Scheme,
|
||||
proxyHost: req.URL.Host,
|
||||
proxyPathPrepend: path.Join(r.prefix, resourceName, id),
|
||||
proxyPathPrepend: path.Join(r.prefix, "ns", namespace, kind, id),
|
||||
}
|
||||
proxy.FlushInterval = 200 * time.Millisecond
|
||||
proxy.ServeHTTP(w, newReq)
|
||||
|
Reference in New Issue
Block a user