2023-11-06 13:33:47 +00:00
|
|
|
|
using k8s;
|
|
|
|
|
using k8s.Models;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace KubernetesWorkflow
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-11-06 13:33:47 +00:00
|
|
|
|
public class StartResult
|
|
|
|
|
{
|
|
|
|
|
public StartResult(
|
|
|
|
|
K8sCluster cluster,
|
|
|
|
|
ContainerRecipe[] containerRecipes,
|
|
|
|
|
RunningDeployment deployment,
|
|
|
|
|
RunningService? internalService,
|
|
|
|
|
RunningService? externalService)
|
|
|
|
|
{
|
|
|
|
|
Cluster = cluster;
|
|
|
|
|
ContainerRecipes = containerRecipes;
|
|
|
|
|
Deployment = deployment;
|
|
|
|
|
InternalService = internalService;
|
|
|
|
|
ExternalService = externalService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public K8sCluster Cluster { get; }
|
|
|
|
|
public ContainerRecipe[] ContainerRecipes { get; }
|
|
|
|
|
public RunningDeployment Deployment { get; }
|
|
|
|
|
public RunningService? InternalService { get; }
|
|
|
|
|
public RunningService? ExternalService { get; }
|
|
|
|
|
|
2023-11-06 15:52:55 +00:00
|
|
|
|
public Port GetInternalServicePorts(ContainerRecipe recipe, string tag)
|
2023-11-06 13:33:47 +00:00
|
|
|
|
{
|
|
|
|
|
if (InternalService != null)
|
|
|
|
|
{
|
|
|
|
|
var p = InternalService.GetServicePortForRecipeAndTag(recipe, tag);
|
|
|
|
|
if (p != null) return p;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-06 15:52:55 +00:00
|
|
|
|
throw new Exception($"Unable to find internal port by tag '{tag}' for recipe '{recipe.Name}'.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Port GetExternalServicePorts(ContainerRecipe recipe, string tag)
|
|
|
|
|
{
|
2023-11-06 13:33:47 +00:00
|
|
|
|
if (ExternalService != null)
|
|
|
|
|
{
|
|
|
|
|
var p = ExternalService.GetServicePortForRecipeAndTag(recipe, tag);
|
|
|
|
|
if (p != null) return p;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-06 15:52:55 +00:00
|
|
|
|
throw new Exception($"Unable to find external port by tag '{tag}' for recipe '{recipe.Name}'.");
|
2023-11-06 13:33:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Port[] GetServicePortsForContainer(ContainerRecipe recipe)
|
|
|
|
|
{
|
|
|
|
|
if (InternalService != null)
|
|
|
|
|
{
|
|
|
|
|
var p = InternalService.GetServicePortsForRecipe(recipe);
|
|
|
|
|
if (p.Any()) return p;
|
|
|
|
|
}
|
|
|
|
|
if (ExternalService != null)
|
|
|
|
|
{
|
|
|
|
|
var p = ExternalService.GetServicePortsForRecipe(recipe);
|
|
|
|
|
if (p.Any()) return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Array.Empty<Port>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RunningDeployment
|
|
|
|
|
{
|
|
|
|
|
public RunningDeployment(string name, string podLabel)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
PodLabel = podLabel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name { get; }
|
|
|
|
|
public string PodLabel { get; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RunningService
|
|
|
|
|
{
|
|
|
|
|
public RunningService(string name, List<ContainerRecipePortMapEntry> result)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
Result = result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name { get; }
|
|
|
|
|
public List<ContainerRecipePortMapEntry> Result { get; }
|
|
|
|
|
|
|
|
|
|
public Port? GetServicePortForRecipeAndTag(ContainerRecipe recipe, string tag)
|
|
|
|
|
{
|
|
|
|
|
return GetServicePortsForRecipe(recipe).SingleOrDefault(p => p.Tag == tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Port[] GetServicePortsForRecipe(ContainerRecipe recipe)
|
|
|
|
|
{
|
|
|
|
|
return Result
|
|
|
|
|
.Where(p => p.RecipeNumber == recipe.Number)
|
|
|
|
|
.SelectMany(p => p.Ports)
|
|
|
|
|
.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 13:28:00 +00:00
|
|
|
|
public class ContainerRecipePortMapEntry
|
|
|
|
|
{
|
2023-11-06 13:33:47 +00:00
|
|
|
|
public ContainerRecipePortMapEntry(int recipeNumber, Port[] ports)
|
2023-06-27 13:28:00 +00:00
|
|
|
|
{
|
2023-11-06 13:33:47 +00:00
|
|
|
|
RecipeNumber = recipeNumber;
|
2023-06-27 13:28:00 +00:00
|
|
|
|
Ports = ports;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
2023-06-27 13:28:00 +00:00
|
|
|
|
|
2023-11-06 13:33:47 +00:00
|
|
|
|
public int RecipeNumber { get; }
|
2023-06-27 13:28:00 +00:00
|
|
|
|
public Port[] Ports { get; }
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
2023-06-02 08:04:07 +00:00
|
|
|
|
|
|
|
|
|
public class PodInfo
|
|
|
|
|
{
|
2023-06-27 13:28:00 +00:00
|
|
|
|
public PodInfo(string name, string ip, string k8sNodeName)
|
2023-06-02 08:04:07 +00:00
|
|
|
|
{
|
2023-06-27 13:28:00 +00:00
|
|
|
|
Name = name;
|
|
|
|
|
Ip = ip;
|
2023-06-02 08:04:07 +00:00
|
|
|
|
K8SNodeName = k8sNodeName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name { get; }
|
|
|
|
|
public string Ip { get; }
|
|
|
|
|
public string K8SNodeName { get; }
|
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|