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/08/11 02:38:45 UTC

[GitHub] [apisix-ingress-controller] AlinsRan opened a new pull request, #1238: fix: namespace_selector invalid when restarting

AlinsRan opened a new pull request, #1238:
URL: https://github.com/apache/apisix-ingress-controller/pull/1238

   <!-- Please answer these questions before submitting a pull request -->
   
   ### Type of change:
   
   <!-- Please delete options that are not relevant. -->
   
   - [ ] Bugfix
   - [ ] New feature provided
   - [ ] Improve performance
   - [ ] Backport patches
   
   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   ### Pre-submission checklist:
   
   <!--
   Please follow the requirements:
   1. Use Draft if the PR is not ready to be reviewed
   2. Test is required for the feat/fix PR, unless you have a good reason
   3. Doc is required for the feat PR
   4. Use a new commit to resolve review instead of `push -f`
   5. Use "request review" to notify the reviewer once you have resolved the review
   -->
   
   * [ ] Did you explain what problem does this PR solve? Or what new features have been added?
   * [ ] Have you added corresponding test cases?
   * [ ] Have you modified the corresponding document?
   * [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix-ingress-controller#community) first**
   


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


[GitHub] [apisix-ingress-controller] tao12345666333 commented on a diff in pull request #1238: fix: namespace_selector invalid when restarting

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on code in PR #1238:
URL: https://github.com/apache/apisix-ingress-controller/pull/1238#discussion_r956875768


##########
test/e2e/suite-ingress/suite-ingress-features/namespace.go:
##########
@@ -189,3 +269,130 @@ spec:
 		})
 	})
 })
+
+var _ = ginkgo.Describe("suite-ingress-features: namespacing ub-label", func() {
+	labelName, labelValue := fmt.Sprintf("namespace-selector-%d", time.Now().Nanosecond()), "watch"
+	s := scaffold.NewScaffold(&scaffold.Options{
+		Name:                  "un-label",
+		IngressAPISIXReplicas: 1,
+		ApisixResourceVersion: scaffold.ApisixResourceVersion().Default,
+		NamespaceSelectorLabel: map[string]string{
+			labelName: labelValue,
+		},
+		DisableNamespaceLabel: true,
+	})
+	namespace1 := fmt.Sprintf("un-label-%d", time.Now().Nanosecond())
+
+	ginkgo.It("un-label", func() {
+		ns := fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+  labels:
+    %s: %s
+`, namespace1, labelName, labelValue)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(ns, namespace1), "creating namespace")
+		//defer s.DeleteResourceFromStringWithNamespace(ns, namespace1)
+		_, err := s.NewHTTPBINWithNamespace(namespace1)
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+
+		backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+		route1 := fmt.Sprintf(`
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: httpbin-route
+spec:
+  ingressClassName: apisix
+  rules:
+  - host: httpbin.com
+    http:
+      paths:
+      - path: /ip
+        pathType: Exact
+        backend:
+          service:
+            name: %s
+            port:
+              number: %d
+`, backendSvc, backendSvcPort[0])
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route1, namespace1), "creating ingress")
+		assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
+		time.Sleep(time.Second * 6)
+		_ = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+
+		assert.Nil(ginkgo.GinkgoT(), s.DeleteResourceFromStringWithNamespace(route1, namespace1), "deleting ingress")
+		ns = fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+`, namespace1)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ns), "creating namespace")
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+		time.Sleep(6 * time.Second)
+		routes, err := s.ListApisixRoutes()
+		assert.Nil(ginkgo.GinkgoT(), err)
+		assert.Len(ginkgo.GinkgoT(), routes, 0)

Review Comment:
   https://pkg.go.dev/k8s.io/client-go@v0.25.0/kubernetes/typed/core/v1#NamespaceInterface
   
   This function can be done through Update or Patch



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


[GitHub] [apisix-ingress-controller] lingsamuel commented on a diff in pull request #1238: fix: namespace_selector invalid when restarting

Posted by GitBox <gi...@apache.org>.
lingsamuel commented on code in PR #1238:
URL: https://github.com/apache/apisix-ingress-controller/pull/1238#discussion_r952392003


##########
test/e2e/scaffold/ingress.go:
##########
@@ -428,13 +428,17 @@ func (s *Scaffold) newIngressAPISIXController() error {
 	})
 
 	var ingressAPISIXDeployment string
