From 5a861df96857ebc129b413a7fa16b8c5590c1c5a Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 10 Aug 2023 11:47:34 +0200 Subject: [PATCH] local tests passed --- KubernetesWorkflow/PodLabels.cs | 18 +++++++++++++++--- KubernetesWorkflow/StartupWorkflow.cs | 12 ++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/KubernetesWorkflow/PodLabels.cs b/KubernetesWorkflow/PodLabels.cs index e1097d5..e73a348 100644 --- a/KubernetesWorkflow/PodLabels.cs +++ b/KubernetesWorkflow/PodLabels.cs @@ -6,6 +6,11 @@ namespace KubernetesWorkflow { private readonly Dictionary labels = new Dictionary(); + private PodLabels(PodLabels source) + { + labels = source.labels.ToDictionary(p => p.Key, p => p.Value); + } + public PodLabels(string testsType, string codexId) { Add("tests-type", testsType); @@ -17,14 +22,21 @@ namespace KubernetesWorkflow Add("testname", NameUtils.GetTestMethodName()); } - public void AddAppName(string appName) + public PodLabels GetLabelsForAppName(string appName) { - Add("app", appName); + var pl = new PodLabels(this); + pl.Add("app", appName); + return pl; } private void Add(string key, string value) { - labels.Add(key, value.ToLowerInvariant()); + labels.Add(key, + value.ToLowerInvariant() + .Replace(":","-") + .Replace("/", "-") + .Replace("\\", "-") + ); } internal Dictionary GetLabels() diff --git a/KubernetesWorkflow/StartupWorkflow.cs b/KubernetesWorkflow/StartupWorkflow.cs index 185980b..c51b991 100644 --- a/KubernetesWorkflow/StartupWorkflow.cs +++ b/KubernetesWorkflow/StartupWorkflow.cs @@ -25,7 +25,7 @@ namespace KubernetesWorkflow public RunningContainers Start(int numberOfContainers, Location location, ContainerRecipeFactory recipeFactory, StartupConfig startupConfig) { - podLabels.AddAppName(recipeFactory.AppName); + var pl = podLabels.GetLabelsForAppName(recipeFactory.AppName); return K8s(controller => { @@ -34,7 +34,7 @@ namespace KubernetesWorkflow var runningPod = controller.BringOnline(recipes, location); return new RunningContainers(startupConfig, runningPod, CreateContainers(runningPod, recipes, startupConfig)); - }); + }, pl); } public void Stop(RunningContainers runningContainers) @@ -163,6 +163,14 @@ namespace KubernetesWorkflow controller.Dispose(); return result; } + + private T K8s(Func action, PodLabels labels) + { + var controller = new K8sController(log, cluster, knownK8SPods, numberSource, testNamespace, labels); + var result = action(controller); + controller.Dispose(); + return result; + } } public interface ILogHandler