sets up additional pod labels
This commit is contained in:
parent
17673e8fa5
commit
01ec6f7d8b
|
@ -72,7 +72,7 @@ namespace CodexNetDeployer
|
||||||
k8sNamespacePrefix: config.KubeNamespace
|
k8sNamespacePrefix: config.KubeNamespace
|
||||||
);
|
);
|
||||||
|
|
||||||
return new TestLifecycle(log, lifecycleConfig, timeset);
|
return new TestLifecycle(log, lifecycleConfig, timeset, config.TestsTypePodLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RunningContainer? StartMetricsService(TestLifecycle lifecycle, CodexSetup setup, List<RunningContainer> codexContainers)
|
private RunningContainer? StartMetricsService(TestLifecycle lifecycle, CodexSetup setup, List<RunningContainer> codexContainers)
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace ContinuousTests
|
||||||
k8sNamespacePrefix: customNamespace
|
k8sNamespacePrefix: customNamespace
|
||||||
);
|
);
|
||||||
|
|
||||||
return new TestLifecycle(log, lifecycleConfig, timeSet);
|
return new TestLifecycle(log, lifecycleConfig, timeSet, "continuous-tests");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? GetKubeConfig(string kubeConfigFile)
|
private static string? GetKubeConfig(string kubeConfigFile)
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace DistTestCore
|
||||||
[Parallelizable(ParallelScope.All)]
|
[Parallelizable(ParallelScope.All)]
|
||||||
public abstract class DistTest
|
public abstract class DistTest
|
||||||
{
|
{
|
||||||
|
private const string TestsType = "dist-tests";
|
||||||
private readonly Configuration configuration = new Configuration();
|
private readonly Configuration configuration = new Configuration();
|
||||||
private readonly Assembly[] testAssemblies;
|
private readonly Assembly[] testAssemblies;
|
||||||
private readonly FixtureLog fixtureLog;
|
private readonly FixtureLog fixtureLog;
|
||||||
|
@ -52,7 +53,7 @@ namespace DistTestCore
|
||||||
{
|
{
|
||||||
Stopwatch.Measure(fixtureLog, "Global setup", () =>
|
Stopwatch.Measure(fixtureLog, "Global setup", () =>
|
||||||
{
|
{
|
||||||
var wc = new WorkflowCreator(fixtureLog, configuration.GetK8sConfiguration(GetTimeSet()), "dist-tests");
|
var wc = new WorkflowCreator(fixtureLog, configuration.GetK8sConfiguration(GetTimeSet()), new PodLabels(TestsType, "null"));
|
||||||
wc.CreateWorkflow().DeleteAllResources();
|
wc.CreateWorkflow().DeleteAllResources();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -195,7 +196,7 @@ namespace DistTestCore
|
||||||
{
|
{
|
||||||
lock (lifecycleLock)
|
lock (lifecycleLock)
|
||||||
{
|
{
|
||||||
lifecycles.Add(testName, new TestLifecycle(fixtureLog.CreateTestLog(), configuration, GetTimeSet()));
|
lifecycles.Add(testName, new TestLifecycle(fixtureLog.CreateTestLog(), configuration, GetTimeSet(), TestsType));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -206,7 +207,7 @@ namespace DistTestCore
|
||||||
var testResult = GetTestResult();
|
var testResult = GetTestResult();
|
||||||
var testDuration = lifecycle.GetTestDuration();
|
var testDuration = lifecycle.GetTestDuration();
|
||||||
fixtureLog.Log($"{GetCurrentTestName()} = {testResult} ({testDuration})");
|
fixtureLog.Log($"{GetCurrentTestName()} = {testResult} ({testDuration})");
|
||||||
statusLog.ConcludeTest(testResult, testDuration, GetCodexId(lifecycle));
|
statusLog.ConcludeTest(testResult, testDuration, lifecycle.GetCodexId());
|
||||||
Stopwatch.Measure(fixtureLog, $"Teardown for {GetCurrentTestName()}", () =>
|
Stopwatch.Measure(fixtureLog, $"Teardown for {GetCurrentTestName()}", () =>
|
||||||
{
|
{
|
||||||
lifecycle.Log.EndTest();
|
lifecycle.Log.EndTest();
|
||||||
|
@ -216,14 +217,6 @@ namespace DistTestCore
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetCodexId(TestLifecycle lifecycle)
|
|
||||||
{
|
|
||||||
var v = lifecycle.CodexVersion;
|
|
||||||
if (v == null) return new CodexContainerRecipe().Image;
|
|
||||||
if (v.version != "untagged build") return v.version;
|
|
||||||
return v.revision;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ITimeSet GetTimeSet()
|
private ITimeSet GetTimeSet()
|
||||||
{
|
{
|
||||||
if (ShouldUseLongTimeouts()) return new LongTimeSet();
|
if (ShouldUseLongTimeouts()) return new LongTimeSet();
|
||||||
|
|
|
@ -10,13 +10,14 @@ namespace DistTestCore
|
||||||
{
|
{
|
||||||
private readonly DateTime testStart;
|
private readonly DateTime testStart;
|
||||||
|
|
||||||
public TestLifecycle(BaseLog log, Configuration configuration, ITimeSet timeSet)
|
public TestLifecycle(BaseLog log, Configuration configuration, ITimeSet timeSet, string testsType)
|
||||||
{
|
{
|
||||||
Log = log;
|
Log = log;
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
TimeSet = timeSet;
|
TimeSet = timeSet;
|
||||||
|
|
||||||
WorkflowCreator = new WorkflowCreator(log, configuration.GetK8sConfiguration(timeSet), "dist-tests");
|
var podLabels = new PodLabels(testsType, GetCodexId());
|
||||||
|
WorkflowCreator = new WorkflowCreator(log, configuration.GetK8sConfiguration(timeSet), podLabels);
|
||||||
|
|
||||||
FileManager = new FileManager(Log, configuration);
|
FileManager = new FileManager(Log, configuration);
|
||||||
CodexStarter = new CodexStarter(this);
|
CodexStarter = new CodexStarter(this);
|
||||||
|
@ -66,5 +67,13 @@ namespace DistTestCore
|
||||||
{
|
{
|
||||||
if (CodexVersion == null) CodexVersion = version;
|
if (CodexVersion == null) CodexVersion = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetCodexId()
|
||||||
|
{
|
||||||
|
var v = CodexVersion;
|
||||||
|
if (v == null) return new CodexContainerRecipe().Image;
|
||||||
|
if (v.version != "untagged build") return v.version;
|
||||||
|
return v.revision;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,28 @@
|
||||||
namespace KubernetesWorkflow
|
using Logging;
|
||||||
|
|
||||||
|
namespace KubernetesWorkflow
|
||||||
{
|
{
|
||||||
public class PodLabels
|
public class PodLabels
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, string> labels = new Dictionary<string, string>();
|
private readonly Dictionary<string, string> labels = new Dictionary<string, string>();
|
||||||
|
|
||||||
public void Add(string key, string value)
|
public PodLabels(string testsType, string codexId)
|
||||||
|
{
|
||||||
|
Add("tests-type", testsType);
|
||||||
|
Add("runid", NameUtils.GetRunId());
|
||||||
|
Add("testid", NameUtils.GetTestId());
|
||||||
|
Add("category", NameUtils.GetCategoryName());
|
||||||
|
Add("codexid", codexId);
|
||||||
|
Add("fixturename", NameUtils.GetRawFixtureName());
|
||||||
|
Add("testname", NameUtils.GetTestMethodName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddAppName(string appName)
|
||||||
|
{
|
||||||
|
Add("app", appName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Add(string key, string value)
|
||||||
{
|
{
|
||||||
labels.Add(key, value.ToLowerInvariant());
|
labels.Add(key, value.ToLowerInvariant());
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,26 +10,22 @@ namespace KubernetesWorkflow
|
||||||
private readonly K8sCluster cluster;
|
private readonly K8sCluster cluster;
|
||||||
private readonly KnownK8sPods knownK8SPods;
|
private readonly KnownK8sPods knownK8SPods;
|
||||||
private readonly string testNamespace;
|
private readonly string testNamespace;
|
||||||
private readonly string testsType;
|
private readonly PodLabels podLabels;
|
||||||
private readonly RecipeComponentFactory componentFactory = new RecipeComponentFactory();
|
private readonly RecipeComponentFactory componentFactory = new RecipeComponentFactory();
|
||||||
|
|
||||||
internal StartupWorkflow(BaseLog log, WorkflowNumberSource numberSource, K8sCluster cluster, KnownK8sPods knownK8SPods, string testNamespace, string testsType)
|
internal StartupWorkflow(BaseLog log, WorkflowNumberSource numberSource, K8sCluster cluster, KnownK8sPods knownK8SPods, string testNamespace, PodLabels podLabels)
|
||||||
{
|
{
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.numberSource = numberSource;
|
this.numberSource = numberSource;
|
||||||
this.cluster = cluster;
|
this.cluster = cluster;
|
||||||
this.knownK8SPods = knownK8SPods;
|
this.knownK8SPods = knownK8SPods;
|
||||||
this.testNamespace = testNamespace;
|
this.testNamespace = testNamespace;
|
||||||
this.testsType = testsType;
|
this.podLabels = podLabels;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RunningContainers Start(int numberOfContainers, Location location, ContainerRecipeFactory recipeFactory, StartupConfig startupConfig)
|
public RunningContainers Start(int numberOfContainers, Location location, ContainerRecipeFactory recipeFactory, StartupConfig startupConfig)
|
||||||
{
|
{
|
||||||
var podLabels = new PodLabels();
|
podLabels.AddAppName(recipeFactory.AppName);
|
||||||
podLabels.Add("runid", NameUtils.GetRunId());
|
|
||||||
podLabels.Add("tests-type", testsType);
|
|
||||||
podLabels.Add("app", recipeFactory.AppName);
|
|
||||||
|
|
||||||
return K8s(controller =>
|
return K8s(controller =>
|
||||||
{
|
{
|
||||||
|
@ -38,7 +34,7 @@ namespace KubernetesWorkflow
|
||||||
var runningPod = controller.BringOnline(recipes, location);
|
var runningPod = controller.BringOnline(recipes, location);
|
||||||
|
|
||||||
return new RunningContainers(startupConfig, runningPod, CreateContainers(runningPod, recipes, startupConfig));
|
return new RunningContainers(startupConfig, runningPod, CreateContainers(runningPod, recipes, startupConfig));
|
||||||
}, podLabels);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop(RunningContainers runningContainers)
|
public void Stop(RunningContainers runningContainers)
|
||||||
|
@ -155,17 +151,12 @@ namespace KubernetesWorkflow
|
||||||
|
|
||||||
private void K8s(Action<K8sController> action)
|
private void K8s(Action<K8sController> action)
|
||||||
{
|
{
|
||||||
var controller = new K8sController(log, cluster, knownK8SPods, numberSource, testNamespace, new PodLabels());
|
var controller = new K8sController(log, cluster, knownK8SPods, numberSource, testNamespace, podLabels);
|
||||||
action(controller);
|
action(controller);
|
||||||
controller.Dispose();
|
controller.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private T K8s<T>(Func<K8sController, T> action)
|
private T K8s<T>(Func<K8sController, T> action)
|
||||||
{
|
|
||||||
return K8s(action, new PodLabels());
|
|
||||||
}
|
|
||||||
|
|
||||||
private T K8s<T>(Func<K8sController, T> action, PodLabels podLabels)
|
|
||||||
{
|
{
|
||||||
var controller = new K8sController(log, cluster, knownK8SPods, numberSource, testNamespace, podLabels);
|
var controller = new K8sController(log, cluster, knownK8SPods, numberSource, testNamespace, podLabels);
|
||||||
var result = action(controller);
|
var result = action(controller);
|
||||||
|
|
|
@ -10,20 +10,15 @@ namespace KubernetesWorkflow
|
||||||
private readonly KnownK8sPods knownPods = new KnownK8sPods();
|
private readonly KnownK8sPods knownPods = new KnownK8sPods();
|
||||||
private readonly K8sCluster cluster;
|
private readonly K8sCluster cluster;
|
||||||
private readonly BaseLog log;
|
private readonly BaseLog log;
|
||||||
private readonly string testsType;
|
private readonly PodLabels podLabels;
|
||||||
private readonly string testNamespace;
|
private readonly string testNamespace;
|
||||||
|
|
||||||
public WorkflowCreator(BaseLog log, Configuration configuration, string testsType)
|
public WorkflowCreator(BaseLog log, Configuration configuration, PodLabels podLabels)
|
||||||
: this(log, configuration, testsType, Guid.NewGuid().ToString().ToLowerInvariant())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorkflowCreator(BaseLog log, Configuration configuration, string testsType, string testNamespacePostfix)
|
|
||||||
{
|
{
|
||||||
cluster = new K8sCluster(configuration);
|
cluster = new K8sCluster(configuration);
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.testsType = testsType;
|
this.podLabels = podLabels;
|
||||||
testNamespace = testNamespacePostfix;
|
testNamespace = Guid.NewGuid().ToString().ToLowerInvariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StartupWorkflow CreateWorkflow()
|
public StartupWorkflow CreateWorkflow()
|
||||||
|
@ -31,7 +26,7 @@ namespace KubernetesWorkflow
|
||||||
var workflowNumberSource = new WorkflowNumberSource(numberSource.GetNextNumber(),
|
var workflowNumberSource = new WorkflowNumberSource(numberSource.GetNextNumber(),
|
||||||
containerNumberSource);
|
containerNumberSource);
|
||||||
|
|
||||||
return new StartupWorkflow(log, workflowNumberSource, cluster, knownPods, testNamespace, testsType);
|
return new StartupWorkflow(log, workflowNumberSource, cluster, knownPods, testNamespace, podLabels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue