Repository: kubeedge/kubeedge (Go)

Issue:
/api/v1/namespaces/kube-system is not correctly handled in metamanager.
<!-- Please use this template while reporting a bug and provide as much info as possible. Thanks!-->
**What happened**:

The original request from `cilium-agent`:
```
GET /api/v1/namespaces/kube-system HTTP/1.1
Host: 127.0.0.1:10550
User-Agent: cilium-agent/1.12.0 9447cd1 2022-07-19T12:22:00+02:00 go version go1.18.4 linux/amd64
Accept: application/vnd.kubernetes.protobuf, */*
Accept-Encoding: gzip
```
But `/api/v1/namespaces/kube-system` is turned into `/api/v1/namespaces/kube-system/namespaces/kube-system` after the message from edge side is parsed in `func ParseKey(key string) (gvr schema.GroupVersionResource, namespace string, name string)` of `github.com/kubeedge/kubeedge/pkg/metaserver/key.go`.  
As a result, api cannot be found and 404 error is returned.  

K8s apiserver's log:
```
I0613 03:12:58.780785       1 queueset.go:375] QS(workload-low): Dispatching request &request.RequestInfo{IsResourceRequest:true, Path:"/api/v1/namespaces/kube-system/namespaces/kube-system", Verb:"get", APIPrefix:"api", APIGroup:"", APIVersion:"v1", Namespace:"kube-system", Resource:"namespaces", Subresource:"", Name:"kube-system", Parts:[]string{"namespaces", "kube-system"}} &user.DefaultInfo{Name:"system:serviceaccount:kubeedge:cloudcore", UID:"7f505cc7-d8bf-4281-a93b-f83365548605", Groups:[]string{"system:serviceaccounts", "system:serviceaccounts:kubeedge", "system:authenticated"}, Extra:map[string][]string{"authentication.kubernetes.io/pod-name":[]string{"cloudcore-5876c76687-zcj2g"}, "authentication.kubernetes.io/pod-uid":[]string{"8d87442a-455d-47fe-94f9-3791ed639d22"}}} from its queue
I0613 03:12:58.782860       1 handler.go:153] kube-aggregator: GET "/api/v1/namespaces/kube-system/namespaces/kube-system" satisfied by nonGoRestful
I0613 03:12:58.782944       1 pathrecorder.go:247] kube-aggregator: "/api/v1/namespaces/kube-system/namespaces/kube-system" satisfied by prefix /api/
I0613 03:12:58.782991       1 handler.go:143] kube-apiserver: GET "/api/v1/namespaces/kube-system/namespaces/kube-system" satisfied by gorestful with webservice /api/v1
I0613 03:12:58.783609       1 httplog.go:109] "HTTP" verb="GET" URI="/api/v1/namespaces/kube-system/namespaces/kube-system" latency="16.519337ms" userAgent="cloudcore/v0.0.0 (linux/amd64) kubernetes/$Format" audit-ID="a7b2cd87-20de-4a55-8a50-535ce93f3841" srcIP="172.20.0.1:54482" resp=404
```

**What you expected to happen**:

`/api/v1/namespaces/kube-system` is handled correctly.

**How to reproduce it (as minimally and precisely as possible)**:

Enable `metaManager/metaServer` and `serviceBus` on edge node.  
Enable `dynamicController` of `cloudcore`.  
Deploy a resource with an application which requests for `GET /api/v1/namespaces/kube-system` on edge side.  

**Environment**:
- Kubernetes version: 1.22.16
- KubeEdge version: v1.12.1



Discussion:
we have a PR to fix this https://github.com/kubeedge/kubeedge/pull/4756
@wackxu Hi, I've tried the modification in the PR, it does not cover this issue. Maybe we need the following change as well.

