2
0
mirror of synced 2025-01-13 18:14:14 +00:00

39 lines
1.1 KiB
C#
Raw Normal View History

2023-11-07 16:02:09 +01:00
namespace KubernetesWorkflow
2023-09-11 16:57:57 +02:00
{
internal enum RunnerLocation
{
2023-11-07 12:42:01 +01:00
Unknown,
2023-09-11 16:57:57 +02:00
ExternalToCluster,
InternalToCluster,
}
internal static class RunnerLocationUtils
{
private static RunnerLocation location = RunnerLocation.Unknown;
2023-09-11 16:57:57 +02:00
internal static RunnerLocation GetRunnerLocation()
2023-09-11 16:57:57 +02:00
{
DetermineRunnerLocation();
if (location == RunnerLocation.Unknown) throw new Exception("Runner location is unknown.");
return location;
}
2023-11-07 16:02:09 +01:00
private static void DetermineRunnerLocation()
{
if (location != RunnerLocation.Unknown) return;
var port = Environment.GetEnvironmentVariable("KUBERNETES_PORT");
var host = Environment.GetEnvironmentVariable("KUBERNETES_SERVICE_HOST");
if (string.IsNullOrEmpty(port) || string.IsNullOrEmpty(host))
{
location = RunnerLocation.ExternalToCluster;
}
else
{
location = RunnerLocation.InternalToCluster;
}
}
2023-09-11 16:57:57 +02:00
}
}