diff --git a/CodexDistTestCore/Config/K8sCluster.cs b/CodexDistTestCore/Config/K8sCluster.cs index 8f85b70..0fd60d0 100644 --- a/CodexDistTestCore/Config/K8sCluster.cs +++ b/CodexDistTestCore/Config/K8sCluster.cs @@ -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 K8sNodeLocationMap = new Dictionary + { + { 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]; } } } diff --git a/CodexDistTestCore/DistTest.cs b/CodexDistTestCore/DistTest.cs index 55bd75c..db32997 100644 --- a/CodexDistTestCore/DistTest.cs +++ b/CodexDistTestCore/DistTest.cs @@ -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); } diff --git a/CodexDistTestCore/K8sOperations.cs b/CodexDistTestCore/K8sOperations.cs index 193c8dd..0febe44 100644 --- a/CodexDistTestCore/K8sOperations.cs +++ b/CodexDistTestCore/K8sOperations.cs @@ -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 { - { "codex-test-location", k8SCluster.GetNodeLabelForLocation(offline.Location) } + { "codex-test-location", k8sCluster.GetNodeLabelForLocation(offline.Location) } }; } diff --git a/CodexDistTestCore/OnlineCodexNode.cs b/CodexDistTestCore/OnlineCodexNode.cs index 76b38d7..6b523bc 100644 --- a/CodexDistTestCore/OnlineCodexNode.cs +++ b/CodexDistTestCore/OnlineCodexNode.cs @@ -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)