Cleans up runnerLocationUtils.

This commit is contained in:
benbierens 2023-11-07 16:02:09 +01:00
parent ec6c987ef9
commit 073f0d86a1
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
1 changed files with 2 additions and 42 deletions

View File

@ -1,7 +1,4 @@
using Logging;
using System.Net.NetworkInformation;
namespace KubernetesWorkflow
namespace KubernetesWorkflow
{
internal enum RunnerLocation
{
@ -21,7 +18,7 @@ namespace KubernetesWorkflow
return location;
}
private static void DetermineRunnerLocation()//ILog log, PodInfo info, K8sCluster cluster)
private static void DetermineRunnerLocation()
{
if (location != RunnerLocation.Unknown) return;
@ -37,42 +34,5 @@ namespace KubernetesWorkflow
location = RunnerLocation.InternalToCluster;
}
}
private static RunnerLocation PingForLocation(PodInfo podInfo, K8sCluster cluster)
{
if (PingHost(podInfo.Ip))
{
return RunnerLocation.InternalToCluster;
}
if (PingHost(Format(cluster.HostAddress)))
{
return RunnerLocation.ExternalToCluster;
}
throw new Exception("Unable to determine location relative to kubernetes cluster.");
}
private static string Format(string host)
{
return host
.Replace("http://", "")
.Replace("https://", "");
}
private static bool PingHost(string host)
{
try
{
using var pinger = new Ping();
PingReply reply = pinger.Send(host);
return reply.Status == IPStatus.Success;
}
catch (PingException)
{
}
return false;
}
}
}