2023-03-26 06:52:53 +00:00
|
|
|
|
using k8s;
|
|
|
|
|
|
|
|
|
|
namespace CodexDistTestCore.Config
|
|
|
|
|
{
|
|
|
|
|
public class K8sCluster
|
|
|
|
|
{
|
|
|
|
|
public const string K8sNamespace = "codex-test-namespace";
|
2023-03-26 07:41:46 +00:00
|
|
|
|
private const string KubeConfigFile = "C:\\kube\\config";
|
|
|
|
|
private readonly Dictionary<Location, string> K8sNodeLocationMap = new Dictionary<Location, string>
|
|
|
|
|
{
|
|
|
|
|
{ Location.BensLaptop, "worker01" },
|
|
|
|
|
{ Location.BensOldGamingMachine, "worker02" },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private KubernetesClientConfiguration? config;
|
2023-03-26 06:52:53 +00:00
|
|
|
|
|
|
|
|
|
public KubernetesClientConfiguration GetK8sClientConfig()
|
|
|
|
|
{
|
2023-03-26 07:41:46 +00:00
|
|
|
|
if (config != null) return config;
|
|
|
|
|
config = KubernetesClientConfiguration.BuildConfigFromConfigFile(KubeConfigFile);
|
|
|
|
|
return config;
|
2023-03-26 06:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetIp()
|
|
|
|
|
{
|
2023-03-26 07:41:46 +00:00
|
|
|
|
var c = GetK8sClientConfig();
|
|
|
|
|
|
|
|
|
|
var host = c.Host.Replace("https://", "");
|
|
|
|
|
|
|
|
|
|
return host.Substring(0, host.IndexOf(':'));
|
2023-03-26 06:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetNodeLabelForLocation(Location location)
|
|
|
|
|
{
|
2023-03-26 07:41:46 +00:00
|
|
|
|
if (location == Location.Unspecified) return string.Empty;
|
|
|
|
|
return K8sNodeLocationMap[location];
|
2023-03-26 06:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|