logos-storage-nim-cs-dist-t.../ProjectPlugins/CodexPlugin/CodexInstanceContainerExtension.cs

47 lines
1.5 KiB
C#
Raw Normal View History

2025-01-16 13:51:29 +01:00
using CodexClient;
2025-01-15 15:43:50 +01:00
using KubernetesWorkflow.Types;
using Utils;
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: 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
}
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
}
}
}