cleanup config

This commit is contained in:
benbierens 2023-03-26 09:41:46 +02:00
parent 3359b10929
commit 107bb0f76b
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 28 additions and 22 deletions

View File

@ -1,37 +1,39 @@
using k8s;
using NUnit.Framework;
namespace CodexDistTestCore.Config
{
public class K8sCluster
{
public const string K8sNamespace = "codex-test-namespace";
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()
{
// todo: If the default KubeConfig file does not suffice, change it here:
return KubernetesClientConfiguration.BuildConfigFromConfigFile();
if (config != null) return config;
config = KubernetesClientConfiguration.BuildConfigFromConfigFile(KubeConfigFile);
return config;
}
public string GetIp()
{
return "127.0.0.1";
var c = GetK8sClientConfig();
var host = c.Host.Replace("https://", "");
return host.Substring(0, host.IndexOf(':'));
}
public string GetNodeLabelForLocation(Location location)
{
switch (location)
{
case Location.Unspecified:
return string.Empty;
case Location.BensLaptop:
return "worker01";
case Location.BensOldGamingMachine:
return "worker02";
}
Assert.Fail("Unknown location selected: " + location);
throw new InvalidOperationException();
if (location == Location.Unspecified) return string.Empty;
return K8sNodeLocationMap[location];
}
}
}

View File

@ -1,4 +1,5 @@
using NUnit.Framework;
using CodexDistTestCore.Config;
using NUnit.Framework;
namespace CodexDistTestCore
{
@ -41,7 +42,10 @@ namespace CodexDistTestCore
}
else
{
var dockerImage = new CodexDockerImage();
log = new TestLog();
log.Log($"Using docker image '{dockerImage.GetImageTag()}'");
fileManager = new FileManager(log);
k8sManager = new K8sManager(log, fileManager);
}

View File

@ -8,7 +8,7 @@ namespace CodexDistTestCore
public class K8sOperations
{
private readonly CodexDockerImage dockerImage = new CodexDockerImage();
private readonly K8sCluster k8SCluster = new K8sCluster();
private readonly K8sCluster k8sCluster = new K8sCluster();
private readonly Kubernetes client;
private readonly KnownK8sPods knownPods;
@ -16,7 +16,7 @@ namespace CodexDistTestCore
{
this.knownPods = knownPods;
client = new Kubernetes(k8SCluster.GetK8sClientConfig());
client = new Kubernetes(k8sCluster.GetK8sClientConfig());
}
public void Close()
@ -222,7 +222,7 @@ namespace CodexDistTestCore
return new Dictionary<string, string>
{
{ "codex-test-location", k8SCluster.GetNodeLabelForLocation(offline.Location) }
{ "codex-test-location", k8sCluster.GetNodeLabelForLocation(offline.Location) }
};
}

View File

@ -16,7 +16,7 @@ namespace CodexDistTestCore
private const string SuccessfullyConnectedMessage = "Successfully connected to peer";
private const string UploadFailedMessage = "Unable to store block";
private readonly K8sCluster k8SCluster = new K8sCluster();
private readonly K8sCluster k8sCluster = new K8sCluster();
private readonly TestLog log;
private readonly IFileManager fileManager;
@ -103,7 +103,7 @@ namespace CodexDistTestCore
private Http Http()
{
return new Http(ip: k8SCluster.GetIp(), port: Container.ServicePort, baseUrl: "/api/codex/v1");
return new Http(ip: k8sCluster.GetIp(), port: Container.ServicePort, baseUrl: "/api/codex/v1");
}
private void Log(string msg)