From 56063bbbf1dfc109b7c0df18e9335fa9b698c28c Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 13 Apr 2023 10:11:33 +0200 Subject: [PATCH] two-client tests pass --- DistTestCore/Codex/CodexAccess.cs | 2 +- KubernetesWorkflow/ContainerRecipeFactory.cs | 9 ++- KubernetesWorkflow/K8sCluster.cs | 43 ++++++------ KubernetesWorkflow/K8sController.cs | 2 +- Tests/BasicTests/SimpleTests.cs | 71 ++++++++++---------- 5 files changed, 67 insertions(+), 60 deletions(-) diff --git a/DistTestCore/Codex/CodexAccess.cs b/DistTestCore/Codex/CodexAccess.cs index ca6953f..d0c0f72 100644 --- a/DistTestCore/Codex/CodexAccess.cs +++ b/DistTestCore/Codex/CodexAccess.cs @@ -30,7 +30,7 @@ namespace DistTestCore.Codex private Http Http() { - var ip = Container.Pod.Cluster.GetIp(); + var ip = Container.Pod.Cluster.IP; var port = Container.ServicePorts[0].Number; return new Http(ip, port, baseUrl: "/api/codex/v1"); } diff --git a/KubernetesWorkflow/ContainerRecipeFactory.cs b/KubernetesWorkflow/ContainerRecipeFactory.cs index fc06f33..60ea91e 100644 --- a/KubernetesWorkflow/ContainerRecipeFactory.cs +++ b/KubernetesWorkflow/ContainerRecipeFactory.cs @@ -14,7 +14,14 @@ Initialize(config); - return new ContainerRecipe(containerNumber, Image, exposedPorts.ToArray(), internalPorts.ToArray(), envVars.ToArray()); + var recipe = new ContainerRecipe(containerNumber, Image, exposedPorts.ToArray(), internalPorts.ToArray(), envVars.ToArray()); + + exposedPorts.Clear(); + internalPorts.Clear(); + envVars.Clear(); + this.factory = null!; + + return recipe; } protected abstract string Image { get; } diff --git a/KubernetesWorkflow/K8sCluster.cs b/KubernetesWorkflow/K8sCluster.cs index c823a09..4d5a772 100644 --- a/KubernetesWorkflow/K8sCluster.cs +++ b/KubernetesWorkflow/K8sCluster.cs @@ -4,40 +4,21 @@ namespace KubernetesWorkflow { public class K8sCluster { - private KubernetesClientConfiguration? config; - public K8sCluster(Configuration configuration) { Configuration = configuration; } public Configuration Configuration { get; } + public string IP { get; private set; } = string.Empty; public KubernetesClientConfiguration GetK8sClientConfig() { - if (config != null) return config; - - if (Configuration.KubeConfigFile != null) - { - config = KubernetesClientConfiguration.BuildConfigFromConfigFile(Configuration.KubeConfigFile); - } - else - { - config = KubernetesClientConfiguration.BuildDefaultConfig(); - } - + var config = GetConfig(); + UpdateIp(config); return config; } - public string GetIp() - { - var c = GetK8sClientConfig(); - - var host = c.Host.Replace("https://", ""); - - return host.Substring(0, host.IndexOf(':')); - } - public string GetNodeLabelForLocation(Location location) { if (location == Location.Unspecified) return string.Empty; @@ -53,5 +34,23 @@ namespace KubernetesWorkflow { return Configuration.RetryDelay; } + + private KubernetesClientConfiguration GetConfig() + { + if (Configuration.KubeConfigFile != null) + { + return KubernetesClientConfiguration.BuildConfigFromConfigFile(Configuration.KubeConfigFile); + } + else + { + return KubernetesClientConfiguration.BuildDefaultConfig(); + } + } + + private void UpdateIp(KubernetesClientConfiguration config) + { + var host = config.Host.Replace("https://", ""); + IP = host.Substring(0, host.IndexOf(':')); + } } } diff --git a/KubernetesWorkflow/K8sController.cs b/KubernetesWorkflow/K8sController.cs index 3df4549..295397b 100644 --- a/KubernetesWorkflow/K8sController.cs +++ b/KubernetesWorkflow/K8sController.cs @@ -227,7 +227,7 @@ namespace KubernetesWorkflow { return new V1ObjectMeta { - Name = "deploy-" + workflowNumberSource.WorkflowNumber, + Name = "service-" + workflowNumberSource.WorkflowNumber, NamespaceProperty = K8sNamespace }; } diff --git a/Tests/BasicTests/SimpleTests.cs b/Tests/BasicTests/SimpleTests.cs index f4214e6..4c33425 100644 --- a/Tests/BasicTests/SimpleTests.cs +++ b/Tests/BasicTests/SimpleTests.cs @@ -1,4 +1,5 @@ using DistTestCore; +using KubernetesWorkflow; using NUnit.Framework; namespace Tests.BasicTests @@ -20,41 +21,41 @@ namespace Tests.BasicTests testFile.AssertIsEqual(downloadedFile); } - //[Test] - //public void TwoClientsOnePodTest() - //{ - // var group = SetupCodexNodes(2).BringOnline(); + [Test] + public void TwoClientsOnePodTest() + { + var group = SetupCodexNodes(2).BringOnline(); - // var primary = group[0]; - // var secondary = group[1]; + var primary = group[0]; + var secondary = group[1]; - // PerformTwoClientTest(primary, secondary); - //} + PerformTwoClientTest(primary, secondary); + } - //[Test] - //public void TwoClientsTwoPodsTest() - //{ - // var primary = SetupCodexNodes(1).BringOnline()[0]; + [Test] + public void TwoClientsTwoPodsTest() + { + var primary = SetupCodexNodes(1).BringOnline()[0]; - // var secondary = SetupCodexNodes(1).BringOnline()[0]; + var secondary = SetupCodexNodes(1).BringOnline()[0]; - // PerformTwoClientTest(primary, secondary); - //} + PerformTwoClientTest(primary, secondary); + } - //[Test] - //[Ignore("Requires Location map to be configured for k8s cluster.")] - //public void TwoClientsTwoLocationsTest() - //{ - // var primary = SetupCodexNodes(1) - // .At(Location.BensLaptop) - // .BringOnline()[0]; + [Test] + [Ignore("Requires Location map to be configured for k8s cluster.")] + public void TwoClientsTwoLocationsTest() + { + var primary = SetupCodexNodes(1) + .At(Location.BensLaptop) + .BringOnline()[0]; - // var secondary = SetupCodexNodes(1) - // .At(Location.BensOldGamingMachine) - // .BringOnline()[0]; + var secondary = SetupCodexNodes(1) + .At(Location.BensOldGamingMachine) + .BringOnline()[0]; - // PerformTwoClientTest(primary, secondary); - //} + PerformTwoClientTest(primary, secondary); + } //[Test] //public void TwoMetricsExample() @@ -118,17 +119,17 @@ namespace Tests.BasicTests // //primary.Marketplace.AssertThatBalance(Is.GreaterThan(primaryBalance), "Storer was not paid for storage."); //} - //private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary) - //{ - // primary.ConnectToPeer(secondary); + private void PerformTwoClientTest(IOnlineCodexNode primary, IOnlineCodexNode secondary) + { + primary.ConnectToPeer(secondary); - // var testFile = GenerateTestFile(1.MB()); + var testFile = GenerateTestFile(1.MB()); - // var contentId = primary.UploadFile(testFile); + var contentId = primary.UploadFile(testFile); - // var downloadedFile = secondary.DownloadContent(contentId); + var downloadedFile = secondary.DownloadContent(contentId); - // testFile.AssertIsEqual(downloadedFile); - //} + testFile.AssertIsEqual(downloadedFile); + } } }