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;
|
|
|
|
|
}
|
2023-09-04 07:08:34 +00:00
|
|
|
|
|
2023-04-12 13:22:09 +00:00
|
|
|
|
public Configuration Configuration { get; }
|
2023-05-31 11:50:52 +00:00
|
|
|
|
public string HostAddress { 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();
|
2023-05-31 11:50:52 +00:00
|
|
|
|
UpdateHostAddress(config);
|
2023-04-12 11:53:55 +00:00
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 08:02:16 +00:00
|
|
|
|
public TimeSpan K8sOperationRetryDelay()
|
2023-04-12 13:11:36 +00:00
|
|
|
|
{
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-31 11:50:52 +00:00
|
|
|
|
private void UpdateHostAddress(KubernetesClientConfiguration config)
|
2023-04-13 08:11:33 +00:00
|
|
|
|
{
|
|
|
|
|
var host = config.Host.Replace("https://", "");
|
2023-05-31 11:50:52 +00:00
|
|
|
|
if (host.Contains(":"))
|
|
|
|
|
{
|
2023-05-31 13:02:07 +00:00
|
|
|
|
HostAddress = "http://" + host.Substring(0, host.IndexOf(':'));
|
2023-05-31 11:50:52 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HostAddress = config.Host;
|
|
|
|
|
}
|
2023-04-13 08:11:33 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|