2023-11-06 14:33:47 +01:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Utils;
|
2023-06-21 08:28:40 +02:00
|
|
|
|
|
|
|
|
|
namespace KubernetesWorkflow
|
2023-04-12 13:53:55 +02:00
|
|
|
|
{
|
|
|
|
|
public class RunningContainers
|
|
|
|
|
{
|
2023-11-06 14:33:47 +01:00
|
|
|
|
public RunningContainers(StartupConfig startupConfig, StartResult startResult, RunningContainer[] containers)
|
2023-04-12 13:53:55 +02:00
|
|
|
|
{
|
|
|
|
|
StartupConfig = startupConfig;
|
2023-11-06 14:33:47 +01:00
|
|
|
|
StartResult = startResult;
|
2023-04-12 13:53:55 +02:00
|
|
|
|
Containers = containers;
|
2023-11-06 14:33:47 +01:00
|
|
|
|
|
|
|
|
|
foreach (var c in containers) c.RunningContainers = this;
|
2023-04-12 13:53:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public StartupConfig StartupConfig { get; }
|
2023-11-06 14:33:47 +01:00
|
|
|
|
public StartResult StartResult { get; }
|
2023-04-12 13:53:55 +02:00
|
|
|
|
public RunningContainer[] Containers { get; }
|
2023-04-13 14:36:17 +02:00
|
|
|
|
|
2023-11-06 14:33:47 +01:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return $"{Containers.Length}x '{Containers.First().Name}'"; }
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 14:36:17 +02:00
|
|
|
|
public string Describe()
|
|
|
|
|
{
|
2023-04-30 10:56:19 +02:00
|
|
|
|
return string.Join(",", Containers.Select(c => c.Name));
|
2023-04-13 14:36:17 +02:00
|
|
|
|
}
|
2023-04-12 13:53:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RunningContainer
|
|
|
|
|
{
|
2023-11-06 14:33:47 +01:00
|
|
|
|
public RunningContainer(string name, ContainerRecipe recipe, ContainerAddress[] addresses)
|
2023-04-12 13:53:55 +02:00
|
|
|
|
{
|
2023-06-23 10:35:23 +02:00
|
|
|
|
Name = name;
|
2023-11-06 14:33:47 +01:00
|
|
|
|
Recipe = recipe;
|
|
|
|
|
Addresses = addresses;
|
2023-04-12 13:53:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-30 10:56:19 +02:00
|
|
|
|
public string Name { get; }
|
2023-04-12 13:53:55 +02:00
|
|
|
|
public ContainerRecipe Recipe { get; }
|
2023-11-06 14:33:47 +01:00
|
|
|
|
public ContainerAddress[] Addresses { get; }
|
2023-08-15 11:01:18 +02:00
|
|
|
|
|
2023-11-06 14:33:47 +01:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public RunningContainers RunningContainers { get; internal set; } = null!;
|
2023-10-23 15:28:20 +02:00
|
|
|
|
|
2023-10-19 11:18:59 +02:00
|
|
|
|
public Address GetAddress(string portTag)
|
2023-09-11 16:57:57 +02:00
|
|
|
|
{
|
2023-11-06 14:33:47 +01:00
|
|
|
|
var containerAddress = Addresses.Single(a => a.PortTag == portTag);
|
|
|
|
|
if (containerAddress.IsInteral && RunningContainers.StartResult.RunnerLocation == RunnerLocation.ExternalToCluster)
|
2023-09-11 16:57:57 +02:00
|
|
|
|
{
|
2023-11-06 14:33:47 +01:00
|
|
|
|
throw new Exception("Attempt to access a container address created from an Internal port, " +
|
|
|
|
|
"while runner is located external to the cluster.");
|
2023-09-11 16:57:57 +02:00
|
|
|
|
}
|
2023-11-06 14:33:47 +01:00
|
|
|
|
return containerAddress.Address;
|
2023-09-11 16:57:57 +02:00
|
|
|
|
}
|
2023-04-12 13:53:55 +02:00
|
|
|
|
}
|
2023-08-07 10:44:48 +02:00
|
|
|
|
|
2023-11-06 14:33:47 +01:00
|
|
|
|
public class ContainerAddress
|
2023-10-19 11:08:30 +02:00
|
|
|
|
{
|
2023-11-06 14:33:47 +01:00
|
|
|
|
public ContainerAddress(string portTag, Address address, bool isInteral)
|
2023-10-19 11:08:30 +02:00
|
|
|
|
{
|
2023-11-06 14:33:47 +01:00
|
|
|
|
PortTag = portTag;
|
|
|
|
|
Address = address;
|
|
|
|
|
IsInteral = isInteral;
|
2023-10-19 11:08:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-06 14:33:47 +01:00
|
|
|
|
public string PortTag { get; }
|
|
|
|
|
public Address Address { get; }
|
|
|
|
|
public bool IsInteral { get; }
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"{PortTag} -> '{Address}'";
|
|
|
|
|
}
|
2023-10-19 11:08:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 10:44:48 +02:00
|
|
|
|
public static class RunningContainersExtensions
|
|
|
|
|
{
|
|
|
|
|
public static RunningContainer[] Containers(this RunningContainers[] runningContainers)
|
|
|
|
|
{
|
|
|
|
|
return runningContainers.SelectMany(c => c.Containers).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Describe(this RunningContainers[] runningContainers)
|
|
|
|
|
{
|
|
|
|
|
return string.Join(",", runningContainers.Select(c => c.Describe()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-12 13:53:55 +02:00
|
|
|
|
}
|