Skip to content

Commit efc13f7

Browse files
committed
set listener and filter chain names, rollback other names
Signed-off-by: Huabing (Robin) Zhao <[email protected]>
1 parent 4073bfa commit efc13f7

29 files changed

+1037
-126
lines changed

.github/workflows/build_and_test.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ jobs:
104104
profile: gateway-namespace-mode
105105
- version: v1.33.1
106106
ipFamily: ipv4
107-
profile: port-as-listener-name
108-
- version: v1.32.5
109-
ipFamily: ipv6
110-
profile: port-as-listener-name
107+
profile: xds-name-scheme-v2
111108
steps:
112109
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
113110
- uses: ./tools/github-actions/setup-deps
@@ -157,10 +154,8 @@ jobs:
157154
profile: gateway-namespace-mode
158155
- version: v1.33.1
159156
ipFamily: ipv4
160-
profile: port-as-listener-name
161-
- version: v1.32.5
162-
ipFamily: ipv6
163-
profile: port-as-listener-name
157+
profile: xds-name-scheme-v2
158+
164159
steps:
165160
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
166161
- uses: ./tools/github-actions/setup-deps

api/v1alpha1/envoygateway_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (e *EnvoyGateway) GatewayNamespaceMode() bool {
111111

112112
// defaultRuntimeFlags are the default runtime flags for Envoy Gateway.
113113
var defaultRuntimeFlags = map[RuntimeFlag]bool{
114-
UseProtocolPortAsListenerName: false,
114+
XDSNameSchemeV2: false,
115115
}
116116

117117
// IsEnabled checks if a runtime flag is enabled in the EnvoyGateway configuration.

api/v1alpha1/envoygateway_types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ type EnvoyGatewaySpec struct {
102102
// RuntimeFlag defines a runtime flag used to guard breaking changes or risky experimental features in new Envoy Gateway releases.
103103
// A runtime flag may be enabled or disabled by default and can be toggled through the EnvoyGateway resource.
104104
// +enum
105-
// +kubebuilder:validation:Enum=UseProtocolPortAsListenerName
105+
// +kubebuilder:validation:Enum=xdsNameSchemeV2
106106
type RuntimeFlag string
107107

108108
const (
109-
// UseProtocolPortAsListenerName indicates that the listener name should be derived from the protocol and port.
110-
UseProtocolPortAsListenerName RuntimeFlag = "UseProtocolPortAsListenerName"
109+
// XDSNameSchemeV2 indicates that the xds name scheme v2 is used.
110+
// * The listener name will be generated using the protocol and port of the listener.
111+
XDSNameSchemeV2 RuntimeFlag = "XDSNameSchemeV2"
111112
)
112113

113114
// RuntimeFlags provide a mechanism to guard breaking changes or risky experimental features in new Envoy Gateway releases.

internal/gatewayapi/translator_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ func mustUnmarshal(t *testing.T, val []byte, out any) {
4747

4848
func TestTranslate(t *testing.T) {
4949
testCasesConfig := []struct {
50-
name string
51-
EnvoyPatchPolicyEnabled bool
52-
BackendEnabled bool
53-
GatewayNamespaceMode bool
54-
UseProtocolPortAsListenerName bool
50+
name string
51+
EnvoyPatchPolicyEnabled bool
52+
BackendEnabled bool
53+
GatewayNamespaceMode bool
5554
}{
5655
{
5756
name: "envoypatchpolicy-invalid-feature-disabled",
@@ -65,10 +64,6 @@ func TestTranslate(t *testing.T) {
6564
name: "gateway-namespace-mode-infra-httproute",
6665
GatewayNamespaceMode: true,
6766
},
68-
{
69-
name: "protocol-port-as-listener-name",
70-
UseProtocolPortAsListenerName: true,
71-
},
7267
}
7368

7469
inputFiles, err := filepath.Glob(filepath.Join("testdata", "*.in.yaml"))

internal/xds/translator/listener.go

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (t *Translator) buildXdsTCPListener(
200200
listener := &listenerv3.Listener{
201201
Name: xdsListenerName(
202202
listenerDetails.Name, listenerDetails.ExternalPort,
203-
corev3.SocketAddress_TCP, t.useProtocolPortAsListenerName()),
203+
corev3.SocketAddress_TCP, t.xdsNameSchemeV2()),
204204
AccessLog: al,
205205
SocketOptions: socketOptions,
206206
PerConnectionBufferLimitBytes: bufferLimitBytes,
@@ -227,12 +227,12 @@ func (t *Translator) buildXdsTCPListener(
227227
}
228228

229229
// xdsListenerName returns the name of the xDS listener in two formats:
230-
// 1. "tcp-80" if useProtocolPortAsListenerName is true.
231-
// 2. "default/gateway-1/http" if useProtocolPortAsListenerName is false.
230+
// 1. "tcp-80" if xdsNameSchemeV2 is true.
231+
// 2. "default/gateway-1/http" if xdsNameSchemeV2 is false.
232232
// The second format can cause unnecessary listener drains and will be removed in the future.
233233
// https://github.com/envoyproxy/gateway/issues/6534
234-
func xdsListenerName(name string, externalPort uint32, protocol corev3.SocketAddress_Protocol, useProtocolPortAsListenerName bool) string {
235-
if useProtocolPortAsListenerName {
234+
func xdsListenerName(name string, externalPort uint32, protocol corev3.SocketAddress_Protocol, xdsNameSchemeV2 bool) string {
235+
if xdsNameSchemeV2 {
236236
protocolType := "tcp"
237237
if protocol == corev3.SocketAddress_UDP {
238238
protocolType = "udp"
@@ -272,7 +272,7 @@ func (t *Translator) buildXdsQuicListener(
272272
}
273273
// Keep the listener name compatible with the old naming scheme
274274
listenerName := listenerDetails.Name + "-quic"
275-
if t.useProtocolPortAsListenerName() {
275+
if t.xdsNameSchemeV2() {
276276
listenerName = xdsListenerName(listenerDetails.Name, listenerDetails.ExternalPort, corev3.SocketAddress_UDP, true)
277277
}
278278
xdsListener := &listenerv3.Listener{
@@ -343,11 +343,7 @@ func (t *Translator) addHCMToXDSListener(
343343
}
344344

345345
// Append port to the statPrefix.
346-
if t.useProtocolPortAsListenerName() {
347-
statPrefix = strings.Join([]string{statPrefix, strconv.Itoa(int(irListener.ExternalPort))}, "-")
348-
} else {
349-
statPrefix = strings.Join([]string{statPrefix, strconv.Itoa(int(irListener.Port))}, "-")
350-
}
346+
statPrefix = strings.Join([]string{statPrefix, strconv.Itoa(int(irListener.Port))}, "-")
351347

352348
// Client IP detection
353349
useRemoteAddress := true
@@ -364,7 +360,7 @@ func (t *Translator) addHCMToXDSListener(
364360
Rds: &hcmv3.Rds{
365361
ConfigSource: makeConfigSource(),
366362
// Configure route name to be found via RDS.
367-
RouteConfigName: routeConfigName(irListener, t.useProtocolPortAsListenerName()),
363+
RouteConfigName: routeConfigName(irListener),
368364
},
369365
},
370366
HttpProtocolOptions: http1ProtocolOptions(irListener.HTTP1),
@@ -461,7 +457,7 @@ func (t *Translator) addHCMToXDSListener(
461457

462458
filterChain := &listenerv3.FilterChain{
463459
Filters: filters,
464-
Name: httpListenerFilterChainName(irListener, t.useProtocolPortAsListenerName()),
460+
Name: httpListenerFilterChainName(irListener),
465461
}
466462

467463
if irListener.TLS != nil {
@@ -486,7 +482,7 @@ func (t *Translator) addHCMToXDSListener(
486482
}
487483
filterChain.TransportSocket = tSocket
488484

489-
err := addServerNamesMatch(xdsListener, filterChain, irListener.Hostnames, t.useProtocolPortAsListenerName())
485+
err := addServerNamesMatch(xdsListener, filterChain, irListener.Hostnames)
490486
if err != nil {
491487
return err
492488
}
@@ -504,24 +500,16 @@ func (t *Translator) addHCMToXDSListener(
504500
return nil
505501
}
506502

507-
func routeConfigName(irListener *ir.HTTPListener, useProtocolPortAsListenerName bool) string {
508-
// If the ir Listener is HTTP, then the route is merged on the same port.
509-
if useProtocolPortAsListenerName && irListener.TLS == nil {
510-
return fmt.Sprintf("default-%d", irListener.ExternalPort)
511-
}
512-
// If the ir Listener is HTTPS, then each Listener has its own route config because we build a separate
513-
// filter chain for each SNI.
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
514505
return irListener.Name
515506
}
516507

517-
func httpListenerFilterChainName(irListener *ir.HTTPListener, useProtocolPortAsListenerName bool) string {
518-
return routeConfigName(irListener, useProtocolPortAsListenerName)
508+
func httpListenerFilterChainName(irListener *ir.HTTPListener) string {
509+
return irListener.Name
519510
}
520511

521-
func tcpListenerFilterChainName(xdsListener *listenerv3.Listener, irRoute *ir.TCPRoute, useProtocolPortAsListenerName bool) string {
522-
if useProtocolPortAsListenerName {
523-
return xdsListener.Name
524-
}
512+
func tcpListenerFilterChainName(irRoute *ir.TCPRoute) string {
525513
return irRoute.Name
526514
}
527515

@@ -592,12 +580,7 @@ func buildEarlyHeaderMutation(headers *ir.HeaderSettings) []*corev3.TypedExtensi
592580
}
593581
}
594582

595-
func addServerNamesMatch(
596-
xdsListener *listenerv3.Listener,
597-
filterChain *listenerv3.FilterChain,
598-
hostnames []string,
599-
useProtocolPortAsListenerName bool,
600-
) error {
583+
func addServerNamesMatch(xdsListener *listenerv3.Listener, filterChain *listenerv3.FilterChain, hostnames []string) error {
601584
// Skip adding ServerNames match for:
602585
// 1. nil listeners
603586
// 2. UDP (QUIC) listeners used for HTTP3
@@ -615,11 +598,6 @@ func addServerNamesMatch(
615598
ServerNames: hostnames,
616599
}
617600

618-
// Add hostname suffix to the filter chain name if useProtocolPortAsListenerName is false to avoid conflicts.
619-
if useProtocolPortAsListenerName {
620-
filterChain.Name = fmt.Sprintf("%s/%s", filterChain.Name, strings.ReplaceAll(strings.Join(hostnames, "-"), ".", "_"))
621-
}
622-
623601
if err := addXdsTLSInspectorFilter(xdsListener); err != nil {
624602
return err
625603
}
@@ -722,11 +700,7 @@ func (t *Translator) addXdsTCPFilterChain(
722700
}
723701

724702
filterChain := &listenerv3.FilterChain{
725-
Name: tcpListenerFilterChainName(
726-
xdsListener,
727-
irRoute,
728-
t.useProtocolPortAsListenerName(),
729-
),
703+
Name: tcpListenerFilterChainName(irRoute),
730704
Filters: filters,
731705
}
732706

@@ -735,7 +709,6 @@ func (t *Translator) addXdsTCPFilterChain(
735709
xdsListener,
736710
filterChain,
737711
irRoute.TLS.TLSInspectorConfig.SNIs,
738-
t.useProtocolPortAsListenerName(),
739712
)
740713
if err != nil {
741714
return err
@@ -751,7 +724,6 @@ func (t *Translator) addXdsTCPFilterChain(
751724
xdsListener,
752725
filterChain,
753726
snis,
754-
t.useProtocolPortAsListenerName(),
755727
)
756728
if err != nil {
757729
return err
@@ -1024,7 +996,7 @@ func buildXdsUDPListener(
1024996
clusterName string,
1025997
udpListener *ir.UDPListener,
1026998
accesslog *ir.AccessLog,
1027-
useProtocolPortAsListenerName bool,
999+
xdsNameSchemeV2 bool,
10281000
) (*listenerv3.Listener, error) {
10291001
if udpListener == nil {
10301002
return nil, errors.New("udp listener is nil")
@@ -1069,7 +1041,7 @@ func buildXdsUDPListener(
10691041
return nil, err
10701042
}
10711043
xdsListener := &listenerv3.Listener{
1072-
Name: xdsListenerName(udpListener.Name, udpListener.ExternalPort, corev3.SocketAddress_UDP, useProtocolPortAsListenerName),
1044+
Name: xdsListenerName(udpListener.Name, udpListener.ExternalPort, corev3.SocketAddress_UDP, xdsNameSchemeV2),
10731045
AccessLog: al,
10741046
Address: &corev3.Address{
10751047
Address: &corev3.Address_SocketAddress{

internal/xds/translator/server_names_match_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestAddServerNamesMatch(t *testing.T) {
9797
t.Run(tt.name, func(t *testing.T) {
9898
filterChain := &listenerv3.FilterChain{}
9999

100-
err := addServerNamesMatch(tt.xdsListener, filterChain, tt.hostnames, false)
100+
err := addServerNamesMatch(tt.xdsListener, filterChain, tt.hostnames)
101101
require.NoError(t, err)
102102

103103
// Check if filter chain match was added

internal/xds/translator/testdata/in/xds-ir/port-as-listener-name.yaml renamed to internal/xds/translator/testdata/in/xds-ir/xds-name-scheme-v1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ http:
100100
hostnames:
101101
- '*'
102102
http3:
103-
quicPort: 443
103+
quicPort: 1443
104104
isHTTP2: false
105105
path:
106106
escapedSlashesAction: UnescapeAndRedirect

0 commit comments

Comments
 (0)