local tests passed

This commit is contained in:
benbierens 2023-08-10 11:47:34 +02:00
parent 01ec6f7d8b
commit 5a861df968
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
2 changed files with 25 additions and 5 deletions

View File

@ -6,6 +6,11 @@ namespace KubernetesWorkflow
{
private readonly Dictionary<string, string> labels = new Dictionary<string, string>();
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<string, string> GetLabels()

View File

@ -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<T>(Func<K8sController, T> action, PodLabels labels)
{
var controller = new K8sController(log, cluster, knownK8SPods, numberSource, testNamespace, labels);
var result = action(controller);
controller.Dispose();
return result;
}
}
public interface ILogHandler