Skip to content

Commit 9427a74

Browse files
authored
Remove host override from container sample (#2109)
1 parent b83aece commit 9427a74

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

examples/Container/Frontend/Balancer/ConfigurableResolverFactory.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -24,6 +24,8 @@ namespace Frontend.Balancer
2424
{
2525
public class ConfigurableResolverFactory : ResolverFactory
2626
{
27+
private static readonly BalancerAttributesKey<string> HostOverrideKey = new BalancerAttributesKey<string>("HostOverride");
28+
2729
private readonly ResolverFactory _innerResolverFactory;
2830
private readonly BalancerConfiguration _balancerConfiguration;
2931

@@ -101,6 +103,13 @@ private void RaiseResult(ResolverResult result)
101103
// DNS results change order between refreshes.
102104
// Explicitly order by host to keep result order consistent.
103105
var orderedAddresses = result.Addresses.OrderBy(a => a.EndPoint.Host).ToList();
106+
// Remove host override from addresses so the destination IP address is available.
107+
// The sample does this because the server returns the IP address to the client.
108+
// This makes it clear that gRPC calls are balanced between pods.
109+
foreach (var address in orderedAddresses)
110+
{
111+
((IDictionary<string, object?>)address.Attributes).Remove(HostOverrideKey.Key);
112+
}
104113
_listener(ResolverResult.ForResult(orderedAddresses, serviceConfig, Status.DefaultSuccess));
105114
}
106115
else

0 commit comments

Comments
 (0)