From 1412dd84feb5f869308b8f52e594fe2e11cdc6bd Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 6 Nov 2023 16:52:55 +0100 Subject: [PATCH] Get ports explicitly for internal or external endpoints --- Framework/KubernetesWorkflow/RunningContainers.cs | 3 +-- Framework/KubernetesWorkflow/RunningPod.cs | 9 +++++++-- Framework/KubernetesWorkflow/StartupWorkflow.cs | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Framework/KubernetesWorkflow/RunningContainers.cs b/Framework/KubernetesWorkflow/RunningContainers.cs index f49f1af..0410aed 100644 --- a/Framework/KubernetesWorkflow/RunningContainers.cs +++ b/Framework/KubernetesWorkflow/RunningContainers.cs @@ -64,8 +64,7 @@ namespace KubernetesWorkflow public Address GetInternalAddress(string portTag) { - var containerAddress = Addresses.Single(a => a.PortTag == portTag); - if (!containerAddress.IsInteral) throw new Exception(portTag + " refers to an external port"); + var containerAddress = Addresses.Single(a => a.PortTag == portTag && a.IsInteral); return containerAddress.Address; } } diff --git a/Framework/KubernetesWorkflow/RunningPod.cs b/Framework/KubernetesWorkflow/RunningPod.cs index 2ec7162..f27d5f3 100644 --- a/Framework/KubernetesWorkflow/RunningPod.cs +++ b/Framework/KubernetesWorkflow/RunningPod.cs @@ -29,7 +29,7 @@ namespace KubernetesWorkflow [JsonIgnore] internal RunnerLocation RunnerLocation { get; set; } - public Port GetServicePorts(ContainerRecipe recipe, string tag) + public Port GetInternalServicePorts(ContainerRecipe recipe, string tag) { if (InternalService != null) { @@ -37,13 +37,18 @@ namespace KubernetesWorkflow if (p != null) return p; } + throw new Exception($"Unable to find internal port by tag '{tag}' for recipe '{recipe.Name}'."); + } + + public Port GetExternalServicePorts(ContainerRecipe recipe, string tag) + { if (ExternalService != null) { var p = ExternalService.GetServicePortForRecipeAndTag(recipe, tag); if (p != null) return p; } - throw new Exception($"Unable to find port by tag '{tag}' for recipe '{recipe.Name}'."); + throw new Exception($"Unable to find external port by tag '{tag}' for recipe '{recipe.Name}'."); } public Port[] GetServicePortsForContainer(ContainerRecipe recipe) diff --git a/Framework/KubernetesWorkflow/StartupWorkflow.cs b/Framework/KubernetesWorkflow/StartupWorkflow.cs index 0eadb95..3e13c55 100644 --- a/Framework/KubernetesWorkflow/StartupWorkflow.cs +++ b/Framework/KubernetesWorkflow/StartupWorkflow.cs @@ -151,6 +151,7 @@ namespace KubernetesWorkflow foreach (var exposedPort in recipe.ExposedPorts) { result.Add(new ContainerAddress(exposedPort.Tag, GetContainerExternalAddress(startResult, recipe, exposedPort.Tag), false)); + result.Add(new ContainerAddress(exposedPort.Tag, GetContainerInternalAddress(startResult, recipe, exposedPort.Tag), true)); } foreach (var internalPort in recipe.InternalPorts) { @@ -162,7 +163,7 @@ namespace KubernetesWorkflow private static Address GetContainerExternalAddress(StartResult startResult, ContainerRecipe recipe, string tag) { - var port = startResult.GetServicePorts(recipe, tag); + var port = startResult.GetExternalServicePorts(recipe, tag); return new Address( startResult.Cluster.HostAddress, @@ -172,7 +173,7 @@ namespace KubernetesWorkflow private Address GetContainerInternalAddress(StartResult startResult, ContainerRecipe recipe, string tag) { var serviceName = startResult.InternalService!.Name; - var port = startResult.GetServicePorts(recipe, tag); + var port = startResult.GetInternalServicePorts(recipe, tag); return new Address( $"http://{serviceName}", port.Number);