47 lines
1.6 KiB
C#
Raw Permalink Normal View History

using LogosStorageClient;
2025-01-15 15:43:50 +01:00
using KubernetesWorkflow.Types;
using Utils;
namespace StoragePlugin
{
public static class LogosStorageInstanceContainerExtension
2025-01-16 10:15:02 +01:00
{
public static ILogosStorageInstance 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
return new LogosStorageInstance(
2025-01-16 10:15:02 +01:00
name: container.Name,
imageName: container.Recipe.Image,
startUtc: container.Recipe.RecipeCreatedUtc,
discoveryEndpoint: SetClusterInternalIpAddress(pod, container.GetInternalAddress(LogosStorageContainerRecipe.DiscoveryPortTag)),
apiEndpoint: container.GetAddress(LogosStorageContainerRecipe.ApiPortTag),
listenEndpoint: container.GetInternalAddress(LogosStorageContainerRecipe.ListenPortTag),
2025-01-16 10:15:02 +01:00
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(LogosStorageContainerRecipe.MetricsPortTag);
2025-01-15 16:24:36 +01:00
}
catch
{
return null;
}
2025-01-15 15:43:50 +01:00
}
}
}