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

59 lines
1.6 KiB
C#
Raw Permalink Normal View History

2023-04-12 11:53:55 +00:00
using k8s;
namespace KubernetesWorkflow
{
public class K8sCluster
{
public K8sCluster(Configuration configuration)
{
Configuration = configuration;
}
public Configuration Configuration { get; }
public string HostAddress { get; private set; } = string.Empty;
2023-04-12 11:53:55 +00:00
public KubernetesClientConfiguration GetK8sClientConfig()
{
2023-04-13 08:11:33 +00:00
var config = GetConfig();
UpdateHostAddress(config);
2024-06-14 07:05:56 +00:00
config.SkipTlsVerify = true; // Required for operation on Wings cluster.
2023-04-12 11:53:55 +00:00
return config;
}
public TimeSpan K8sOperationTimeout()
{
return Configuration.OperationTimeout;
}
public TimeSpan K8sOperationRetryDelay()
{
return Configuration.RetryDelay;
}
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 UpdateHostAddress(KubernetesClientConfiguration config)
2023-04-13 08:11:33 +00:00
{
var host = config.Host.Replace("https://", "");
if (host.Contains(":"))
{
HostAddress = "http://" + host.Substring(0, host.IndexOf(':'));
}
else
{
HostAddress = config.Host;
}
2023-04-13 08:11:33 +00:00
}
2023-04-12 11:53:55 +00:00
}
}