determine runner location with environment variables
This commit is contained in:
parent
3f8699a59b
commit
ec6c987ef9
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue