summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorzhengxinwei <zhengxinwei@huawei.com>2023-07-22 14:55:12 +0800
committerzhengxinwei <zhengxinwei@huawei.com>2023-10-07 09:46:55 +0800
commitaa3ba72d383d125ec3d84783a539d5b0d4c5c62c (patch)
treecac86dfb50fb6608e1b77c2e722d0661593fdabf /pkg
parentMerge pull request #5040 from Onion-of-dreamed/fix/without-mqtt-tag (diff)
downloadkubeedge-aa3ba72d383d125ec3d84783a539d5b0d4c5c62c.tar.gz
metaserver support pass through API, open /version path
Signed-off-by: zhengxinwei <zhengxinwei@huawei.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/metaserver/key.go5
-rw-r--r--pkg/metaserver/key_test.go5
-rw-r--r--pkg/util/pass-through/pass_through.go16
-rw-r--r--pkg/util/pass-through/pass_through_test.go36
4 files changed, 61 insertions, 1 deletions
diff --git a/pkg/metaserver/key.go b/pkg/metaserver/key.go
index bb0691e81..fcbfc8ee1 100644
--- a/pkg/metaserver/key.go
+++ b/pkg/metaserver/key.go
@@ -56,9 +56,12 @@ func KeyFuncObj(obj runtime.Object) (string, error) {
// KeyFuncReq generate key from req context
func KeyFuncReq(ctx context.Context, _ string) (string, error) {
info, ok := apirequest.RequestInfoFrom(ctx)
- if !ok || !info.IsResourceRequest {
+ if !ok {
return "", fmt.Errorf("no request info in context")
}
+ if !info.IsResourceRequest {
+ return info.Path, nil
+ }
group := ""
switch info.APIPrefix {
diff --git a/pkg/metaserver/key_test.go b/pkg/metaserver/key_test.go
index f1d2c0b3d..d1829ddfa 100644
--- a/pkg/metaserver/key_test.go
+++ b/pkg/metaserver/key_test.go
@@ -115,6 +115,9 @@ func TestKeyFuncReq(t *testing.T) {
// api version identification
{"POST", "/apis/extensions/v1beta3/namespaces/other/pods", "create", "api", "extensions", "v1beta3", "other", "pods", "", "", []string{"pods"}},
+
+ // non-resource api pass through
+ {method: "GET", url: "/version"},
}
stdResult := []string{
"/core/v1/namespaces/null/null",
@@ -146,6 +149,8 @@ func TestKeyFuncReq(t *testing.T) {
"/extensions/v1/pods/other/null",
"/extensions/v1beta3/pods/other/null",
+
+ "/version",
}
resolver := newTestRequestInfoResolver()
for k, v := range Cases {
diff --git a/pkg/util/pass-through/pass_through.go b/pkg/util/pass-through/pass_through.go
new file mode 100644
index 000000000..225512546
--- /dev/null
+++ b/pkg/util/pass-through/pass_through.go
@@ -0,0 +1,16 @@
+package passthrough
+
+type passRequest string
+
+const (
+ versionRequest passRequest = "/version::get"
+)
+
+var passThroughMap = map[passRequest]bool{
+ versionRequest: true,
+}
+
+// IsPassThroughPath determining whether the uri can be passed through
+func IsPassThroughPath(path, verb string) bool {
+ return passThroughMap[passRequest(path+"::"+verb)]
+}
diff --git a/pkg/util/pass-through/pass_through_test.go b/pkg/util/pass-through/pass_through_test.go
new file mode 100644
index 000000000..ddbd21b02
--- /dev/null
+++ b/pkg/util/pass-through/pass_through_test.go
@@ -0,0 +1,36 @@
+package passthrough
+
+import "testing"
+
+func TestIsPassThroughPath(t *testing.T) {
+ tests := []struct {
+ name string
+ path string
+ verb string
+ want bool
+ }{
+ {
+ name: "/healthz::get is not pass through path",
+ path: "/healthz",
+ verb: "get",
+ want: false,
+ }, {
+ name: "/version::post is not pass through path",
+ path: "/version",
+ verb: "post",
+ want: false,
+ }, {
+ name: "/version::get is pass through path",
+ path: "/version",
+ verb: "get",
+ want: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := IsPassThroughPath(tt.path, tt.verb); got != tt.want {
+ t.Errorf("IsPassThroughPath() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}