-	label := fmt.Sprintf("apisix.ingress.watch=%s", s.namespace)
+	label := "\"\""

Review Comment:
   `` `""` `` would be clearer



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


[GitHub] [apisix-ingress-controller] tao12345666333 merged pull request #1238: fix: namespace_selector invalid when restarting

Posted by GitBox <gi...@apache.org>.
tao12345666333 merged PR #1238:
URL: https://github.com/apache/apisix-ingress-controller/pull/1238


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


[GitHub] [apisix-ingress-controller] tao12345666333 commented on a diff in pull request #1238: fix: namespace_selector invalid when restarting

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on code in PR #1238:
URL: https://github.com/apache/apisix-ingress-controller/pull/1238#discussion_r956876806


##########
test/e2e/suite-ingress/suite-ingress-features/namespace.go:
##########
@@ -189,3 +269,130 @@ spec:
 		})
 	})
 })
+
+var _ = ginkgo.Describe("suite-ingress-features: namespacing ub-label", func() {
+	labelName, labelValue := fmt.Sprintf("namespace-selector-%d", time.Now().Nanosecond()), "watch"
+	s := scaffold.NewScaffold(&scaffold.Options{
+		Name:                  "un-label",
+		IngressAPISIXReplicas: 1,
+		ApisixResourceVersion: scaffold.ApisixResourceVersion().Default,
+		NamespaceSelectorLabel: map[string]string{
+			labelName: labelValue,
+		},
+		DisableNamespaceLabel: true,
+	})
+	namespace1 := fmt.Sprintf("un-label-%d", time.Now().Nanosecond())
+
+	ginkgo.It("un-label", func() {
+		ns := fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+  labels:
+    %s: %s
+`, namespace1, labelName, labelValue)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(ns, namespace1), "creating namespace")
+		//defer s.DeleteResourceFromStringWithNamespace(ns, namespace1)
+		_, err := s.NewHTTPBINWithNamespace(namespace1)
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+
+		backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+		route1 := fmt.Sprintf(`
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: httpbin-route
+spec:
+  ingressClassName: apisix
+  rules:
+  - host: httpbin.com
+    http:
+      paths:
+      - path: /ip
+        pathType: Exact
+        backend:
+          service:
+            name: %s
+            port:
+              number: %d
+`, backendSvc, backendSvcPort[0])
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route1, namespace1), "creating ingress")
+		assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
+		time.Sleep(time.Second * 6)
+		_ = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+
+		assert.Nil(ginkgo.GinkgoT(), s.DeleteResourceFromStringWithNamespace(route1, namespace1), "deleting ingress")
+		ns = fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+`, namespace1)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ns), "creating namespace")
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+		time.Sleep(6 * time.Second)
+		routes, err := s.ListApisixRoutes()
+		assert.Nil(ginkgo.GinkgoT(), err)
+		assert.Len(ginkgo.GinkgoT(), routes, 0)

Review Comment:
   Patch is simpler, just need to pass one of the following
   
   ```
    {"metadata":{"labels":{"YOUR Label Name":null}}}
   ```



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


[GitHub] [apisix-ingress-controller] tao12345666333 commented on a diff in pull request #1238: fix: namespace_selector invalid when restarting

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on code in PR #1238:
URL: https://github.com/apache/apisix-ingress-controller/pull/1238#discussion_r956965068


##########
test/e2e/suite-ingress/suite-ingress-features/namespace.go:
##########
@@ -90,18 +143,48 @@ spec:
             port:
               number: %d
 `, backendSvc, backendSvcPort[0])
+			assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(route3), "creating ingress")
+			time.Sleep(6 * time.Second)
+			routes, err = s.ListApisixRoutes()
+			assert.Nil(ginkgo.GinkgoT(), err)
+			assert.Len(ginkgo.GinkgoT(), routes, 1)
+			_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "local.httpbin.org").Expect().Status(http.StatusNotFound)
+
+			// remove route1
+			assert.Nil(ginkgo.GinkgoT(), s.DeleteResourceFromStringWithNamespace(route1, namespace1), "delte ingress")

Review Comment:
   ```suggestion
   			assert.Nil(ginkgo.GinkgoT(), s.DeleteResourceFromStringWithNamespace(route1, namespace1), "delete ingress")
   ```



##########
test/e2e/suite-ingress/suite-ingress-features/namespace.go:
##########
@@ -90,18 +143,48 @@ spec:
             port:
               number: %d
 `, backendSvc, backendSvcPort[0])
