determine runner location with environment variables

This commit is contained in:
benbierens 2023-11-07 15:51:28 +01:00
parent 3f8699a59b
commit ec6c987ef9
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
2 changed files with 18 additions and 21 deletions

View File

@ -38,8 +38,6 @@ namespace KubernetesWorkflow
var internalService = CreateInternalService(containerRecipes);
var externalService = CreateExternalService(containerRecipes);
DetermineRunnerLocation(deployment);
return new StartResult(cluster, containerRecipes, deployment, internalService, externalService);
}
@ -834,12 +832,5 @@ namespace KubernetesWorkflow
return new PodInfo(name, ip, k8sNodeName);
}
private void DetermineRunnerLocation(RunningDeployment deployment)
{
if (RunnerLocationUtils.IsKnown()) return;
var podInfo = GetPodInfo(deployment);
RunnerLocationUtils.DetermineRunnerLocation(log, podInfo, cluster);
}
}
}

View File

@ -14,24 +14,30 @@ namespace KubernetesWorkflow
{
private static RunnerLocation location = RunnerLocation.Unknown;
internal static void DetermineRunnerLocation(ILog log, PodInfo info, K8sCluster cluster)
{
if (location != RunnerLocation.Unknown) return;
location = PingForLocation(info, cluster);
log.Log("Runner location set to: " + location);
}
internal static bool IsKnown()
{
return location != RunnerLocation.Unknown;
}
internal static RunnerLocation GetRunnerLocation()
{
DetermineRunnerLocation();
if (location == RunnerLocation.Unknown) throw new Exception("Runner location is unknown.");
return location;
}
private static void DetermineRunnerLocation()//ILog log, PodInfo info, K8sCluster cluster)
{
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;
}
}
private static RunnerLocation PingForLocation(PodInfo podInfo, K8sCluster cluster)
{
if (PingHost(podInfo.Ip))