mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-01-02 21:43:08 +00:00
47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using CodexClient;
|
|
using KubernetesWorkflow.Types;
|
|
using Utils;
|
|
|
|
namespace CodexPlugin
|
|
{
|
|
public static class CodexInstanceContainerExtension
|
|
{
|
|
public static ICodexInstance CreateFromPod(RunningPod pod)
|
|
{
|
|
var container = pod.Containers.Single();
|
|
|
|
return new CodexInstance(
|
|
name: container.Name,
|
|
imageName: container.Recipe.Image,
|
|
startUtc: container.Recipe.RecipeCreatedUtc,
|
|
discoveryEndpoint: SetClusterInternalIpAddress(pod, container.GetInternalAddress(CodexContainerRecipe.DiscoveryPortTag)),
|
|
apiEndpoint: container.GetAddress(CodexContainerRecipe.ApiPortTag),
|
|
listenEndpoint: container.GetInternalAddress(CodexContainerRecipe.ListenPortTag),
|
|
ethAccount: container.Recipe.Additionals.Get<EthAccount>(),
|
|
metricsEndpoint: GetMetricsEndpoint(container)
|
|
);
|
|
}
|
|
|
|
private static Address SetClusterInternalIpAddress(RunningPod pod, Address address)
|
|
{
|
|
return new Address(
|
|
logName: address.LogName,
|
|
host: pod.PodInfo.Ip,
|
|
port: address.Port
|
|
);
|
|
}
|
|
|
|
private static Address? GetMetricsEndpoint(RunningContainer container)
|
|
{
|
|
try
|
|
{
|
|
return container.GetInternalAddress(CodexContainerRecipe.MetricsPortTag);
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|