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 2022/03/17 01:27:17 UTC

[GitHub] [apisix-ingress-controller] tao12345666333 commented on a change in pull request #919: fix: watch all namespaces by default

tao12345666333 commented on a change in pull request #919:
URL: https://github.com/apache/apisix-ingress-controller/pull/919#discussion_r828604659



##########
File path: test/e2e/scaffold/httpbin.go
##########
@@ -103,6 +103,15 @@ func (s *Scaffold) newHTTPBIN() (*corev1.Service, error) {
 	return svc, nil
 }
 
+func (s *Scaffold) NewHTTPBIN(namespace string) (*corev1.Service, error) {

Review comment:
       change its name to NewHTTPBINWithNamespace?

##########
File path: test/e2e/ingress/namespace.go
##########
@@ -86,7 +88,94 @@ spec:
       servicePort: %d
 `, backendSvc, backendSvcPort[0])
 
-		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, "default"), "creating ApisixRoute")
-		_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
+			assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, "default"), "creating ApisixRoute")
+			_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
+		})
+	})
+
+	ginkgo.Context("without namespace_selector", func() {
+		// make namespace_selector empty
+		s.DisableNamespaceSelector()
+		namespace := "second-httpbin-service-namespace"
+
+		// create another http-bin service in a new namespace.
+		ginkgo.BeforeEach(func() {
+			k8s.CreateNamespace(ginkgo.GinkgoT(), &k8s.KubectlOptions{
+				ConfigPath: scaffold.GetKubeconfig(),
+			}, namespace)
+			_, err := s.NewHTTPBIN(namespace)
+			assert.Nil(ginkgo.GinkgoT(), err, "create second httpbin service")
+		})
+
+		// clean this tmp namespace when test case is done.
+		ginkgo.AfterEach(func() {
+			err := k8s.DeleteNamespaceE(ginkgo.GinkgoT(), &k8s.KubectlOptions{
+				ConfigPath: scaffold.GetKubeconfig()}, namespace)
+			assert.Nilf(ginkgo.GinkgoT(), err, "deleting namespace %s", namespace)
+		})
+
+		ginkgo.It("all resources will be watched", func() {
+			backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+			route := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpbin-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - httpbin.com
+      paths:
+      - /ip
+    backends:
+    - serviceName: %s
+      servicePort: %d
+`, backendSvc, backendSvcPort[0])
+			assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(route), "creating first ApisixRoute")
+			time.Sleep(3 * time.Second)
+
+			// Now create another ApisixRoute in default namespace.

Review comment:
       The comments are inconsistent with the logic below

##########
File path: test/e2e/ingress/namespace.go
##########
@@ -86,7 +88,94 @@ spec:
       servicePort: %d
 `, backendSvc, backendSvcPort[0])
 
-		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, "default"), "creating ApisixRoute")
-		_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
+			assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, "default"), "creating ApisixRoute")
+			_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
+		})
+	})
+
+	ginkgo.Context("without namespace_selector", func() {
+		// make namespace_selector empty
+		s.DisableNamespaceSelector()
+		namespace := "second-httpbin-service-namespace"

Review comment:
       Is it enough that we create in the current namespace and default namespace?

##########
File path: test/e2e/ingress/namespace.go
##########
@@ -86,7 +88,94 @@ spec:
       servicePort: %d
 `, backendSvc, backendSvcPort[0])
 
-		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, "default"), "creating ApisixRoute")
-		_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
+			assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, "default"), "creating ApisixRoute")
+			_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
+		})
+	})
+
+	ginkgo.Context("without namespace_selector", func() {
+		// make namespace_selector empty
+		s.DisableNamespaceSelector()
+		namespace := "second-httpbin-service-namespace"
+
+		// create another http-bin service in a new namespace.
+		ginkgo.BeforeEach(func() {
+			k8s.CreateNamespace(ginkgo.GinkgoT(), &k8s.KubectlOptions{
+				ConfigPath: scaffold.GetKubeconfig(),
+			}, namespace)
+			_, err := s.NewHTTPBIN(namespace)
+			assert.Nil(ginkgo.GinkgoT(), err, "create second httpbin service")
+		})
+
+		// clean this tmp namespace when test case is done.
+		ginkgo.AfterEach(func() {
+			err := k8s.DeleteNamespaceE(ginkgo.GinkgoT(), &k8s.KubectlOptions{
+				ConfigPath: scaffold.GetKubeconfig()}, namespace)
+			assert.Nilf(ginkgo.GinkgoT(), err, "deleting namespace %s", namespace)
+		})
+
+		ginkgo.It("all resources will be watched", func() {
+			backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+			route := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+  name: httpbin-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - httpbin.com
+      paths:
+      - /ip
+    backends:
+    - serviceName: %s
+      servicePort: %d
+`, backendSvc, backendSvcPort[0])
+			assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(route), "creating first ApisixRoute")
+			time.Sleep(3 * time.Second)
+
+			// Now create another ApisixRoute in default namespace.
+			backendSvc, backendSvcPort = s.DefaultHTTPBackend()
+			route = fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2beta3
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+  http:
+  - name: rule1
+    match:
+      hosts:
+      - httpbin.com
+      paths:
+      - /headers
+    backends:
+    - serviceName: %s
+      servicePort: %d
+`, backendSvc, backendSvcPort[0])
+
+			assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, namespace), "creating second ApisixRoute")
+
+			// restart ingress-controller
+			pods, err := s.GetIngressPodDetails()
+			assert.Nil(ginkgo.GinkgoT(), err)
+			assert.Len(ginkgo.GinkgoT(), pods, 1)
+			ginkgo.GinkgoT().Logf("restart apisix-ingress-controller pod %s", pods[0].Name)
+			assert.Nil(ginkgo.GinkgoT(), s.KillPod(pods[0].Name))
+			time.Sleep(6 * time.Second)
+			// Two ApisixRoutes have been created at this time.
+			assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(2), "checking number of routes")
+			assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixUpstreamsCreated(2), "checking number of upstreams")
+
+			body := s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+			var placeholder ip
+			err = json.Unmarshal([]byte(body), &placeholder)
+			assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")
+			_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+			err = json.Unmarshal([]byte(body), &placeholder)
+			assert.Nil(ginkgo.GinkgoT(), err, "unmarshalling IP")

Review comment:
       Modifications are required here

##########
File path: test/e2e/scaffold/scaffold.go
##########
@@ -54,6 +53,7 @@ type Options struct {
 	APISIXAdminAPIKey     string
 	EnableWebhooks        bool
 	APISIXPublishAddress  string
+	disableNodeSelector   bool

Review comment:
       Its name should be related to namespace, right?

##########
File path: test/e2e/scaffold/scaffold.go
##########
@@ -64,7 +64,6 @@ type Scaffold struct {
 	nodes              []corev1.Node
 	etcdService        *corev1.Service
 	apisixService      *corev1.Service
-	httpbinDeployment  *appsv1.Deployment

Review comment:
       why remove this one?




-- 
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: notifications-unsubscribe@apisix.apache.org

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