Repository: clusternet/clusternet
Pull request #62 (2021-08-11 06:58:43)

lower priority of shadow GVK
<!--  Thanks for sending a pull request!

-->

#### What type of PR is this?

#### What this PR does / why we need it:
kind/bug

#### Which issue(s) this PR fixes:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #

#### Special notes for your reviewer:



Patch:
diff --git a/deploy/hub/clusternet_hub_apiservice.yaml b/deploy/hub/clusternet_hub_apiservice.yaml
index fa04bf3..e544c8f 100644
--- a/deploy/hub/clusternet_hub_apiservice.yaml
+++ b/deploy/hub/clusternet_hub_apiservice.yaml
@@ -6,7 +6,7 @@ spec:
   insecureSkipTLSVerify: true
   group: proxies.clusternet.io
   groupPriorityMinimum: 1000
-  versionPriority: 15
+  versionPriority: 100
   service:
     name: clusternet-hub
     namespace: clusternet-system
@@ -20,8 +20,8 @@ metadata:
 spec:
   insecureSkipTLSVerify: true
   group: shadow
-  groupPriorityMinimum: 1000
-  versionPriority: 15
+  groupPriorityMinimum: 1
+  versionPriority: 1
   service:
     name: clusternet-hub
     namespace: clusternet-system
diff --git a/pkg/wrappers/clientgo/wrapper.go b/pkg/wrappers/clientgo/wrapper.go
index 2a7bc6d..5c7becc 100644
--- a/pkg/wrappers/clientgo/wrapper.go
+++ b/pkg/wrappers/clientgo/wrapper.go
@@ -31,7 +31,7 @@ var (
 	// regex matches '/api/v1/{path}'
 	apiv1Regex = regexp.MustCompile(`^(/api/v1)/(.*)`)
 	// regex matches "/apis/{group}/{version}/{path}"
-	apisRegex = regexp.MustCompile(`^(/apis/\w*/v\w*.)/(.*)`)
+	apisRegex = regexp.MustCompile(`^(/apis/.*/v\w*.)/(.*)`)
 	// regex matches "/apis/xxx.clusternet.io/{version}/{path}"
 	clusternetAPIsRegex = regexp.MustCompile(`^(/apis/\w*\.clusternet\.io/v\w*.)/(.*)`)
 


Test patch:
diff --git a/pkg/wrappers/clientgo/wrapper_test.go b/pkg/wrappers/clientgo/wrapper_test.go
index c6d6638..f3ec8fa 100644
--- a/pkg/wrappers/clientgo/wrapper_test.go
+++ b/pkg/wrappers/clientgo/wrapper_test.go
@@ -157,6 +157,18 @@ func TestNormalizeLocation(t *testing.T) {
 			requestURL:    "https://my.k8s.io/apis/far.clusternet.io/v1bar/namespaces/boo/foos/abc?fieldSelector=metadata.name%3Dabc&resourceVersion=0&watch=true",
 			normalizedURL: "https://my.k8s.io/apis/far.clusternet.io/v1bar/namespaces/boo/foos/abc?fieldSelector=metadata.name%3Dabc&resourceVersion=0&watch=true",
 		},
+		{
+			name:          "clusternet - support crd with group samplecontroller.k8s.io",
+			host:          "https://my.k8s.io",
+			requestURL:    "https://my.k8s.io/apis/samplecontroller.k8s.io/v1alpha1/namespaces/default/foos",
+			normalizedURL: "https://my.k8s.io/apis/shadow/v1alpha1/namespaces/default/foos",
+		},
+		{
+			name:          "clusternet - support crd with group a.foo",
+			host:          "https://my.k8s.io",
+			requestURL:    "https://my.k8s.io/apis/a.foo/v1alpha1/namespaces/default/foos?fieldSelector=metadata.name%3Dabc&resourceVersion=0&watch=true",
+			normalizedURL: "https://my.k8s.io/apis/shadow/v1alpha1/namespaces/default/foos?fieldSelector=metadata.name%3Dabc&resourceVersion=0&watch=true",
+		},
 
 		{
 			name:          "apiv1 - host with trailing slash",