in src/routingmanager/Envoy/EnvoyConfigBuilder.cs [227:307]
private void ConfigureVirtualHostForPrefixedMatchAllHost(V1Service triggerService, RoutingStateEstablisherInput routingStateEstablisherInput, IEnumerable<PodTriggerConfig> allPodTriggersInNamespace, V1ServicePort servicePort, IList<VirtualHost> httpFilterVirtualHosts)
{
if (routingStateEstablisherInput.IngressTriggers.Any(ingressTrigger => string.IsNullOrWhiteSpace(ingressTrigger.Host) && string.IsNullOrWhiteSpace(ingressTrigger.AgicBackendHostName))
|| routingStateEstablisherInput.LoadBalancerTrigger != null)
{
foreach (var podTrigger in allPodTriggersInNamespace)
{
// If we have already configured virtual host for another pod trigger with the same route on header value, so skipping this pod trigger
var existingVirtualHost = httpFilterVirtualHosts.Where(virtualHost => FirstDomainStartsWithRoutingHeaderValue(virtualHost.Domains, podTrigger.RouteOnHeader.Value)).FirstOrDefault();
if (existingVirtualHost != null)
{
// Handle the case where two same routing header value are present for podTrigger
if (routingStateEstablisherInput.PodTriggers != null && routingStateEstablisherInput.PodTriggers.Contains(podTrigger))
{
// This is safe to assume RouteElement and a Cluster are not null as they are defined below.
existingVirtualHost.Routes.First().Route.Cluster = string.Format(_serviceStableWithHeaderWithPortsFormatString, podTrigger.RouteOnHeader.Key, podTrigger.RouteOnHeader.Value, servicePort.Port, servicePort.TargetPort.Value);
}
else
{
_log.Info("While configuring envoy for ingress triggers, Another pod trigger with the same routing header value '{0}' was already used for configuring the ingress triggers, so skipping this pod trigger"
, new PII(podTrigger.RouteOnHeader.Value));
}
continue;
}
_log.Info("Configuring envoy for service '{0}' for port '{1}' for empty host : Pod trigger : '{2}'", new PII(triggerService.Metadata.Name), new PII(servicePort.Port.ToString()), new PII(podTrigger.TriggerEntityName));
var domains = new List<string> { $"{podTrigger.RouteOnHeader.Value}.*" };
var ingressVirtualHost =
new VirtualHost
{
// We are only adding the rule for domain starting with routing header. We are not adding the catch all * here on purpose.
// This is because there is at least one pod trigger for sure. We will be adding the * catch all rule as part of that.
Name = $"listener_{servicePort.Port}_{servicePort.TargetPort.Value}_route_ingress_withDomain_{string.Join(',', domains)}",
Domains = domains,
Routes = new List<RouteElement>
{
new RouteElement
{
Match = new Match
{
Prefix = "/"
},
// Will add Route below
RequestHeadersToAdd = new List<RequestHeadersToAdd>
{
new RequestHeadersToAdd
{
Header = new RequestHeaderToAdd
{
Key = podTrigger.RouteOnHeader.Key,
Value = podTrigger.RouteOnHeader.Value
},
Append = false
}
}
}
}
};
if (routingStateEstablisherInput.PodTriggers != null && routingStateEstablisherInput.PodTriggers.Contains(podTrigger))
{
// This means input.TriggerService has an ingress and pod trigger both, so we need to route to service_stable for the given domains
ingressVirtualHost.Routes.First().Route = new Route
{
Cluster = string.Format(_serviceStableWithHeaderWithPortsFormatString, podTrigger.RouteOnHeader.Key, podTrigger.RouteOnHeader.Value, servicePort.Port, servicePort.TargetPort.Value)
};
}
else
{
ingressVirtualHost.Routes.First().Route = new Route
{
Cluster = string.Format(_serviceCloneWithPortsFormatString, servicePort.Port, servicePort.TargetPort.Value)
};
}
// Add to the last added listener above. There is always only a single Filter chain and a single filter in that.
httpFilterVirtualHosts.Add(ingressVirtualHost);
}
}
}