cs-codex-dist-tests/CodexDistTestCore/Config/K8sCluster.cs

40 lines
1.2 KiB
C#
Raw Normal View History

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;
public KubernetesClientConfiguration GetK8sClientConfig()
{
2023-03-26 07:41:46 +00:00
if (config != null) return config;
config = KubernetesClientConfiguration.BuildConfigFromConfigFile(KubeConfigFile);
return config;
}
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(':'));
}
public string GetNodeLabelForLocation(Location location)
{
2023-03-26 07:41:46 +00:00
if (location == Location.Unspecified) return string.Empty;
return K8sNodeLocationMap[location];
}
}
}