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

   ### Type of change:
   
   - [x] Bugfix
   - [ ] New feature provided
   - [ ] Improve performance
   - [ ] Backport patches
   - [ ] Documentation
   - [ ] Refactor
   - [ ] Chore
   - [ ] CI/CD or Tests
   
   ### What this PR does / why we need it:
   
   Generated APISIX resources are identified by a name composed from the 
Kubernetes resource, and by an ID derived from that name. Two resources that 
compose the same name, or whose names hash to the same ID, end up as one entry: 
the store keys services by ID, so the one reconciled last silently replaces the 
other, and its routes stop being served without any error or status change. 
Routes that share an ID across different services instead make APISIX 
standalone reject the whole configuration (`found duplicate id ... in routes`), 
so no further change in that GatewayProxy is applied until the conflict is 
removed.
   
   There are two ways to get there:
   
   1. **Same namespace and name, different kinds.** Route, service and stream 
route names are composed from namespace, name and rule only. An `ApisixRoute`, 
an `HTTPRoute` and an `Ingress` named `default/foo` all compose the service 
name `default_foo_0`, and the route names of `HTTPRoute`, `GRPCRoute` and 
`Ingress` all compose `default_foo_0-0`. Reusing a name across kinds is common, 
for example while moving an `ApisixRoute` to an `HTTPRoute`.
   2. **ID collisions.** IDs are the 32-bit CRC32 of the name, so distinct 
names can share an ID.
   
   This PR:
   
   - Prefixes route, service and stream route names with an abbreviation of the 
resource kind (`ar`, `hr`, `gr`, `ing`, `tcpr`, `udpr`, `tlsr`), e.g. 
`hr_default_foo_0`. SSL names already carried the kind.
   - Generates IDs from the first 128 bits of the SHA-256 digest of the name 
(32 hex characters, within APISIX's 64-character ID limit).
   - Merges the two identical `GenID` implementations under `internal/id` and 
`pkg/id` into `internal/id`.
   
   This follows the same approach as Kong Ingress Controller, which prefixes 
generated route names with the kind (`httproute.<namespace>.<name>...`) and 
derives IDs as UUIDv5 from the name.
   
   ### Behavior change
   
   Generated route, service and stream route names change, and every generated 
ID changes once (routes, services, upstreams, SSLs, credentials). On the first 
sync after upgrading, the controller replaces the previous resources with the 
new ones. Anything keyed by these IDs or names on the APISIX side starts over, 
for example Prometheus series labelled by route or service ID and per-route 
plugin state such as local rate-limit counters. Consumer usernames are 
unchanged, since they are referenced by plugin configuration such as 
`consumer-restriction`.
   
   No CRD or API change.
   
   ### Tests
   
   - `TestSameNameResourcesOfDifferentKindsKeepDistinctIdentities` translates 
an `ApisixRoute`, `HTTPRoute`, `GRPCRoute` and `Ingress` with the same 
namespace and name, checks that no service or route ID is shared, and that all 
four survive in the store. Without the kind prefix it reports the shared 
service and route IDs and the `ApisixRoute` service is missing from the store.
   - e2e `Test ApisixRoute and HTTPRoute with the same name`: an `HTTPRoute` 
and an `ApisixRoute` named `same-name` on the same GatewayProxy both keep 
serving traffic, including after the `HTTPRoute` is updated.
   
   ### Pre-submission checklist:
   
   - [x] Did you explain what problem does this PR solve? Or what new features 
have been added?
   - [x] Have you added corresponding test cases?
   - [ ] Have you modified the corresponding document?
   - [x] 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: [email protected]

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

Reply via email to