Skip to content

Commit

Permalink
Skip endpoint without ports in LocalEnvironmentManager (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
ababilone authored Jan 16, 2024
1 parent ace5937 commit 2f9219a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/library.tests/LocalEnvironmentManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.BridgeToKubernetes.Library.Connect;
using Microsoft.BridgeToKubernetes.Library.Models;
using Microsoft.BridgeToKubernetes.TestHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
Expand Down Expand Up @@ -269,6 +270,21 @@ public static IEnumerable<object[]> TestData()

}
};

// endpoints with no port should not throw
yield return new object[]
{
new[]
{
new EndpointInfo
{
DnsName = "noport.servicename",
LocalIP = System.Net.IPAddress.Parse("127.0.0.1"),
Ports = Array.Empty<PortPair>()
}
},
new Dictionary<string, string>()
};
}

[Theory]
Expand Down
6 changes: 6 additions & 0 deletions src/library/Connect/LocalEnvironmentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ public IDictionary<string, string> CreateEnvVariablesForK8s(WorkloadInfo workloa

foreach (var endpoint in workloadInfo.ReachableEndpoints)
{
if (endpoint.Ports == null || endpoint.Ports.Length == 0)
{
_log.Verbose("Skipping endpoint {0} as it has no configured port", endpoint.DnsName);
continue;
}

if (string.Equals(endpoint.DnsName, DAPR, StringComparison.OrdinalIgnoreCase))
{
// Override the DAPR env variables with the real local ports (that might be different if we neeeded to re-allocate them)
Expand Down

0 comments on commit 2f9219a

Please sign in to comment.