2023-04-12 11:53:55 +00:00
|
|
|
|
using k8s;
|
|
|
|
|
|
|
|
|
|
namespace KubernetesWorkflow
|
|
|
|
|
{
|
|
|
|
|
public class K8sCluster
|
|
|
|
|
{
|
2023-04-12 13:22:09 +00:00
|
|
|
|
public K8sCluster(Configuration configuration)
|
|
|
|
|
{
|
|
|
|
|
Configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Configuration Configuration { get; }
|
2023-04-13 08:11:33 +00:00
|
|
|
|
public string IP { get; private set; } = string.Empty;
|
2023-04-12 13:22:09 +00:00
|
|
|
|
|
2023-04-12 11:53:55 +00:00
|
|
|
|
public KubernetesClientConfiguration GetK8sClientConfig()
|
|
|
|
|
{
|
2023-04-13 08:11:33 +00:00
|
|
|
|
var config = GetConfig();
|
|
|
|
|
UpdateIp(config);
|
2023-04-12 11:53:55 +00:00
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-13 08:11:33 +00:00
|
|
|
|
|
|
|
|
|
private KubernetesClientConfiguration GetConfig()
|
|
|
|
|
{
|
|
|
|
|
if (Configuration.KubeConfigFile != null)
|
|
|
|
|
{
|
|
|
|
|
return KubernetesClientConfiguration.BuildConfigFromConfigFile(Configuration.KubeConfigFile);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return KubernetesClientConfiguration.BuildDefaultConfig();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateIp(KubernetesClientConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
var host = config.Host.Replace("https://", "");
|
|
|
|
|
IP = host.Substring(0, host.IndexOf(':'));
|
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|