in src/routingmanager/Envoy/EnvoyConfigBuilder.cs [71:172]
private void ConfigureClusters(V1Service triggerService, IEnumerable<PodTriggerConfig> podTriggers, EnvoyConfig envoyConfig, V1ServicePort servicePort)
{
var portName = (servicePort.Name ?? string.Empty).ToLowerInvariant();
var cloneCluster = new Cluster
{
Name = string.Format(_serviceCloneWithPortsFormatString, servicePort.Port, servicePort.TargetPort.Value),
ConnectTimeout = "1.00s",
Type = "strict_dns",
LoadAssignment = new LoadAssignment
{
ClusterName = string.Format(_serviceCloneWithPortsFormatString, servicePort.Port, servicePort.TargetPort.Value),
Endpoints = new List<EndpointElement>
{
new EndpointElement
{
LbEndpoints = new List<LbEndpoint>
{
new LbEndpoint
{
Endpoint = new LbEndpointEndpoint
{
Address = new EndpointAddress
{
SocketAddress = new SocketAddress
{
Address = $"{KubernetesUtilities.GetKubernetesResourceNamePreserveSuffix(triggerService.Metadata.Name, $"{Constants.ClonedSuffix}-svc")}.{triggerService.Metadata.NamespaceProperty}",
// envoy listens on the target port but sends the request to the source port
// of that target so that recepient service can then send it to the target port
PortValue = servicePort.Port
}
}
}
}
}
}
}
}
};
if (_http2GrpcPortRegex.IsMatch(portName))
{
cloneCluster.Http2ProtocolOptions = new object();
}
else if (_http1PortRegex.IsMatch(portName))
{
cloneCluster.Http1ProtocolOptions = new object();
}
envoyConfig.StaticResources.Clusters.Add(cloneCluster);
foreach (var podTrigger in podTriggers)
{
var routeCluster = new Cluster
{
Name = string.Format(_serviceStableWithHeaderWithPortsFormatString, podTrigger.RouteOnHeader.Key, podTrigger.RouteOnHeader.Value, servicePort.Port, servicePort.TargetPort.Value),
ConnectTimeout = "1.00s",
Type = "static",
LoadAssignment = new LoadAssignment
{
ClusterName = string.Format(_serviceStableWithHeaderWithPortsFormatString, podTrigger.RouteOnHeader.Key, podTrigger.RouteOnHeader.Value, servicePort.Port, servicePort.TargetPort.Value),
Endpoints = new List<EndpointElement>
{
new EndpointElement
{
LbEndpoints = new List<LbEndpoint>
{
{
new LbEndpoint
{
Endpoint = new LbEndpointEndpoint
{
Address = new EndpointAddress
{
SocketAddress = new SocketAddress
{
Address = podTrigger.TriggerPodIp,
// envoy listens on the target port and sends the request on the target port itself
// because we are directly sending the request to the pod
PortValue = long.Parse(servicePort.TargetPort.Value)
}
}
}
}
}
}
}
}
}
};
if (_http2GrpcPortRegex.IsMatch(portName))
{
routeCluster.Http2ProtocolOptions = new object();
}
else if (_http1PortRegex.IsMatch(portName))
{
routeCluster.Http1ProtocolOptions = new object();
}
envoyConfig.StaticResources.Clusters.Add(routeCluster);
}
}