You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/05/24 01:13:33 UTC

[GitHub] [apisix-ingress-controller] lingsamuel opened a new pull request #480: feat: support rewrite annotation

lingsamuel opened a new pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480


   Signed-off-by: Ling Samuel <li...@gmail.com>
   
   Please answer these questions before submitting a pull request
   
   - Why submit this pull request?
   - [ ] Bugfix
   - [x] New feature provided
   - [ ] Improve performance
   - [ ] Backport patches
   
   - Related issues
   
   ___
   ### New feature or improvement
   - Describe the details and related test reports.
   
   Support rewrite request by annotation.
   
   Note: because regex may contains comma, the regex require two annotations. 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tao12345666333 commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637670292



##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.

Review comment:
       ```suggestion
   // annotations about rewrite control to APISIX proxy-rewrite plugin.
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tokers commented on pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
tokers commented on pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#issuecomment-846674365


   @lingsamuel All files should carry the Apache License Header.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637821515



##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")

Review comment:
       This could be set to debug.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] codecov-commenter edited a comment on pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#issuecomment-846668725


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#480](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (710ed71) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/0bdd24b86ca109948e786f7f13f84bc1bd0fbc39?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (0bdd24b) will **decrease** coverage by `0.17%`.
   > The diff coverage is `0.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/graphs/tree.svg?width=650&height=150&src=pr&token=WPLQXPY3V0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #480      +/-   ##
   ==========================================
   - Coverage   37.04%   36.86%   -0.18%     
   ==========================================
     Files          47       47              
     Lines        3841     3857      +16     
   ==========================================
   - Hits         1423     1422       -1     
   - Misses       2233     2250      +17     
     Partials      185      185              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/kube/translation/annotations.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMuZ28=) | `36.36% <ø> (ø)` | |
   | [pkg/kube/translation/annotations/rewrite.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMvcmV3cml0ZS5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `26.69% <0.00%> (-0.35%)` | :arrow_down: |
   | [pkg/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2luZ3Jlc3MvY29udHJvbGxlci5nbw==) | `0.00% <0.00%> (ø)` | |
   | [test/e2e/e2e.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-dGVzdC9lMmUvZTJlLmdv) | | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [0bdd24b...710ed71](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637877150



##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")
+	rewriteTarget := e.GetStringAnnotation(_rewriteTarget)
+	rewriteTargetRegex := e.GetStringAnnotation(_rewriteTargetRegex)
+	rewriteTemplate := e.GetStringAnnotation(_rewriteTargetRegexTemplate)
+	if rewriteTarget != "" || rewriteTargetRegex != "" || rewriteTemplate != "" {

Review comment:
       OK, not a big deal.

##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")
+	rewriteTarget := e.GetStringAnnotation(_rewriteTarget)
+	rewriteTargetRegex := e.GetStringAnnotation(_rewriteTargetRegex)
+	rewriteTemplate := e.GetStringAnnotation(_rewriteTargetRegexTemplate)
+	if rewriteTarget != "" || rewriteTargetRegex != "" || rewriteTemplate != "" {
+		plugin.RewriteTarget = rewriteTarget
+		if rewriteTargetRegex != "" && rewriteTemplate != "" {
+			plugin.RewriteTargetRegex = []string{rewriteTargetRegex, rewriteTemplate}

Review comment:
       Do you mean RC2? I didn't say anything about Perl.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
gxthrj commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637885121



##########
File path: test/e2e/annotations/rewrite.go
##########
@@ -0,0 +1,212 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"fmt"
+	"net/http"
+	"time"
+
+	"github.com/onsi/ginkgo"
+	"github.com/stretchr/testify/assert"
+
+	"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("rewrite annotations", func() {
+	s := scaffold.NewDefaultScaffold()
+
+	ginkgo.It("enable in ingress networking/v1", func() {
+		backendSvc, backendPort := s.DefaultHTTPBackend()
+		ing := fmt.Sprintf(`
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  annotations:
+    kubernetes.io/ingress.class: apisix
+    k8s.apisix.apache.org/rewrite-target: "/ip"
+  name: ingress-v1
+spec:
+  rules:
+  - host: httpbin.org
+    http:
+      paths:
+      - path: /sample
+        pathType: Exact
+        backend:
+          service:
+            name: %s
+            port:
+              number: %d
+`, backendSvc, backendPort[0])
+		err := s.CreateResourceFromString(ing)
+		assert.Nil(ginkgo.GinkgoT(), err, "creating ingress")
+		time.Sleep(5 * time.Second)
+
+		_ = s.NewAPISIXClient().GET("/sample").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusOK)
+	})
+
+	ginkgo.It("enable in ingress networking/v1beta1", func() {
+		backendSvc, backendPort := s.DefaultHTTPBackend()
+		ing := fmt.Sprintf(`
+apiVersion: networking.k8s.io/v1beta1
+kind: Ingress
+metadata:
+  annotations:
+    kubernetes.io/ingress.class: apisix
+    k8s.apisix.apache.org/rewrite-target: "/ip"
+  name: ingress-v1beta1
+spec:
+  rules:
+  - host: httpbin.org
+    http:
+      paths:
+      - path: /sample
+        pathType: Exact
+        backend:
+          serviceName: %s
+          servicePort: %d
+`, backendSvc, backendPort[0])
+		err := s.CreateResourceFromString(ing)
+		assert.Nil(ginkgo.GinkgoT(), err, "creating ingress")
+		time.Sleep(5 * time.Second)
+
+		_ = s.NewAPISIXClient().GET("/sample").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusOK)
+	})
+
+	ginkgo.It("enable in ingress extensions/v1beta1", func() {
+		backendSvc, backendPort := s.DefaultHTTPBackend()
+		ing := fmt.Sprintf(`
+apiVersion: extensions/v1beta1
+kind: Ingress
+metadata:
+  annotations:
+    kubernetes.io/ingress.class: apisix
+    k8s.apisix.apache.org/rewrite-target: "/ip"
+  name: ingress-extensions-v1beta1
+spec:
+  rules:
+  - host: httpbin.org
+    http:
+      paths:
+      - path: /sample
+        pathType: Exact
+        backend:
+          serviceName: %s
+          servicePort: %d
+`, backendSvc, backendPort[0])
+		err := s.CreateResourceFromString(ing)
+		assert.Nil(ginkgo.GinkgoT(), err, "creating ingress")
+		time.Sleep(5 * time.Second)
+
+		_ = s.NewAPISIXClient().GET("/sample").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusOK)

Review comment:
       Need to check if the response is from `/ip`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] lingsamuel commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
lingsamuel commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637880451



##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")
+	rewriteTarget := e.GetStringAnnotation(_rewriteTarget)
+	rewriteTargetRegex := e.GetStringAnnotation(_rewriteTargetRegex)
+	rewriteTemplate := e.GetStringAnnotation(_rewriteTargetRegexTemplate)
+	if rewriteTarget != "" || rewriteTargetRegex != "" || rewriteTemplate != "" {
+		plugin.RewriteTarget = rewriteTarget
+		if rewriteTargetRegex != "" && rewriteTemplate != "" {
+			plugin.RewriteTargetRegex = []string{rewriteTargetRegex, rewriteTemplate}

Review comment:
       Golang regex.Compile uses syntax.Perl. But Perl regex syntax is not exactly same with Perl Compatible Regex Expression.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] lingsamuel commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
lingsamuel commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637835000



##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")
+	rewriteTarget := e.GetStringAnnotation(_rewriteTarget)
+	rewriteTargetRegex := e.GetStringAnnotation(_rewriteTargetRegex)
+	rewriteTemplate := e.GetStringAnnotation(_rewriteTargetRegexTemplate)
+	if rewriteTarget != "" || rewriteTargetRegex != "" || rewriteTemplate != "" {

Review comment:
       Even if this check passed, we still to need verify if they are non-empty before we assign regex_uri. Because string array `[]string{"", ""}` no considered as empty.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tao12345666333 commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637698643



##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")

Review comment:
       Log level is too high.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] codecov-commenter commented on pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#issuecomment-846668725


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#480](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (f669fc0) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/0bdd24b86ca109948e786f7f13f84bc1bd0fbc39?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (0bdd24b) will **decrease** coverage by `0.17%`.
   > The diff coverage is `0.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/graphs/tree.svg?width=650&height=150&src=pr&token=WPLQXPY3V0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #480      +/-   ##
   ==========================================
   - Coverage   37.04%   36.86%   -0.18%     
   ==========================================
     Files          47       47              
     Lines        3841     3857      +16     
   ==========================================
   - Hits         1423     1422       -1     
   - Misses       2233     2250      +17     
     Partials      185      185              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/kube/translation/annotations.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMuZ28=) | `36.36% <ø> (ø)` | |
   | [pkg/kube/translation/annotations/rewrite.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMvcmV3cml0ZS5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `26.69% <0.00%> (-0.35%)` | :arrow_down: |
   | [pkg/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2luZ3Jlc3MvY29udHJvbGxlci5nbw==) | `0.00% <0.00%> (ø)` | |
   | [test/e2e/e2e.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-dGVzdC9lMmUvZTJlLmdv) | | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [0bdd24b...f669fc0](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] gxthrj commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
gxthrj commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637882693



##########
File path: docs/en/latest/concepts/annotations.md
##########
@@ -59,3 +59,12 @@ Blocklist Source Range
 
 You can specify the denied client IP addresses or nets by the annotation `k8s.apisix.apache.org/blocklist-source-range`, multiple IP addresses or nets join together with `,`,
 for instance, `k8s.apisix.apache.org/blocklist-source-range: 127.0.0.1,172.17.0.0/16`. Default value is *empty*, which means the sources are not limited.
+
+Rewrite Target
+--------------
+
+You can rewrite requests by specifying the annotation `k8s.apisix.apache.org/rewrite-target` or `k8s.apisix.apache.org/rewrite-target-regex`.
+
+The annotation `k8s.apisix.apache.org/rewrite-target` controls where the request will be forwarded to.
+
+If you want to use regex and match groups, use annotation `k8s.apisix.apache.org/rewrite-target-regex` and `k8s.apisix.apache.org/rewrite-target-regex-template`. The first annotation contains the matching rule (regex), the second one contains the rewrite rule. For example, `/app(/|$)(.*)` and `/$2`. Both annotations must be used together, otherwise they will be ignored.

Review comment:
       Had better to add a demo for this.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] codecov-commenter edited a comment on pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#issuecomment-846668725


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#480](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b64bce7) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/0bdd24b86ca109948e786f7f13f84bc1bd0fbc39?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (0bdd24b) will **decrease** coverage by `0.19%`.
   > The diff coverage is `0.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/graphs/tree.svg?width=650&height=150&src=pr&token=WPLQXPY3V0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #480      +/-   ##
   ==========================================
   - Coverage   37.04%   36.84%   -0.20%     
   ==========================================
     Files          47       47              
     Lines        3841     3859      +18     
   ==========================================
   - Hits         1423     1422       -1     
   - Misses       2233     2252      +19     
     Partials      185      185              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/kube/translation/annotations.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMuZ28=) | `36.36% <ø> (ø)` | |
   | [pkg/kube/translation/annotations/rewrite.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMvcmV3cml0ZS5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `26.69% <0.00%> (-0.35%)` | :arrow_down: |
   | [pkg/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2luZ3Jlc3MvY29udHJvbGxlci5nbw==) | `0.00% <0.00%> (ø)` | |
   | [test/e2e/e2e.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-dGVzdC9lMmUvZTJlLmdv) | | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [0bdd24b...b64bce7](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] codecov-commenter edited a comment on pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#issuecomment-846668725


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#480](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b64bce7) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/0bdd24b86ca109948e786f7f13f84bc1bd0fbc39?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (0bdd24b) will **decrease** coverage by `0.18%`.
   > The diff coverage is `0.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/graphs/tree.svg?width=650&height=150&src=pr&token=WPLQXPY3V0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #480      +/-   ##
   ==========================================
   - Coverage   37.04%   36.86%   -0.19%     
   ==========================================
     Files          47       48       +1     
     Lines        3841     3860      +19     
   ==========================================
     Hits         1423     1423              
   - Misses       2233     2252      +19     
     Partials      185      185              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/kube/translation/annotations.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMuZ28=) | `36.36% <ø> (ø)` | |
   | [pkg/kube/translation/annotations/rewrite.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMvcmV3cml0ZS5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `26.69% <0.00%> (-0.35%)` | :arrow_down: |
   | [pkg/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2luZ3Jlc3MvY29udHJvbGxlci5nbw==) | `0.00% <0.00%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [0bdd24b...b64bce7](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] codecov-commenter edited a comment on pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#issuecomment-846668725


   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#480](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (710ed71) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/0bdd24b86ca109948e786f7f13f84bc1bd0fbc39?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (0bdd24b) will **decrease** coverage by `0.16%`.
   > The diff coverage is `0.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/graphs/tree.svg?width=650&height=150&src=pr&token=WPLQXPY3V0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #480      +/-   ##
   ==========================================
   - Coverage   37.04%   36.88%   -0.17%     
   ==========================================
     Files          47       48       +1     
     Lines        3841     3858      +17     
   ==========================================
     Hits         1423     1423              
   - Misses       2233     2250      +17     
     Partials      185      185              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/kube/translation/annotations.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMuZ28=) | `36.36% <ø> (ø)` | |
   | [pkg/kube/translation/annotations/rewrite.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2t1YmUvdHJhbnNsYXRpb24vYW5ub3RhdGlvbnMvcmV3cml0ZS5nbw==) | `0.00% <0.00%> (ø)` | |
   | [pkg/apisix/cluster.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2FwaXNpeC9jbHVzdGVyLmdv) | `26.69% <0.00%> (-0.35%)` | :arrow_down: |
   | [pkg/ingress/controller.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2luZ3Jlc3MvY29udHJvbGxlci5nbw==) | `0.00% <0.00%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [0bdd24b...710ed71](https://codecov.io/gh/apache/apisix-ingress-controller/pull/480?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637886934



##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")
+	rewriteTarget := e.GetStringAnnotation(_rewriteTarget)
+	rewriteTargetRegex := e.GetStringAnnotation(_rewriteTargetRegex)
+	rewriteTemplate := e.GetStringAnnotation(_rewriteTargetRegexTemplate)
+	if rewriteTarget != "" || rewriteTargetRegex != "" || rewriteTemplate != "" {
+		plugin.RewriteTarget = rewriteTarget
+		if rewriteTargetRegex != "" && rewriteTemplate != "" {
+			plugin.RewriteTargetRegex = []string{rewriteTargetRegex, rewriteTemplate}

Review comment:
       OK.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] tokers commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637810633



##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")

Review comment:
       Remove the debuggin lines.

##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert

Review comment:
       ```suggestion
   // NewRewriteHandler creates a handler to convert
   ```

##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")
+	rewriteTarget := e.GetStringAnnotation(_rewriteTarget)
+	rewriteTargetRegex := e.GetStringAnnotation(_rewriteTargetRegex)
+	rewriteTemplate := e.GetStringAnnotation(_rewriteTargetRegexTemplate)
+	if rewriteTarget != "" || rewriteTargetRegex != "" || rewriteTemplate != "" {
+		plugin.RewriteTarget = rewriteTarget
+		if rewriteTargetRegex != "" && rewriteTemplate != "" {
+			plugin.RewriteTargetRegex = []string{rewriteTargetRegex, rewriteTemplate}

Review comment:
       Should verify the PCRE regex pattern itself.

##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")
+	rewriteTarget := e.GetStringAnnotation(_rewriteTarget)
+	rewriteTargetRegex := e.GetStringAnnotation(_rewriteTargetRegex)
+	rewriteTemplate := e.GetStringAnnotation(_rewriteTargetRegexTemplate)
+	if rewriteTarget != "" || rewriteTargetRegex != "" || rewriteTemplate != "" {

Review comment:
       ```suggestion
   	if rewriteTarget != "" ||( rewriteTargetRegex != "" && rewriteTemplate != "") {
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] lingsamuel commented on a change in pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
lingsamuel commented on a change in pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480#discussion_r637851365



##########
File path: pkg/kube/translation/annotations/rewrite.go
##########
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package annotations
+
+import (
+	"github.com/apache/apisix-ingress-controller/pkg/log"
+	apisixv1 "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+)
+
+const (
+	_rewriteTarget              = "k8s.apisix.apache.org/rewrite-target"
+	_rewriteTargetRegex         = "k8s.apisix.apache.org/rewrite-target-regex"
+	_rewriteTargetRegexTemplate = "k8s.apisix.apache.org/rewrite-target-regex-template"
+)
+
+type rewrite struct{}
+
+// NewIPRestrictionHandler creates a handler to convert
+// annotations about client ips control to APISIX ip-restrict plugin.
+func NewRewriteHandler() Handler {
+	return &rewrite{}
+}
+
+func (i *rewrite) PluginName() string {
+	return "proxy-rewrite"
+}
+
+func (i *rewrite) Handle(e Extractor) (interface{}, error) {
+	var plugin apisixv1.RewriteConfig
+	log.Errorw("handle rewrite annotations")
+	rewriteTarget := e.GetStringAnnotation(_rewriteTarget)
+	rewriteTargetRegex := e.GetStringAnnotation(_rewriteTargetRegex)
+	rewriteTemplate := e.GetStringAnnotation(_rewriteTargetRegexTemplate)
+	if rewriteTarget != "" || rewriteTargetRegex != "" || rewriteTemplate != "" {
+		plugin.RewriteTarget = rewriteTarget
+		if rewriteTargetRegex != "" && rewriteTemplate != "" {
+			plugin.RewriteTargetRegex = []string{rewriteTargetRegex, rewriteTemplate}

Review comment:
       nit: PCRE is not exactly identical to Perl.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-ingress-controller] gxthrj merged pull request #480: feat: support rewrite annotation

Posted by GitBox <gi...@apache.org>.
gxthrj merged pull request #480:
URL: https://github.com/apache/apisix-ingress-controller/pull/480


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org