diff --git a/src/library.tests/LocalEnvironmentManagerTests.cs b/src/library.tests/LocalEnvironmentManagerTests.cs index 3f2ba8f4b..256e43a83 100644 --- a/src/library.tests/LocalEnvironmentManagerTests.cs +++ b/src/library.tests/LocalEnvironmentManagerTests.cs @@ -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; @@ -269,6 +270,21 @@ public static IEnumerable 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() + } + }, + new Dictionary() + }; } [Theory] diff --git a/src/library/Connect/LocalEnvironmentManager.cs b/src/library/Connect/LocalEnvironmentManager.cs index 0acef2b42..6d38aadab 100644 --- a/src/library/Connect/LocalEnvironmentManager.cs +++ b/src/library/Connect/LocalEnvironmentManager.cs @@ -426,6 +426,12 @@ public IDictionary 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)