cs-codex-dist-tests/KubernetesWorkflow/K8sCluster.cs

58 lines
1.5 KiB
C#
Raw Normal View History

2023-04-12 11:53:55 +00:00
using k8s;
namespace KubernetesWorkflow
{
public class K8sCluster
{
private KubernetesClientConfiguration? config;
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;
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;
return Configuration.LocationMap.Single(l => l.Location == location).WorkerName;
2023-04-12 11:53:55 +00:00
}
public TimeSpan K8sOperationTimeout()
{
return Configuration.OperationTimeout;
}
public TimeSpan WaitForK8sServiceDelay()
{
return Configuration.RetryDelay;
}
2023-04-12 11:53:55 +00:00
}
}