+			assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(route3), "creating ingress")
+			time.Sleep(6 * time.Second)
+			routes, err = s.ListApisixRoutes()
+			assert.Nil(ginkgo.GinkgoT(), err)
+			assert.Len(ginkgo.GinkgoT(), routes, 1)
+			_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "local.httpbin.org").Expect().Status(http.StatusNotFound)
+
+			// remove route1
+			assert.Nil(ginkgo.GinkgoT(), s.DeleteResourceFromStringWithNamespace(route1, namespace1), "delte ingress")
+			time.Sleep(6 * time.Second)
+
+			deleteNamespace(namespace1)
+			time.Sleep(6 * time.Second)
+			routes, err = s.ListApisixRoutes()
+			assert.Nil(ginkgo.GinkgoT(), err)
+			assert.Len(ginkgo.GinkgoT(), routes, 0)
+
+			// restart ingress-controller
+			s.RestartIngressControllerDeploy()
+			time.Sleep(6 * time.Second)
+			assert.Nil(ginkgo.GinkgoT(), err)
+			assert.Len(ginkgo.GinkgoT(), routes, 0)
 
-			assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route, "default"), "creating ingress")
-			_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusNotFound)
+			createNamespaceLabel(namespace2)
+			defer deleteNamespace(namespace2)
+			assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route1, namespace2), "creating ingress")
+			assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
+			_ = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK)
+			_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "httpbin.org").Expect().Status(http.StatusNotFound)
+			_ = s.NewAPISIXClient().GET("/headers").WithHeader("Host", "local.httpbin.org").Expect().Status(http.StatusNotFound)
 		})
 	})
 })
 
-var _ = ginkgo.Describe("suite-ingress-features: namespacing filtering disable", func() {
-	s := scaffold.NewDefaultScaffold()
+var _ = ginkgo.Describe("suite-ingress-features: namespacing fltering disable", func() {

Review Comment:
   ```suggestion
   var _ = ginkgo.Describe("suite-ingress-features: namespacing filtering disable", func() {
   ```



##########
test/e2e/suite-ingress/suite-ingress-features/namespace.go:
##########
@@ -189,3 +271,134 @@ spec:
 		})
 	})
 })
