This is an automated email from the ASF dual-hosted git repository. alinsran pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push: new 4745958e fix: route names with the same prefix were mistakenly deleted (#2472) 4745958e is described below commit 4745958edf3d7a62155d51acabbb80f288f3982b Author: AlinsRan <alins...@apache.org> AuthorDate: Tue Jul 15 15:12:24 2025 +0800 fix: route names with the same prefix were mistakenly deleted (#2472) --- internal/provider/adc/cache/indexer.go | 10 ++++++++-- test/e2e/apisix/route.go | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/internal/provider/adc/cache/indexer.go b/internal/provider/adc/cache/indexer.go index e19410b8..ad9dda3b 100644 --- a/internal/provider/adc/cache/indexer.go +++ b/internal/provider/adc/cache/indexer.go @@ -56,6 +56,12 @@ type LabelIndexer struct { GetLabels func(obj any) map[string]string } +// ref: https://pkg.go.dev/github.com/hashicorp/go-memdb#Txn.Get +// by adding suffixes to avoid prefix matching +func (emi *LabelIndexer) genKey(labelValues []string) []byte { + return []byte(strings.Join(labelValues, "/") + "\x00") +} + func (emi *LabelIndexer) FromObject(obj any) (bool, []byte, error) { labels := emi.GetLabels(obj) var labelValues []string @@ -69,7 +75,7 @@ func (emi *LabelIndexer) FromObject(obj any) (bool, []byte, error) { return false, nil, nil } - return true, []byte(strings.Join(labelValues, "/")), nil + return true, emi.genKey(labelValues), nil } func (emi *LabelIndexer) FromArgs(args ...any) ([]byte, error) { @@ -86,5 +92,5 @@ func (emi *LabelIndexer) FromArgs(args ...any) ([]byte, error) { labelValues = append(labelValues, value) } - return []byte(strings.Join(labelValues, "/")), nil + return emi.genKey(labelValues), nil } diff --git a/test/e2e/apisix/route.go b/test/e2e/apisix/route.go index a47e6a31..e39e9c86 100644 --- a/test/e2e/apisix/route.go +++ b/test/e2e/apisix/route.go @@ -356,6 +356,42 @@ spec: applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin-service-e2e-test"}, new(apiv2.ApisixUpstream), apisixUpstreamSpec1) Eventually(request).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) }) + + It("Multiple ApisixRoute with same prefix name", func() { + const apisixRouteSpec = ` +apiVersion: apisix.apache.org/v2 +kind: ApisixRoute +metadata: + name: %s +spec: + ingressClassName: apisix + http: + - name: rule0 + match: + hosts: + - %s + paths: + - /* + backends: + - serviceName: httpbin-service-e2e-test + servicePort: 80 +` + By("apply ApisixRoute") + var apisixRoute apiv2.ApisixRoute + for _, id := range []string{"11111", "1111", "111", "11", "1"} { + name := fmt.Sprintf("route-%s", id) + host := fmt.Sprintf("httpbin-%s", id) + applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: name}, &apisixRoute, fmt.Sprintf(apisixRouteSpec, name, host)) + } + + By("verify ApisixRoute works") + for _, id := range []string{"1", "11", "111", "1111", "11111"} { + host := fmt.Sprintf("httpbin-%s", id) + Eventually(func() int { + return s.NewAPISIXClient().GET("/get").WithHost(host).Expect().Raw().StatusCode + }).WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) + } + }) }) Context("Test ApisixRoute reference ApisixUpstream", func() {