Skip to content

Commit

Permalink
Order by group index.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Mar 30, 2024
1 parent 5419268 commit 45b0781
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,13 @@ private void ProcessEndpoints()
// We can allocate ports per endpoint
var portAllocator = new PortAllocator(10000);

var endpointIndexMap = new Dictionary<string, int>();

// Allocate ports for the endpoints
foreach (var e in endpoints)
{
endpointIndexMap[e.Name] = endpointIndexMap.Count;

int? targetPort = (resource, e.UriScheme, e.TargetPort) switch
{
// The port was specified so use it
Expand Down Expand Up @@ -537,16 +541,17 @@ private void ProcessEndpoints()

// First we group the endpoints by container port (aka destinations), this gives us the logical bindings or destinations
var endpointsByTargetPort = endpoints.GroupBy(e => e.TargetPort)
.Select(g => new
{
Port = g.Key,
Endpoints = g.ToArray(),
External = g.Any(e => e.IsExternal),
IsHttpOnly = g.All(e => e.UriScheme is "http" or "https"),
AnyH2 = g.Any(e => e.Transport is "http2"),
UniqueSchemes = g.Select(e => e.UriScheme).Distinct().ToArray()
})
.ToList();
.Select(g => new
{
Port = g.Key,
Endpoints = g.ToArray(),
External = g.Any(e => e.IsExternal),
IsHttpOnly = g.All(e => e.UriScheme is "http" or "https"),
AnyH2 = g.Any(e => e.Transport is "http2"),
UniqueSchemes = g.Select(e => e.UriScheme).Distinct().ToArray(),
Index = g.Min(e => endpointIndexMap[e.Name])
})
.ToList();

// Failure cases

Expand All @@ -573,7 +578,7 @@ static bool Compatible(string[] schemes) =>
}

// Get all http only groups
var httpOnlyEndpoints = endpointsByTargetPort.Where(g => g.IsHttpOnly).ToArray();
var httpOnlyEndpoints = endpointsByTargetPort.Where(g => g.IsHttpOnly).OrderBy(g => g.Index).ToArray();

// Do we only have one?
var httpIngress = httpOnlyEndpoints.Length == 1 ? httpOnlyEndpoints[0] : null;
Expand Down

0 comments on commit 45b0781

Please sign in to comment.