2023-11-07 15:02:09 +00:00
|
|
|
|
namespace KubernetesWorkflow
|
2023-09-11 14:57:57 +00:00
|
|
|
|
{
|
|
|
|
|
internal enum RunnerLocation
|
|
|
|
|
{
|
2023-11-07 11:42:01 +00:00
|
|
|
|
Unknown,
|
2023-09-11 14:57:57 +00:00
|
|
|
|
ExternalToCluster,
|
|
|
|
|
InternalToCluster,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static class RunnerLocationUtils
|
|
|
|
|
{
|
2023-11-07 12:06:49 +00:00
|
|
|
|
private static RunnerLocation location = RunnerLocation.Unknown;
|
2023-09-11 14:57:57 +00:00
|
|
|
|
|
2023-11-07 14:51:28 +00:00
|
|
|
|
internal static RunnerLocation GetRunnerLocation()
|
2023-09-11 14:57:57 +00:00
|
|
|
|
{
|
2023-11-07 14:51:28 +00:00
|
|
|
|
DetermineRunnerLocation();
|
|
|
|
|
if (location == RunnerLocation.Unknown) throw new Exception("Runner location is unknown.");
|
|
|
|
|
return location;
|
2023-11-07 12:06:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-07 15:02:09 +00:00
|
|
|
|
private static void DetermineRunnerLocation()
|
2023-11-07 12:06:49 +00:00
|
|
|
|
{
|
2023-11-07 14:51:28 +00:00
|
|
|
|
if (location != RunnerLocation.Unknown) return;
|
2023-11-07 12:06:49 +00:00
|
|
|
|
|
2023-11-07 14:51:28 +00:00
|
|
|
|
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-10-19 09:08:30 +00:00
|
|
|
|
}
|
2023-09-11 14:57:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|