From b52db8732b54fdd58e18f1271e30e39d7858ba8f Mon Sep 17 00:00:00 2001 From: hongming Date: Fri, 3 Jul 2020 17:05:31 +0800 Subject: [PATCH] fix: implicit workspace info in query Signed-off-by: hongming --- pkg/apiserver/request/requestinfo.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/apiserver/request/requestinfo.go b/pkg/apiserver/request/requestinfo.go index 7e0da4497..7b01e0f27 100644 --- a/pkg/apiserver/request/requestinfo.go +++ b/pkg/apiserver/request/requestinfo.go @@ -29,6 +29,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog" "kubesphere.io/kubesphere/pkg/api" + "kubesphere.io/kubesphere/pkg/constants" "net/http" "strings" @@ -193,6 +194,15 @@ func (r *RequestInfoFactory) NewRequestInfo(req *http.Request) (*RequestInfo, er } } + selector := req.URL.Query().Get("labelSelector") + // URL forms: /api/v1/watch/namespaces?labelSelector=kubesphere.io/workspace=system-workspace + if strings.HasPrefix(selector, workspaceSelectorPrefix) { + workspace := strings.TrimPrefix(selector, workspaceSelectorPrefix) + // URL forms: /api/v1/watch/namespaces?labelSelector=kubesphere.io/workspace==system-workspace + workspace = strings.TrimPrefix(workspace, "=") + requestInfo.Workspace = workspace + } + // URL forms: /namespaces/{namespace}/{kind}/*, where parts are adjusted to be relative to kind if currentParts[0] == "namespaces" { if len(currentParts) > 1 { @@ -291,10 +301,11 @@ func splitPath(path string) []string { } const ( - GlobalScope = "Global" - ClusterScope = "Cluster" - WorkspaceScope = "Workspace" - NamespaceScope = "Namespace" + GlobalScope = "Global" + ClusterScope = "Cluster" + WorkspaceScope = "Workspace" + NamespaceScope = "Namespace" + workspaceSelectorPrefix = constants.WorkspaceLabelKey + "=" ) func (r *RequestInfoFactory) resolveResourceScope(request RequestInfo) string {