2023-08-15 09:01:18 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Utils;
|
2023-06-21 06:28:40 +00:00
|
|
|
|
|
|
|
|
|
namespace KubernetesWorkflow
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
|
|
|
|
public class RunningContainers
|
|
|
|
|
{
|
|
|
|
|
public RunningContainers(StartupConfig startupConfig, RunningPod runningPod, RunningContainer[] containers)
|
|
|
|
|
{
|
|
|
|
|
StartupConfig = startupConfig;
|
|
|
|
|
RunningPod = runningPod;
|
|
|
|
|
Containers = containers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public StartupConfig StartupConfig { get; }
|
|
|
|
|
public RunningPod RunningPod { get; }
|
|
|
|
|
public RunningContainer[] Containers { get; }
|
2023-04-13 12:36:17 +00:00
|
|
|
|
|
|
|
|
|
public string Describe()
|
|
|
|
|
{
|
2023-04-30 08:56:19 +00:00
|
|
|
|
return string.Join(",", Containers.Select(c => c.Name));
|
2023-04-13 12:36:17 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RunningContainer
|
|
|
|
|
{
|
2023-10-19 09:08:30 +00:00
|
|
|
|
public RunningContainer(RunningPod pod, ContainerRecipe recipe, Port[] servicePorts, string name, ContainerPort[] containerPorts)
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
|
|
|
|
Pod = pod;
|
|
|
|
|
Recipe = recipe;
|
|
|
|
|
ServicePorts = servicePorts;
|
2023-06-23 08:35:23 +00:00
|
|
|
|
Name = name;
|
2023-10-19 09:08:30 +00:00
|
|
|
|
ContainerPorts = containerPorts;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-30 08:56:19 +00:00
|
|
|
|
public string Name { get; }
|
2023-04-12 11:53:55 +00:00
|
|
|
|
public RunningPod Pod { get; }
|
|
|
|
|
public ContainerRecipe Recipe { get; }
|
|
|
|
|
public Port[] ServicePorts { get; }
|
2023-10-19 09:08:30 +00:00
|
|
|
|
public ContainerPort[] ContainerPorts { get; }
|
2023-08-15 09:01:18 +00:00
|
|
|
|
|
2023-10-19 09:18:59 +00:00
|
|
|
|
public Address GetAddress(string portTag)
|
2023-09-11 14:57:57 +00:00
|
|
|
|
{
|
2023-10-19 09:18:59 +00:00
|
|
|
|
var containerPort = ContainerPorts.Single(c => c.Port.Tag == portTag);
|
|
|
|
|
if (RunnerLocationUtils.DetermineRunnerLocation(this) == RunnerLocation.InternalToCluster)
|
2023-09-11 14:57:57 +00:00
|
|
|
|
{
|
2023-10-19 09:18:59 +00:00
|
|
|
|
return containerPort.InternalAddress;
|
2023-09-11 14:57:57 +00:00
|
|
|
|
}
|
2023-10-19 09:18:59 +00:00
|
|
|
|
return containerPort.ExternalAddress;
|
2023-09-11 14:57:57 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
2023-08-07 08:44:48 +00:00
|
|
|
|
|
2023-10-19 09:08:30 +00:00
|
|
|
|
public class ContainerPort
|
|
|
|
|
{
|
|
|
|
|
public ContainerPort(Port port, Address externalAddress, Address internalAddress)
|
|
|
|
|
{
|
|
|
|
|
Port = port;
|
|
|
|
|
ExternalAddress = externalAddress;
|
|
|
|
|
InternalAddress = internalAddress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Port Port { get; }
|
|
|
|
|
public Address ExternalAddress { get; }
|
|
|
|
|
public Address InternalAddress { get; }
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 08:44:48 +00: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 11:53:55 +00:00
|
|
|
|
}
|