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,
|
|
|
|
|
|
discoveryEndpoint: container.GetInternalAddress(CodexContainerRecipe.DiscoveryPortTag),
|
|
|
|
|
|
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-01-16 10:15:02 +01:00
|
|
|
|
// todo: is this needed for the discovery address??
|
|
|
|
|
|
//var info = codexAccess.GetPodInfo();
|
|
|
|
|
|
//return new Address(
|
|
|
|
|
|
// logName: $"{GetName()}:DiscoveryPort",
|
|
|
|
|
|
// host: info.Ip,
|
|
|
|
|
|
// port: Container.Recipe.GetPortByTag(CodexContainerRecipe.DiscoveryPortTag)!.Number
|
|
|
|
|
|
//);
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|