Removes runnerlocation field from StartResult.
This commit is contained in:
parent
eecdcf308d
commit
6e60a8614c
|
@ -38,15 +38,9 @@ namespace KubernetesWorkflow
|
||||||
var internalService = CreateInternalService(containerRecipes);
|
var internalService = CreateInternalService(containerRecipes);
|
||||||
var externalService = CreateExternalService(containerRecipes);
|
var externalService = CreateExternalService(containerRecipes);
|
||||||
|
|
||||||
var result = new StartResult(cluster, containerRecipes, deployment, internalService, externalService);
|
DetermineRunnerLocation(deployment);
|
||||||
result.RunnerLocation = DetermineRunnerLocation(deployment);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RunnerLocation DetermineRunnerLocation(RunningDeployment deployment)
|
return new StartResult(cluster, containerRecipes, deployment, internalService, externalService);
|
||||||
{
|
|
||||||
var podInfo = GetPodInfo(deployment);
|
|
||||||
return RunnerLocationUtils.DetermineRunnerLocation(log, podInfo, cluster);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PodInfo GetPodInfo(RunningDeployment deployment)
|
public PodInfo GetPodInfo(RunningDeployment deployment)
|
||||||
|
@ -840,5 +834,12 @@ namespace KubernetesWorkflow
|
||||||
|
|
||||||
return new PodInfo(name, ip, k8sNodeName);
|
return new PodInfo(name, ip, k8sNodeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DetermineRunnerLocation(RunningDeployment deployment)
|
||||||
|
{
|
||||||
|
if (RunnerLocationUtils.IsKnown()) return;
|
||||||
|
var podInfo = GetPodInfo(deployment);
|
||||||
|
RunnerLocationUtils.DetermineRunnerLocation(log, podInfo, cluster);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,24 @@ namespace KubernetesWorkflow
|
||||||
|
|
||||||
internal static class RunnerLocationUtils
|
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;
|
if (location != RunnerLocation.Unknown) return;
|
||||||
knownLocation = PingForLocation(info, cluster);
|
location = PingForLocation(info, cluster);
|
||||||
log.Log("Runner location set to: " + knownLocation);
|
log.Log("Runner location set to: " + location);
|
||||||
return knownLocation;
|
}
|
||||||
|
|
||||||
|
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)
|
private static RunnerLocation PingForLocation(PodInfo podInfo, K8sCluster cluster)
|
||||||
|
|
|
@ -52,21 +52,7 @@ namespace KubernetesWorkflow
|
||||||
var addresses = Addresses.Where(a => a.PortTag == portTag).ToArray();
|
var addresses = Addresses.Where(a => a.PortTag == portTag).ToArray();
|
||||||
if (!addresses.Any()) throw new Exception("No addresses found for portTag: " + portTag);
|
if (!addresses.Any()) throw new Exception("No addresses found for portTag: " + portTag);
|
||||||
|
|
||||||
var location = RunningContainers.StartResult.RunnerLocation;
|
var select = SelectAddress(addresses);
|
||||||
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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Log($"Container '{Name}' selected for tag '{portTag}' address: '{select}'");
|
log.Log($"Container '{Name}' selected for tag '{portTag}' address: '{select}'");
|
||||||
return select.Address;
|
return select.Address;
|
||||||
}
|
}
|
||||||
|
@ -76,6 +62,20 @@ namespace KubernetesWorkflow
|
||||||
var containerAddress = Addresses.Single(a => a.PortTag == portTag && a.IsInteral);
|
var containerAddress = Addresses.Single(a => a.PortTag == portTag && a.IsInteral);
|
||||||
return containerAddress.Address;
|
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
|
public class ContainerAddress
|
||||||
|
|
|
@ -26,9 +26,6 @@ namespace KubernetesWorkflow
|
||||||
public RunningService? InternalService { get; }
|
public RunningService? InternalService { get; }
|
||||||
public RunningService? ExternalService { get; }
|
public RunningService? ExternalService { get; }
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
internal RunnerLocation RunnerLocation { get; set; }
|
|
||||||
|
|
||||||
public Port GetInternalServicePorts(ContainerRecipe recipe, string tag)
|
public Port GetInternalServicePorts(ContainerRecipe recipe, string tag)
|
||||||
{
|
{
|
||||||
if (InternalService != null)
|
if (InternalService != null)
|
||||||
|
|
Loading…
Reference in New Issue