2023-04-12 11:53:55 +00:00
|
|
|
|
using k8s;
|
|
|
|
|
|
|
|
|
|
namespace KubernetesWorkflow
|
|
|
|
|
{
|
|
|
|
|
public class K8sCluster
|
|
|
|
|
{
|
|
|
|
|
private KubernetesClientConfiguration? config;
|
|
|
|
|
|
2023-04-12 13:22:09 +00:00
|
|
|
|
public K8sCluster(Configuration configuration)
|
|
|
|
|
{
|
|
|
|
|
Configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Configuration Configuration { get; }
|
|
|
|
|
|
2023-04-12 11:53:55 +00:00
|
|
|
|
public KubernetesClientConfiguration GetK8sClientConfig()
|
|
|
|
|
{
|
|
|
|
|
if (config != null) return config;
|
2023-04-12 13:22:09 +00:00
|
|
|
|
|
|
|
|
|
if (Configuration.KubeConfigFile != null)
|
|
|
|
|
{
|
|
|
|
|
config = KubernetesClientConfiguration.BuildConfigFromConfigFile(Configuration.KubeConfigFile);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
config = KubernetesClientConfiguration.BuildDefaultConfig();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 11:53:55 +00:00
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetIp()
|
|
|
|
|
{
|
|
|
|
|
var c = GetK8sClientConfig();
|
|
|
|
|
|
|
|
|
|
var host = c.Host.Replace("https://", "");
|
|
|
|
|
|
|
|
|
|
return host.Substring(0, host.IndexOf(':'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetNodeLabelForLocation(Location location)
|
|
|
|
|
{
|
|
|
|
|
if (location == Location.Unspecified) return string.Empty;
|
2023-04-12 13:22:09 +00:00
|
|
|
|
return Configuration.LocationMap.Single(l => l.Location == location).WorkerName;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
2023-04-12 13:11:36 +00:00
|
|
|
|
|
|
|
|
|
public TimeSpan K8sOperationTimeout()
|
|
|
|
|
{
|
2023-04-12 13:22:09 +00:00
|
|
|
|
return Configuration.OperationTimeout;
|
2023-04-12 13:11:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TimeSpan WaitForK8sServiceDelay()
|
|
|
|
|
{
|
2023-04-12 13:22:09 +00:00
|
|
|
|
return Configuration.RetryDelay;
|
2023-04-12 13:11:36 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|