Removes runnerlocation field from StartResult.

This commit is contained in:
benbierens 2023-11-07 13:06:49 +01:00
parent eecdcf308d
commit 6e60a8614c
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 40 additions and 32 deletions

View File

@ -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);
}
}
}

View File

@ -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)

View File

@ -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

View File

@ -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)