Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: compute endpointType for all protocol types #2833

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/xds/translator/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@
EndpointTypeStatic
)

func buildEndpointType(settings []*ir.DestinationSetting) EndpointType {
// Get endpoint address type for xds cluster by returning the first DestinationSetting's AddressType,
// since there's no Mixed AddressType among all the DestinationSettings.
if settings == nil {
return EndpointTypeStatic
}

Check warning on line 65 in internal/xds/translator/cluster.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/cluster.go#L64-L65

Added lines #L64 - L65 were not covered by tests

addrType := settings[0].AddressType

if addrType != nil && *addrType == ir.FQDN {
return EndpointTypeDNS
}

return EndpointTypeStatic
}

func buildXdsCluster(args *xdsClusterArgs) *clusterv3.Cluster {
cluster := &clusterv3.Cluster{
Name: args.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
tcp:
- name: "tls-passthrough"
- name: "tls-passthrough-foo"
address: "0.0.0.0"
port: 10080
tls:
passthrough:
snis:
- foo.com
destination:
name: "tls-passthrough-dest"
name: "tls-passthrough-foo-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000
- host: "5.6.7.8"
port: 50001
- name: "tls-passthrough-bar"
address: "0.0.0.0"
port: 10081
tls:
passthrough:
snis:
- bar.com
destination:
name: "tls-passthrough-bar-dest"
settings:
- endpoints:
- host: "bar"
port: 50000
addressType: FQDN
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,36 @@
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: tls-passthrough-dest
serviceName: tls-passthrough-foo-dest
lbPolicy: LEAST_REQUEST
name: tls-passthrough-dest
name: tls-passthrough-foo-dest
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
- circuitBreakers:
thresholds:
- maxRetries: 1024
commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
dnsRefreshRate: 30s
lbPolicy: LEAST_REQUEST
loadAssignment:
clusterName: tls-passthrough-bar-dest
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: bar
portValue: 50000
loadBalancingWeight: 1
loadBalancingWeight: 1
locality:
region: tls-passthrough-bar-dest/backend/0
name: tls-passthrough-bar-dest
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
respectDnsTtl: true
type: STRICT_DNS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- clusterName: tls-passthrough-dest
- clusterName: tls-passthrough-foo-dest
endpoints:
- lbEndpoints:
- endpoint:
Expand All @@ -15,4 +15,4 @@
loadBalancingWeight: 1
loadBalancingWeight: 1
locality:
region: tls-passthrough-dest/backend/0
region: tls-passthrough-foo-dest/backend/0
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,32 @@
- name: envoy.filters.network.tcp_proxy
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
cluster: tls-passthrough-dest
cluster: tls-passthrough-foo-dest
statPrefix: passthrough
listenerFilters:
- name: envoy.filters.listener.tls_inspector
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector
name: tls-passthrough
name: tls-passthrough-foo
perConnectionBufferLimitBytes: 32768
- address:
socketAddress:
address: 0.0.0.0
portValue: 10081
drainType: MODIFY_ONLY
filterChains:
- filterChainMatch:
serverNames:
- bar.com
filters:
- name: envoy.filters.network.tcp_proxy
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
cluster: tls-passthrough-bar-dest
statPrefix: passthrough
listenerFilters:
- name: envoy.filters.listener.tls_inspector
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector
name: tls-passthrough-bar
perConnectionBufferLimitBytes: 32768
17 changes: 3 additions & 14 deletions internal/xds/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func processTCPListenerXdsTranslation(tCtx *types.ResourceVersionTable, tcpListe
name: tcpListener.Destination.Name,
settings: tcpListener.Destination.Settings,
tSocket: nil,
endpointType: EndpointTypeStatic,
endpointType: buildEndpointType(tcpListener.Destination.Settings),
}); err != nil && !errors.Is(err, ErrXdsClusterExists) {
errs = errors.Join(errs, err)
}
Expand Down Expand Up @@ -402,7 +402,7 @@ func processUDPListenerXdsTranslation(tCtx *types.ResourceVersionTable, udpListe
name: udpListener.Destination.Name,
settings: udpListener.Destination.Settings,
tSocket: nil,
endpointType: EndpointTypeStatic,
endpointType: buildEndpointType(udpListener.Destination.Settings),
}); err != nil && !errors.Is(err, ErrXdsClusterExists) {
errs = errors.Join(errs, err)
}
Expand Down Expand Up @@ -495,17 +495,6 @@ func findXdsEndpoint(tCtx *types.ResourceVersionTable, name string) *endpointv3.

// processXdsCluster processes a xds cluster by its endpoint address type.
func processXdsCluster(tCtx *types.ResourceVersionTable, httpRoute *ir.HTTPRoute, http1Settings *ir.HTTP1Settings) error {
// Get endpoint address type for xds cluster by returning the first DestinationSetting's AddressType,
// since there's no Mixed AddressType among all the DestinationSettings.
addrTypeState := httpRoute.Destination.Settings[0].AddressType

var endpointType EndpointType
if addrTypeState != nil && *addrTypeState == ir.FQDN {
endpointType = EndpointTypeDNS
} else {
endpointType = EndpointTypeStatic
}

var tSocket *corev3.TransportSocket

if httpRoute.Destination.Settings[0].TLS != nil {
Expand All @@ -528,7 +517,7 @@ func processXdsCluster(tCtx *types.ResourceVersionTable, httpRoute *ir.HTTPRoute
name: httpRoute.Destination.Name,
settings: httpRoute.Destination.Settings,
tSocket: tSocket,
endpointType: endpointType,
endpointType: buildEndpointType(httpRoute.Destination.Settings),
loadBalancer: httpRoute.LoadBalancer,
proxyProtocol: httpRoute.ProxyProtocol,
circuitBreaker: httpRoute.CircuitBreaker,
Expand Down