+
+var _ = ginkgo.Describe("suite-ingress-features: namespacing un-label", func() {
+	labelName, labelValue := fmt.Sprintf("namespace-selector-%d", time.Now().Nanosecond()), "watch"
+	s := scaffold.NewScaffold(&scaffold.Options{
+		Name:                  "un-label",
+		IngressAPISIXReplicas: 1,
+		ApisixResourceVersion: scaffold.ApisixResourceVersion().Default,
+		NamespaceSelectorLabel: map[string]string{
+			labelName: labelValue,
+		},
+		DisableNamespaceLabel: true,
+	})
+	namespace1 := fmt.Sprintf("un-label-%d", time.Now().Nanosecond())
+
+	ginkgo.It("un-label", func() {
+		client := s.GetKubernetesClient()
+
+		ns := fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+  labels:
+    %s: %s
+`, namespace1, labelName, labelValue)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(ns, namespace1), "creating namespace")
+		//defer s.DeleteResourceFromStringWithNamespace(ns, namespace1)
+		_, err := s.NewHTTPBINWithNamespace(namespace1)
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+
+		backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+		route1 := fmt.Sprintf(`
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: httpbin-route
+spec:
+  ingressClassName: apisix
+  rules:
+  - host: httpbin.com
+    http:
+      paths:
+      - path: /ip
+        pathType: Exact
+        backend:
+          service:
+            name: %s
+            port:
+              number: %d
+`, backendSvc, backendSvcPort[0])
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route1, namespace1), "creating ingress")
+		assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
+		time.Sleep(time.Second * 6)
+		_ = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+
+		assert.Nil(ginkgo.GinkgoT(), s.DeleteResourceFromStringWithNamespace(route1, namespace1), "deleting ingress")
+		// un-label
+		_, err = client.CoreV1().Namespaces().Update(
+			context.Background(),
+			&v1.Namespace{ObjectMeta: metav1.ObjectMeta{
+				Name:   namespace1,
+				Labels: map[string]string{},
+			}},
+			metav1.UpdateOptions{},
+		)
+		assert.Nil(ginkgo.GinkgoT(), err, "creating namespace")

Review Comment:
   ```suggestion
   		assert.Nil(ginkgo.GinkgoT(), err, "unlabel the namespace")
   ```



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


[GitHub] [apisix-ingress-controller] codecov-commenter commented on pull request #1238: fix: namespace_selector invalid when restarting

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

   # [Codecov](https://codecov.io/gh/apache/apisix-ingress-controller/pull/1238?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 [#1238](https://codecov.io/gh/apache/apisix-ingress-controller/pull/1238?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (3815a08) into [master](https://codecov.io/gh/apache/apisix-ingress-controller/commit/537501cd3415dbd71f45a539f57c757d9a634549?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (537501c) will **decrease** coverage by `0.07%`.
   > The diff coverage is `n/a`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #1238      +/-   ##
   ==========================================
   - Coverage   42.64%   42.57%   -0.08%     
   ==========================================
     Files          73       73              
     Lines        6462     6454       -8     
   ==========================================
   - Hits         2756     2748       -8     
     Misses       3409     3409              
     Partials      297      297              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-ingress-controller/pull/1238?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/api/validation/utils.go](https://codecov.io/gh/apache/apisix-ingress-controller/pull/1238/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-cGtnL2FwaS92YWxpZGF0aW9uL3V0aWxzLmdv) | `32.43% <ø> (-12.02%)` | :arrow_down: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix-ingress-controller] AlinsRan commented on a diff in pull request #1238: fix: namespace_selector invalid when restarting

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on code in PR #1238:
URL: https://github.com/apache/apisix-ingress-controller/pull/1238#discussion_r956867378


##########
test/e2e/suite-ingress/suite-ingress-features/namespace.go:
##########
@@ -189,3 +269,130 @@ spec:
 		})
 	})
 })
+
+var _ = ginkgo.Describe("suite-ingress-features: namespacing ub-label", func() {
+	labelName, labelValue := fmt.Sprintf("namespace-selector-%d", time.Now().Nanosecond()), "watch"
+	s := scaffold.NewScaffold(&scaffold.Options{
+		Name:                  "un-label",
+		IngressAPISIXReplicas: 1,
+		ApisixResourceVersion: scaffold.ApisixResourceVersion().Default,
+		NamespaceSelectorLabel: map[string]string{
+			labelName: labelValue,
+		},
+		DisableNamespaceLabel: true,
+	})
+	namespace1 := fmt.Sprintf("un-label-%d", time.Now().Nanosecond())
+
+	ginkgo.It("un-label", func() {
+		ns := fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+  labels:
+    %s: %s
+`, namespace1, labelName, labelValue)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(ns, namespace1), "creating namespace")
+		//defer s.DeleteResourceFromStringWithNamespace(ns, namespace1)
+		_, err := s.NewHTTPBINWithNamespace(namespace1)
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+
+		backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+		route1 := fmt.Sprintf(`
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: httpbin-route
+spec:
+  ingressClassName: apisix
+  rules:
+  - host: httpbin.com
+    http:
+      paths:
+      - path: /ip
+        pathType: Exact
+        backend:
+          service:
+            name: %s
+            port:
+              number: %d
+`, backendSvc, backendSvcPort[0])
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route1, namespace1), "creating ingress")
+		assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
+		time.Sleep(time.Second * 6)
+		_ = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+
+		assert.Nil(ginkgo.GinkgoT(), s.DeleteResourceFromStringWithNamespace(route1, namespace1), "deleting ingress")
+		ns = fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+`, namespace1)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ns), "creating namespace")
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+		time.Sleep(6 * time.Second)
+		routes, err := s.ListApisixRoutes()
+		assert.Nil(ginkgo.GinkgoT(), err)
+		assert.Len(ginkgo.GinkgoT(), routes, 0)

Review Comment:
   There is no such interface. This can be done, but it is not convenient.



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


[GitHub] [apisix-ingress-controller] tao12345666333 commented on a diff in pull request #1238: fix: namespace_selector invalid when restarting

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on code in PR #1238:
URL: https://github.com/apache/apisix-ingress-controller/pull/1238#discussion_r956857671


##########
test/e2e/suite-ingress/suite-ingress-features/namespace.go:
##########
@@ -189,3 +269,130 @@ spec:
 		})
 	})
 })
+
+var _ = ginkgo.Describe("suite-ingress-features: namespacing ub-label", func() {

Review Comment:
   ```suggestion
   var _ = ginkgo.Describe("suite-ingress-features: namespacing un-label", func() {
   ```



##########
test/e2e/suite-ingress/suite-ingress-features/namespace.go:
##########
@@ -189,3 +269,130 @@ spec:
 		})
 	})
 })
+
+var _ = ginkgo.Describe("suite-ingress-features: namespacing ub-label", func() {
+	labelName, labelValue := fmt.Sprintf("namespace-selector-%d", time.Now().Nanosecond()), "watch"
+	s := scaffold.NewScaffold(&scaffold.Options{
+		Name:                  "un-label",
+		IngressAPISIXReplicas: 1,
+		ApisixResourceVersion: scaffold.ApisixResourceVersion().Default,
+		NamespaceSelectorLabel: map[string]string{
+			labelName: labelValue,
+		},
+		DisableNamespaceLabel: true,
+	})
+	namespace1 := fmt.Sprintf("un-label-%d", time.Now().Nanosecond())
+
+	ginkgo.It("un-label", func() {
+		ns := fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+  labels:
+    %s: %s
+`, namespace1, labelName, labelValue)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(ns, namespace1), "creating namespace")
+		//defer s.DeleteResourceFromStringWithNamespace(ns, namespace1)
+		_, err := s.NewHTTPBINWithNamespace(namespace1)
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+
+		backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+		route1 := fmt.Sprintf(`
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: httpbin-route
+spec:
+  ingressClassName: apisix
+  rules:
+  - host: httpbin.com
+    http:
+      paths:
+      - path: /ip
+        pathType: Exact
+        backend:
+          service:
+            name: %s
+            port:
+              number: %d
+`, backendSvc, backendSvcPort[0])
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route1, namespace1), "creating ingress")
+		assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
+		time.Sleep(time.Second * 6)
+		_ = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+
+		assert.Nil(ginkgo.GinkgoT(), s.DeleteResourceFromStringWithNamespace(route1, namespace1), "deleting ingress")
+		ns = fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+`, namespace1)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ns), "creating namespace")
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+		time.Sleep(6 * time.Second)
+		routes, err := s.ListApisixRoutes()
+		assert.Nil(ginkgo.GinkgoT(), err)
+		assert.Len(ginkgo.GinkgoT(), routes, 0)

Review Comment:
   In order to be more in line with the actual situation, I suggest modifying the logic here to directly clean up the namespace labels 



##########
test/e2e/suite-ingress/suite-ingress-features/namespace.go:
##########
@@ -37,12 +38,37 @@ type headers struct {
 }
 
 var _ = ginkgo.Describe("suite-ingress-features: namespacing filtering enable", func() {
-	s := scaffold.NewDefaultScaffold()
+	s := scaffold.NewScaffold(&scaffold.Options{
+		Name:                  "enable-namespace-selector",
+		IngressAPISIXReplicas: 1,
+		ApisixResourceVersion: scaffold.ApisixResourceVersion().Default,
+		NamespaceSelectorLabel: map[string]string{
+			fmt.Sprintf("namespace-selector-%d", time.Now().Nanosecond()): "watch",
+		},
+		DisableNamespaceLabel: true,
+	})
 
 	ginkgo.Context("with namespace_selector", func() {
+		namespace1 := fmt.Sprintf("namespace-selector-1-%d", time.Now().Nanosecond())
+		namespace2 := fmt.Sprintf("namespace-selector-2-%d", time.Now().Nanosecond())
+
+		createNamespaceLabel := func(namespace string) {
+			k8s.CreateNamespaceWithMetadata(ginkgo.GinkgoT(), &k8s.KubectlOptions{ConfigPath: scaffold.GetKubeconfig()}, metav1.ObjectMeta{Name: namespace, Labels: s.NamespaceSelectorLabel()})
+			_, err := s.NewHTTPBINWithNamespace(namespace)
+			time.Sleep(6 * time.Second)
+			assert.Nil(ginkgo.GinkgoT(), err, "create second httpbin service")

Review Comment:
   ```suggestion
   			assert.Nil(ginkgo.GinkgoT(), err, "create new httpbin service")
   ```



##########
pkg/providers/k8s/namespace/namespace_provider.go:
##########
@@ -48,44 +46,25 @@ type WatchingNamespaceProvider interface {
 }
 
 func NewWatchingNamespaceProvider(ctx context.Context, kube *kube.KubeClient, cfg *config.Config) (WatchingNamespaceProvider, error) {
-	var (
-		watchingNamespaces = new(sync.Map)
-		watchingLabels     = make(map[string]string)
-	)
-	if len(cfg.Kubernetes.AppNamespaces) > 1 || cfg.Kubernetes.AppNamespaces[0] != v1.NamespaceAll {
-		for _, ns := range cfg.Kubernetes.AppNamespaces {
-			watchingNamespaces.Store(ns, struct{}{})
-		}
-	}
-	// support namespace label-selector
-	for _, selector := range cfg.Kubernetes.NamespaceSelector {
-		labelSlice := strings.Split(selector, "=")
-		watchingLabels[labelSlice[0]] = labelSlice[1]
-	}
-
-	// watchingNamespaces and watchingLabels are empty means to monitor all namespaces.
-	if !validation.HasValueInSyncMap(watchingNamespaces) && len(watchingLabels) == 0 {
-		opts := metav1.ListOptions{}
-		// list all namespaces
-		nsList, err := kube.Client.CoreV1().Namespaces().List(ctx, opts)
-		if err != nil {
-			log.Error(err.Error())
-			ctx.Done()
-		} else {
-			wns := new(sync.Map)
-			for _, v := range nsList.Items {
-				wns.Store(v.Name, struct{}{})
-			}
-			watchingNamespaces = wns
-		}
-	}
-
 	c := &watchingProvider{
 		kube: kube,
 		cfg:  cfg,
 
-		watchingNamespaces: watchingNamespaces,
-		watchingLabels:     watchingLabels,
+		watchingNamespaces: new(sync.Map),
+		watchingLabels:     make(map[string]string),
+
+		enableLabelsWatching: false,
+	}
+
+	if len(cfg.Kubernetes.NamespaceSelector) == 0 {
+		return c, nil
+	}
+
+	// support namespace label-selector
+	c.enableLabelsWatching = true
+	for _, selector := range cfg.Kubernetes.NamespaceSelector {
+		labelSlice := strings.Split(selector, "=")
+		c.watchingLabels[labelSlice[0]] = labelSlice[1]

Review Comment:
   I think a judgment should be added here to avoid mistakes. (Avoid indexing over
   
   



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


[GitHub] [apisix-ingress-controller] AlinsRan commented on a diff in pull request #1238: fix: namespace_selector invalid when restarting

Posted by GitBox <gi...@apache.org>.
AlinsRan commented on code in PR #1238:
URL: https://github.com/apache/apisix-ingress-controller/pull/1238#discussion_r956891272


##########
test/e2e/suite-ingress/suite-ingress-features/namespace.go:
##########
@@ -189,3 +269,130 @@ spec:
 		})
 	})
 })
+
+var _ = ginkgo.Describe("suite-ingress-features: namespacing ub-label", func() {
+	labelName, labelValue := fmt.Sprintf("namespace-selector-%d", time.Now().Nanosecond()), "watch"
+	s := scaffold.NewScaffold(&scaffold.Options{
+		Name:                  "un-label",
+		IngressAPISIXReplicas: 1,
+		ApisixResourceVersion: scaffold.ApisixResourceVersion().Default,
+		NamespaceSelectorLabel: map[string]string{
+			labelName: labelValue,
+		},
+		DisableNamespaceLabel: true,
+	})
+	namespace1 := fmt.Sprintf("un-label-%d", time.Now().Nanosecond())
+
+	ginkgo.It("un-label", func() {
+		ns := fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+  labels:
+    %s: %s
+`, namespace1, labelName, labelValue)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(ns, namespace1), "creating namespace")
+		//defer s.DeleteResourceFromStringWithNamespace(ns, namespace1)
+		_, err := s.NewHTTPBINWithNamespace(namespace1)
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+
+		backendSvc, backendSvcPort := s.DefaultHTTPBackend()
+		route1 := fmt.Sprintf(`
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: httpbin-route
+spec:
+  ingressClassName: apisix
+  rules:
+  - host: httpbin.com
+    http:
+      paths:
+      - path: /ip
+        pathType: Exact
+        backend:
+          service:
+            name: %s
+            port:
+              number: %d
+`, backendSvc, backendSvcPort[0])
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromStringWithNamespace(route1, namespace1), "creating ingress")
+		assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixRoutesCreated(1))
+		time.Sleep(time.Second * 6)
+		_ = s.NewAPISIXClient().GET("/ip").WithHeader("Host", "httpbin.com").Expect().Status(http.StatusOK).Body().Raw()
+
+		assert.Nil(ginkgo.GinkgoT(), s.DeleteResourceFromStringWithNamespace(route1, namespace1), "deleting ingress")
+		ns = fmt.Sprintf(`
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: %s
+`, namespace1)
+		assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ns), "creating namespace")
+		assert.Nil(ginkgo.GinkgoT(), err, "create httpbin service in", namespace1)
+		time.Sleep(6 * time.Second)
+		routes, err := s.ListApisixRoutes()
+		assert.Nil(ginkgo.GinkgoT(), err)
+		assert.Len(ginkgo.GinkgoT(), routes, 0)

Review Comment:
   Done.



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


[GitHub] [apisix-ingress-controller] tao12345666333 commented on a diff in pull request #1238: fix: namespace_selector invalid when restarting

Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on code in PR #1238:
URL: https://github.com/apache/apisix-ingress-controller/pull/1238#discussion_r953539388


##########
test/e2e/scaffold/ingress.go:
##########
@@ -428,13 +428,17 @@ func (s *Scaffold) newIngressAPISIXController() error {
 	})
 
 	var ingressAPISIXDeployment string
-	label := fmt.Sprintf("apisix.ingress.watch=%s", s.namespace)
+	label := "\"\""

Review Comment:
   +1



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