```
@@ -139,10 +144,15 @@ func ParseKey(key string) (gvr schema.GroupVersionResource, namespace string, na
                return
        }
 
-       gvr = gv.WithResource(slices[resourceIndex])
-       namespace = slices[namespaceIndex]
-       if namespace == v2.NullNamespace {
+       gvr = gv.WithResource(slices[resourceIndex]     )
+       // if the request resource is namespaces, set the ns to null in the key
+       if slices[resourceIndex] == "namespaces" {
                namespace = ""
+       } else {
+               namespace = slices[namespaceIndex]
+               if namespace == v2.NullNamespace {
+                       namespace = ""
+               }
        }
        name = slices[nameIndex]
        if name == v2.NullName {
```
propbably we need to reopen this in favor of https://github.com/kubeedge/kubeedge/issues/4819#issuecomment-1600509188
`message_dispatcher` seems also have some problem related to `namespace`.

```
E0710 14:39:49.017833       1 message_dispatcher.go:298] "Failed to create objectSync" err="namespaces \"null\" not found" objectSyncName="pc-k8s-192-168-0-121.6e3d70fd-21ad-452b-aa3a-dfebb12e5cbf" resourceNamespace="null" resourceName="kubeedge"
E0710 14:39:49.083759       1 message_dispatcher.go:298] "Failed to create objectSync" err="namespaces \"null\" not found" objectSyncName="pc-k8s-192-168-0-121.5165f4dc-9cec-468e-b2e7-3594854a9235" resourceNamespace="null" resourceName="kube-system"
E0710 14:39:49.157691       1 message_dispatcher.go:298] "Failed to create objectSync" err="namespaces \"null\" not found" objectSyncName="pc-k8s-192-168-0-121.15c493e7-4d73-4092-ba42-a8d19059aa29" resourceNamespace="null" resourceName="kube-public"
E0710 14:39:49.214988       1 message_dispatcher.go:298] "Failed to create objectSync" err="namespaces \"null\" not found" objectSyncName="pc-k8s-192-168-0-121.91442b36-61a7-4539-b05b-0067631f2620" resourceNamespace="null" resourceName="kube-node-lease"
```

The resource in the message is: `node/pc-k8s-192-168-0-121/null/namespace/kube-system`.



Patch:
diff --git a/pkg/metaserver/key.go b/pkg/metaserver/key.go
index 3901b7b0ff4..710752a198d 100644
--- a/pkg/metaserver/key.go
+++ b/pkg/metaserver/key.go
@@ -76,6 +76,11 @@ func KeyFuncReq(ctx context.Context, _ string) (string, error) {
 	resource := info.Resource
 	namespace := info.Namespace
 	name := info.Name
+
+	// if the request resource is namespaces, set the ns to null in the key
+	if resource == "namespaces" {
+		namespace = v2.NullNamespace
+	}
 	if namespace == "" {
 		namespace = v2.NullNamespace
 	}
diff --git a/pkg/metaserver/util/util.go b/pkg/metaserver/util/util.go
index 437cd8ad851..8fdf5bdc2dd 100644
--- a/pkg/metaserver/util/util.go
+++ b/pkg/metaserver/util/util.go
@@ -49,6 +49,7 @@ func UnsafeResourceToKind(r string) string {
 		"endpoints":                    "Endpoints",
 		"endpointslices":               "EndpointSlice",
 		"nodes":                        "Node",
+		"namespaces":                   "Namespace",
 		"services":                     "Service",
 		"podstatus":                    "PodStatus",
 		"nodestatus":                   "NodeStatus",


Test patch:
diff --git a/pkg/metaserver/key_test.go b/pkg/metaserver/key_test.go
index 0643e9a3e6b..f1d2c0b3dab 100644
--- a/pkg/metaserver/key_test.go
+++ b/pkg/metaserver/key_test.go
@@ -118,7 +118,7 @@ func TestKeyFuncReq(t *testing.T) {
 	}
 	stdResult := []string{
 		"/core/v1/namespaces/null/null",
-		"/core/v1/namespaces/other/other", //a namespace called other
+		"/core/v1/namespaces/null/other", //a namespace called other
 
 		"/core/v1/pods/other/null",
 		"/core/v1/pods/other/foo",