fix(kingress): include header match in duplicate-route dedup key (#3580)

Fix incorrect duplicate-route detection in the KIngress controller that caused header-differentiated routes to be silently dropped.
This commit is contained in:
shiyan
2026-03-24 16:17:46 +08:00
committed by GitHub
parent c75f741104
commit 213286bb9e
2 changed files with 202 additions and 1 deletions

View File

@@ -503,7 +503,7 @@ func (c *controller) ConvertHTTPRoute(convertOptions *common.ConvertOptions, wra
// Two duplicated rules in the same ingress.
if ingressRouteBuilder.Event == common.Normal {
pathFormat := wrapperHttpRoute.PathFormat()
pathFormat := wrapperHttpRoute.PathFormat() + kingressPathHeadersKey(httpPath.Headers)
if definedRules.Contains(pathFormat) {
ingressRouteBuilder.PreIngress = cfg
ingressRouteBuilder.Event = common.DuplicatedRoute
@@ -726,3 +726,25 @@ func isIngressPublic(ingSpec *ingress.IngressSpec) bool {
}
return false
}
// kingressPathHeadersKey builds a stable string from path-level headers for use
// in duplicate-route detection. KIngress paths are distinguished by headers
// (not by URL path), so the dedup key must include header information.
func kingressPathHeadersKey(headers map[string]ingress.HeaderMatch) string {
if len(headers) == 0 {
return ""
}
keys := make([]string, 0, len(headers))
for k := range headers {
keys = append(keys, k)
}
sort.Strings(keys)
var sb strings.Builder
for _, k := range keys {
sb.WriteByte('\x00')
sb.WriteString(k)
sb.WriteByte('=')
sb.WriteString(headers[k].Exact)
}
return sb.String()
}