diff --git a/Framework/KubernetesWorkflow/K8sController.cs b/Framework/KubernetesWorkflow/K8sController.cs index c45e374..930ad1c 100644 --- a/Framework/KubernetesWorkflow/K8sController.cs +++ b/Framework/KubernetesWorkflow/K8sController.cs @@ -38,15 +38,9 @@ namespace KubernetesWorkflow var internalService = CreateInternalService(containerRecipes); var externalService = CreateExternalService(containerRecipes); - var result = new StartResult(cluster, containerRecipes, deployment, internalService, externalService); - result.RunnerLocation = DetermineRunnerLocation(deployment); - return result; - } + DetermineRunnerLocation(deployment); - private RunnerLocation DetermineRunnerLocation(RunningDeployment deployment) - { - var podInfo = GetPodInfo(deployment); - return RunnerLocationUtils.DetermineRunnerLocation(log, podInfo, cluster); + return new StartResult(cluster, containerRecipes, deployment, internalService, externalService); } public PodInfo GetPodInfo(RunningDeployment deployment) @@ -840,5 +834,12 @@ namespace KubernetesWorkflow return new PodInfo(name, ip, k8sNodeName); } + + private void DetermineRunnerLocation(RunningDeployment deployment) + { + if (RunnerLocationUtils.IsKnown()) return; + var podInfo = GetPodInfo(deployment); + RunnerLocationUtils.DetermineRunnerLocation(log, podInfo, cluster); + } } } diff --git a/Framework/KubernetesWorkflow/RunnerLocationUtils.cs b/Framework/KubernetesWorkflow/RunnerLocationUtils.cs index 429fc63..ca61c4c 100644 --- a/Framework/KubernetesWorkflow/RunnerLocationUtils.cs +++ b/Framework/KubernetesWorkflow/RunnerLocationUtils.cs @@ -12,14 +12,24 @@ namespace KubernetesWorkflow internal static class RunnerLocationUtils { - private static RunnerLocation knownLocation = RunnerLocation.Unknown; + private static RunnerLocation location = RunnerLocation.Unknown; - internal static RunnerLocation DetermineRunnerLocation(ILog log, PodInfo info, K8sCluster cluster) + internal static void DetermineRunnerLocation(ILog log, PodInfo info, K8sCluster cluster) { - if (knownLocation != RunnerLocation.Unknown) return knownLocation; - knownLocation = PingForLocation(info, cluster); - log.Log("Runner location set to: " + knownLocation); - return knownLocation; + if (location != RunnerLocation.Unknown) return; + location = PingForLocation(info, cluster); + log.Log("Runner location set to: " + location); + } + + internal static bool IsKnown() + { + return location != RunnerLocation.Unknown; + } + + internal static RunnerLocation GetRunnerLocation() + { + if (location == RunnerLocation.Unknown) throw new Exception("Runner location is unknown."); + return location; } private static RunnerLocation PingForLocation(PodInfo podInfo, K8sCluster cluster) diff --git a/Framework/KubernetesWorkflow/RunningContainers.cs b/Framework/KubernetesWorkflow/RunningContainers.cs index 619c636..602f6a4 100644 --- a/Framework/KubernetesWorkflow/RunningContainers.cs +++ b/Framework/KubernetesWorkflow/RunningContainers.cs @@ -52,21 +52,7 @@ namespace KubernetesWorkflow var addresses = Addresses.Where(a => a.PortTag == portTag).ToArray(); if (!addresses.Any()) throw new Exception("No addresses found for portTag: " + portTag); - var location = RunningContainers.StartResult.RunnerLocation; - ContainerAddress select = null!; - if (location == RunnerLocation.InternalToCluster) - { - select = addresses.Single(a => a.IsInteral); - } - else if (location == RunnerLocation.ExternalToCluster) - { - select = addresses.Single(a => !a.IsInteral); - } - else - { - throw new Exception("Running location not known."); - } - + var select = SelectAddress(addresses); log.Log($"Container '{Name}' selected for tag '{portTag}' address: '{select}'"); return select.Address; } @@ -76,6 +62,20 @@ namespace KubernetesWorkflow var containerAddress = Addresses.Single(a => a.PortTag == portTag && a.IsInteral); return containerAddress.Address; } + + private ContainerAddress SelectAddress(ContainerAddress[] addresses) + { + var location = RunnerLocationUtils.GetRunnerLocation(); + if (location == RunnerLocation.InternalToCluster) + { + return addresses.Single(a => a.IsInteral); + } + if (location == RunnerLocation.ExternalToCluster) + { + return addresses.Single(a => !a.IsInteral); + } + throw new Exception("Running location not known."); + } } public class ContainerAddress diff --git a/Framework/KubernetesWorkflow/RunningPod.cs b/Framework/KubernetesWorkflow/RunningPod.cs index f27d5f3..cdda1dc 100644 --- a/Framework/KubernetesWorkflow/RunningPod.cs +++ b/Framework/KubernetesWorkflow/RunningPod.cs @@ -26,9 +26,6 @@ namespace KubernetesWorkflow public RunningService? InternalService { get; } public RunningService? ExternalService { get; } - [JsonIgnore] - internal RunnerLocation RunnerLocation { get; set; } - public Port GetInternalServicePorts(ContainerRecipe recipe, string tag) { if (InternalService != null)