Skip to content

Commit c7e3908

Browse files
authored
refactor append metadata exchange filter (istio#48152)
1 parent 52a4005 commit c7e3908

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

pilot/pkg/networking/core/v1alpha3/listener_builder.go

+19-15
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,7 @@ func (lb *ListenerBuilder) buildHTTPConnectionManager(httpOpts *httpListenerOpts
378378

379379
// Metadata exchange filter needs to be added before any other HTTP filters are added. This is done to
380380
// ensure that mx filter comes before HTTP RBAC filter. This is related to https://github.com/istio/istio/issues/41066
381-
if features.MetadataExchange && !httpOpts.hbone && !lb.node.IsAmbient() {
382-
if features.NativeMetadataExchange && util.IsIstioVersionGE119(lb.node.IstioVersion) {
383-
if httpOpts.class == istionetworking.ListenerClassSidecarInbound {
384-
filters = append(filters, xdsfilters.SidecarInboundMetadataFilter)
385-
} else {
386-
if httpOpts.skipIstioMXHeaders {
387-
filters = append(filters, xdsfilters.SidecarOutboundMetadataFilterSkipHeaders)
388-
} else {
389-
filters = append(filters, xdsfilters.SidecarOutboundMetadataFilter)
390-
}
391-
}
392-
} else {
393-
filters = append(filters, xdsfilters.HTTPMx)
394-
}
395-
}
381+
filters = appendMxFilter(httpOpts, lb.node, filters)
396382
// TODO: how to deal with ext-authz? It will be in the ordering twice
397383
filters = append(filters, lb.authzCustomBuilder.BuildHTTP(httpOpts.class)...)
398384
filters = extension.PopAppendHTTP(filters, wasm, extensions.PluginPhase_AUTHN)
@@ -449,3 +435,21 @@ func (lb *ListenerBuilder) buildHTTPConnectionManager(httpOpts *httpListenerOpts
449435
}
450436
return connectionManager
451437
}
438+
439+
func appendMxFilter(httpOpts *httpListenerOpts, node *model.Proxy, filters []*hcm.HttpFilter) []*hcm.HttpFilter {
440+
if !features.MetadataExchange || httpOpts.hbone || node.IsAmbient() {
441+
return filters
442+
}
443+
if !features.NativeMetadataExchange || !util.IsIstioVersionGE119(node.IstioVersion) {
444+
return append(filters, xdsfilters.HTTPMx)
445+
}
446+
447+
if httpOpts.class == istionetworking.ListenerClassSidecarInbound {
448+
return append(filters, xdsfilters.SidecarInboundMetadataFilter)
449+
}
450+
451+
if httpOpts.skipIstioMXHeaders {
452+
return append(filters, xdsfilters.SidecarOutboundMetadataFilterSkipHeaders)
453+
}
454+
return append(filters, xdsfilters.SidecarOutboundMetadataFilter)
455+
}

0 commit comments

Comments
 (0)