Skip to content

Commit bcf7ff1

Browse files
authored
fix: xds name schema v2 (#6638)
* rename route config Signed-off-by: Huabing (Robin) Zhao <[email protected]> * rename HCM statPrefix Signed-off-by: Huabing (Robin) Zhao <[email protected]> * rename virtual host Signed-off-by: Huabing (Robin) Zhao <[email protected]> * fix test Signed-off-by: Huabing (Robin) Zhao <[email protected]> * minor change Signed-off-by: Huabing (Robin) Zhao <[email protected]> * address comment Signed-off-by: Huabing (Robin) Zhao <[email protected]> --------- Signed-off-by: Huabing (Robin) Zhao <[email protected]>
1 parent 2feb1f6 commit bcf7ff1

File tree

5 files changed

+42
-31
lines changed

5 files changed

+42
-31
lines changed

internal/xds/translator/listener.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -335,23 +335,13 @@ func (t *Translator) addHCMToXDSListener(
335335
}
336336

337337
// HTTP filter configuration
338-
var statPrefix string
339-
if irListener.TLS != nil {
340-
statPrefix = "https"
341-
} else {
342-
statPrefix = "http"
343-
}
344-
345-
// Append port to the statPrefix.
346-
statPrefix = strings.Join([]string{statPrefix, strconv.Itoa(int(irListener.Port))}, "-")
347-
348338
// Client IP detection
349339
useRemoteAddress := true
350340
originalIPDetectionExtensions := originalIPDetectionExtensions(irListener.ClientIPDetection)
351341
if originalIPDetectionExtensions != nil {
352342
useRemoteAddress = false
353343
}
354-
344+
statPrefix := hcmStatPrefix(irListener, t.xdsNameSchemeV2())
355345
mgr := &hcmv3.HttpConnectionManager{
356346
AccessLog: al,
357347
CodecType: hcmv3.HttpConnectionManager_AUTO,
@@ -360,7 +350,7 @@ func (t *Translator) addHCMToXDSListener(
360350
Rds: &hcmv3.Rds{
361351
ConfigSource: makeConfigSource(),
362352
// Configure route name to be found via RDS.
363-
RouteConfigName: routeConfigName(irListener),
353+
RouteConfigName: routeConfigName(irListener, t.xdsNameSchemeV2()),
364354
},
365355
},
366356
HttpProtocolOptions: http1ProtocolOptions(irListener.HTTP1),
@@ -500,9 +490,24 @@ func (t *Translator) addHCMToXDSListener(
500490
return nil
501491
}
502492

503-
func routeConfigName(irListener *ir.HTTPListener) string {
504-
// TODO(zhaohuabing): change the routeConfig name for HTTP listeners because they are merged into one route config
505-
return irListener.Name
493+
func hcmStatPrefix(irListener *ir.HTTPListener, nameSchemeV2 bool) string {
494+
statPrefix := "http"
495+
if irListener.TLS != nil {
496+
statPrefix = "https"
497+
}
498+
499+
if nameSchemeV2 {
500+
return fmt.Sprintf("%s-%d", statPrefix, irListener.ExternalPort)
501+
}
502+
return fmt.Sprintf("%s-%d", statPrefix, irListener.Port)
503+
}
504+
505+
// use the same name for the route config as the filter chain name, as they're 1:1 mapping.
506+
func routeConfigName(irListener *ir.HTTPListener, nameSchemeV2 bool) string {
507+
if irListener.TLS != nil {
508+
return httpsListenerFilterChainName(irListener)
509+
}
510+
return httpListenerDefaultFilterChainName(irListener, nameSchemeV2)
506511
}
507512

508513
// port value is used for the default filter chain name for HTTP listeners, as multiple HTTP listeners are merged into
@@ -515,7 +520,7 @@ func httpListenerDefaultFilterChainName(irListener *ir.HTTPListener, nameSchemeV
515520
return irListener.Name
516521
}
517522

518-
// irListener name is used as the filter chain name for HTTPS listener, as Listener is 1:1 mapping to the filter chain
523+
// irListener name is used as the filter chain name for HTTPS listener, as HTTPS Listener is 1:1 mapping to the filter chain.
519524
// The Gateway API layer ensures that each listener has a unique combination of hostname and port.
520525
func httpsListenerFilterChainName(irListener *ir.HTTPListener) string {
521526
return irListener.Name

internal/xds/translator/testdata/out/xds-ir/xds-name-scheme-v2.listeners.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
configSource:
2626
ads: {}
2727
resourceApiVersion: V3
28-
routeConfigName: envoy-gateway/gateway-1/http1
28+
routeConfigName: http-80
2929
serverHeaderTransformation: PASS_THROUGH
30-
statPrefix: http-10080
30+
statPrefix: http-80
3131
useRemoteAddress: true
3232
name: http-80
3333
maxConnectionsToAcceptPerSocketEvent: 1
@@ -65,7 +65,7 @@
6565
resourceApiVersion: V3
6666
routeConfigName: envoy-gateway/gateway-1/https1
6767
serverHeaderTransformation: PASS_THROUGH
68-
statPrefix: https-10443
68+
statPrefix: https-443
6969
useRemoteAddress: true
7070
name: envoy-gateway/gateway-1/https1
7171
transportSocket:
@@ -110,7 +110,7 @@
110110
resourceApiVersion: V3
111111
routeConfigName: envoy-gateway/gateway-1/https2
112112
serverHeaderTransformation: PASS_THROUGH
113-
statPrefix: https-10443
113+
statPrefix: https-443
114114
useRemoteAddress: true
115115
name: envoy-gateway/gateway-1/https2
116116
transportSocket:
@@ -168,7 +168,7 @@
168168
resourceApiVersion: V3
169169
routeConfigName: envoy-gateway/gateway-2/https-http3
170170
serverHeaderTransformation: PASS_THROUGH
171-
statPrefix: https-11443
171+
statPrefix: https-1443
172172
useRemoteAddress: true
173173
name: envoy-gateway/gateway-2/https-http3
174174
transportSocket:
@@ -222,7 +222,7 @@
222222
resourceApiVersion: V3
223223
routeConfigName: envoy-gateway/gateway-2/https-http3
224224
serverHeaderTransformation: PASS_THROUGH
225-
statPrefix: https-11443
225+
statPrefix: https-1443
226226
useRemoteAddress: true
227227
name: envoy-gateway/gateway-2/https-http3
228228
transportSocket:

internal/xds/translator/testdata/out/xds-ir/xds-name-scheme-v2.routes.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
- ignorePortInHostMatching: true
2-
name: envoy-gateway/gateway-1/http1
2+
name: http-80
33
virtualHosts:
44
- domains:
55
- foo.net
6-
name: envoy-gateway/gateway-1/http1/foo_net
6+
name: foo_net
77
routes:
88
- match:
99
prefix: /
@@ -14,7 +14,7 @@
1414
- upgradeType: websocket
1515
- domains:
1616
- bar.net
17-
name: envoy-gateway/gateway-1/http2/bar_net
17+
name: bar_net
1818
routes:
1919
- match:
2020
prefix: /
@@ -28,7 +28,7 @@
2828
virtualHosts:
2929
- domains:
3030
- foo.com
31-
name: envoy-gateway/gateway-1/https1/foo_com
31+
name: foo_com
3232
routes:
3333
- match:
3434
prefix: /
@@ -42,7 +42,7 @@
4242
virtualHosts:
4343
- domains:
4444
- bar.com
45-
name: envoy-gateway/gateway-1/https2/bar_com
45+
name: bar_com
4646
routes:
4747
- match:
4848
prefix: /
@@ -56,7 +56,7 @@
5656
virtualHosts:
5757
- domains:
5858
- '*'
59-
name: envoy-gateway/gateway-2/https-http3/*
59+
name: '*'
6060
routes:
6161
- match:
6262
prefix: /

internal/xds/translator/translator.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func (t *Translator) processHTTPListenerXdsTranslation(
446446
routeCfgName = findXdsHTTPRouteConfigName(tcpXDSListener)
447447
// If the route config name is not found, we use the current ir Listener name as the route config name to create a new route config.
448448
if routeCfgName == "" {
449-
routeCfgName = routeConfigName(httpListener)
449+
routeCfgName = routeConfigName(httpListener, t.xdsNameSchemeV2())
450450
}
451451

452452
// Create a route config if we have not found one yet
@@ -504,7 +504,7 @@ func (t *Translator) addRouteToRouteConfig(
504504
underscoredHostname := strings.ReplaceAll(httpRoute.Hostname, ".", "_")
505505
// Allocate virtual host for this httpRoute.
506506
vHost = &routev3.VirtualHost{
507-
Name: virtualHostName(httpListener, underscoredHostname),
507+
Name: virtualHostName(httpListener, underscoredHostname, t.xdsNameSchemeV2()),
508508
Domains: []string{httpRoute.Hostname},
509509
Metadata: buildXdsMetadata(httpListener.Metadata),
510510
}
@@ -656,7 +656,10 @@ func (t *Translator) addRouteToRouteConfig(
656656
return errs
657657
}
658658

659-
func virtualHostName(httpListener *ir.HTTPListener, underscoredHostname string) string {
659+
func virtualHostName(httpListener *ir.HTTPListener, underscoredHostname string, xdsNameSchemeV2 bool) string {
660+
if xdsNameSchemeV2 {
661+
return underscoredHostname
662+
}
660663
return fmt.Sprintf("%s/%s", httpListener.Name, underscoredHostname)
661664
}
662665

test/e2e/tests/connection_limit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ var ConnectionLimitTest = suite.ConformanceTest{
8585
}
8686

8787
prefix := "http-10080"
88+
if XDSNameSchemeV2() {
89+
prefix = "http-80"
90+
}
8891
gtwName := "connection-limit-gateway"
8992
promQL := fmt.Sprintf(`envoy_connection_limit_limited_connections{envoy_connection_limit_prefix="%s",gateway_envoyproxy_io_owning_gateway_name="%s"}`, prefix, gtwName)
9093

0 commit comments

Comments
 (0)