cs-codex-dist-tests/Framework/KubernetesWorkflow/RunningPod.cs

131 lines
3.7 KiB
C#
Raw Normal View History

using k8s;
using k8s.Models;
using Newtonsoft.Json;
namespace KubernetesWorkflow
2023-04-12 11:53:55 +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; }
public Port GetInternalServicePorts(ContainerRecipe recipe, string tag)
{
if (InternalService != null)
{
var p = InternalService.GetServicePortForRecipeAndTag(recipe, tag);
if (p != null) return p;
}
throw new Exception($"Unable to find internal port by tag '{tag}' for recipe '{recipe.Name}'.");
}
public Port GetExternalServicePorts(ContainerRecipe recipe, string tag)
{
if (ExternalService != null)
{
var p = ExternalService.GetServicePortForRecipeAndTag(recipe, tag);
if (p != null) return p;
}
throw new Exception($"Unable to find external port by tag '{tag}' for recipe '{recipe.Name}'.");
}
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
{
public ContainerRecipePortMapEntry(int recipeNumber, Port[] ports)
2023-06-27 13:28:00 +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
public int RecipeNumber { get; }
2023-06-27 13:28:00 +00:00
public Port[] Ports { get; }
2023-04-12 11:53:55 +00:00
}
public class PodInfo
{
2023-06-27 13:28:00 +00:00
public PodInfo(string name, string ip, string k8sNodeName)
{
2023-06-27 13:28:00 +00:00
Name = name;
Ip = ip;
K8SNodeName = k8sNodeName;
}
public string Name { get; }
public string Ip { get; }
public string K8SNodeName { get; }
}
2023-04-12 11:53:55 +00:00
}