tao12345666333 commented on code in PR #1471:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/1471#discussion_r1032697323


##########
pkg/providers/ingress/translation/annotations/plugins/http_method.go:
##########
@@ -17,6 +17,8 @@ package plugins
 import (
        
"github.com/apache/apisix-ingress-controller/pkg/providers/ingress/translation/annotations"
        apisixv1 
"github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
+       "github.com/incubator4/go-resty-expr/expr"
+       "net/http"

Review Comment:
   please sort the imports.



##########
pkg/providers/ingress/translation/annotations/plugins/http_method_test.go:
##########
@@ -15,6 +15,8 @@
 package plugins
 
 import (
+       "github.com/incubator4/go-resty-expr/expr"
+       "net/http"

Review Comment:
   ditto



##########
test/e2e/suite-annotations/http_method.go:
##########
@@ -0,0 +1,198 @@
+package annotations
+
+import (
+       "fmt"
+       "net/http"
+       "time"
+
+       ginkgo "github.com/onsi/ginkgo/v2"
+       "github.com/stretchr/testify/assert"
+
+       "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-annotations: allow-http-methods 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/allow-http-methods: POST,PUT
+  name: ingress-v1
+spec:
+  rules:
+  - host: httpbin.org
+    http:
+      paths:
+      - path: /ip
+        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)
+
+               resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", 
"httpbin.org").Expect()
+               resp.Status(http.StatusMethodNotAllowed)

Review Comment:
   We also need to check whether the methods that has been configured can work 
normally. (POST and PUT)



##########
test/e2e/suite-annotations/http_method.go:
##########
@@ -0,0 +1,198 @@
+package annotations
+
+import (
+       "fmt"
+       "net/http"
+       "time"
+
+       ginkgo "github.com/onsi/ginkgo/v2"
+       "github.com/stretchr/testify/assert"
+
+       "github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
+)
+
+var _ = ginkgo.Describe("suite-annotations: allow-http-methods 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/allow-http-methods: POST,PUT
+  name: ingress-v1
+spec:
+  rules:
+  - host: httpbin.org
+    http:
+      paths:
+      - path: /ip
+        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)
+
+               resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", 
"httpbin.org").Expect()
+               resp.Status(http.StatusMethodNotAllowed)
+       })
+
+       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/allow-http-methods: POST,PUT
+  name: ingress-v1beta1
+spec:
+  rules:
+  - host: httpbin.org
+    http:
+      paths:
+      - path: /ip
+        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)
+
+               resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", 
"httpbin.org").Expect()
+               resp.Status(http.StatusMethodNotAllowed)
+       })
+
+       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/allow-http-methods: POST,PUT
+  name: ingress-extensions-v1beta1
+spec:
+  rules:
+  - host: httpbin.org
+    http:
+      paths:
+      - path: /ip
+        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)
+
+               resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", 
"httpbin.org").Expect()
+               resp.Status(http.StatusMethodNotAllowed)
+       })
+})
+
+var _ = ginkgo.Describe("suite-annotations: blocklist-http-methods 
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/allow-http-methods: GET
+  name: ingress-v1
+spec:
+  rules:
+  - host: httpbin.org
+    http:
+      paths:
+      - path: /ip
+        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)
+
+               resp := s.NewAPISIXClient().GET("/ip").WithHeader("Host", 
"httpbin.org").Expect()
+               resp.Status(http.StatusMethodNotAllowed)

Review Comment:
   Also check whether it can work normally if it is not on the Block list.



##########
pkg/types/apisix/v1/plugin_types.go:
##########
@@ -16,7 +16,7 @@ package v1
 
 import (
        "encoding/json"
-       "fmt"
+       "github.com/incubator4/go-resty-expr/expr"

Review Comment:
   ditto



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to