2025-01-16 13:51:29 +01:00
|
|
|
|
using CodexClient;
|
2025-01-15 15:43:50 +01:00
|
|
|
|
using KubernetesWorkflow.Types;
|
|
|
|
|
|
using Utils;
|
2025-01-15 15:00:25 +01:00
|
|
|
|
|
|
|
|
|
|
namespace CodexPlugin
|
|
|
|
|
|
{
|
2025-01-16 10:15:02 +01:00
|
|
|
|
public static class CodexInstanceContainerExtension
|
|
|
|
|
|
{
|
|
|
|
|
|
public static ICodexInstance CreateFromPod(RunningPod pod)
|
2025-01-15 15:43:50 +01:00
|
|
|
|
{
|
2025-01-16 10:15:02 +01:00
|
|
|
|
var container = pod.Containers.Single();
|
2025-01-15 15:43:50 +01:00
|
|
|
|
|
2025-01-16 10:15:02 +01:00
|
|
|
|
return new CodexInstance(
|
|
|
|
|
|
name: container.Name,
|
|
|
|
|
|
imageName: container.Recipe.Image,
|
|
|
|
|
|
startUtc: container.Recipe.RecipeCreatedUtc,
|
2025-02-21 14:17:13 +01:00
|
|
|
|
discoveryEndpoint: SetClusterInternalIpAddress(pod, container.GetInternalAddress(CodexContainerRecipe.DiscoveryPortTag)),
|
2025-01-16 10:15:02 +01:00
|
|
|
|
apiEndpoint: container.GetAddress(CodexContainerRecipe.ApiPortTag),
|
|
|
|
|
|
listenEndpoint: container.GetInternalAddress(CodexContainerRecipe.ListenPortTag),
|
|
|
|
|
|
ethAccount: container.Recipe.Additionals.Get<EthAccount>(),
|
|
|
|
|
|
metricsEndpoint: GetMetricsEndpoint(container)
|
|
|
|
|
|
);
|
2025-01-15 15:43:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-21 14:17:13 +01:00
|
|
|
|
private static Address SetClusterInternalIpAddress(RunningPod pod, Address address)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Address(
|
|
|
|
|
|
logName: address.LogName,
|
|
|
|
|
|
host: pod.PodInfo.Ip,
|
|
|
|
|
|
port: address.Port
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-01-16 10:15:02 +01:00
|
|
|
|
|
|
|
|
|
|
private static Address? GetMetricsEndpoint(RunningContainer container)
|
2025-01-15 15:43:50 +01:00
|
|
|
|
{
|
2025-01-15 16:24:36 +01:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return container.GetInternalAddress(CodexContainerRecipe.MetricsPortTag);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2025-01-15 15:43:50 +01:00
|
|
|
|
}
|
2025-01-15 15:00:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|