diff --git a/CodexPlugin/CodexPlugin.cs b/CodexPlugin/CodexPlugin.cs index b82821d..e862f78 100644 --- a/CodexPlugin/CodexPlugin.cs +++ b/CodexPlugin/CodexPlugin.cs @@ -7,6 +7,7 @@ namespace CodexPlugin { private readonly CodexStarter codexStarter; private readonly IPluginTools tools; + private readonly CodexLogLevel defaultLogLevel = CodexLogLevel.Trace; public CodexPlugin(IPluginTools tools) { @@ -27,7 +28,8 @@ namespace CodexPlugin public RunningContainers[] StartCodexNodes(int numberOfNodes, Action setup) { - var codexSetup = new CodexSetup(numberOfNodes, CodexLogLevel.Trace); + var codexSetup = new CodexSetup(numberOfNodes); + codexSetup.LogLevel = defaultLogLevel; setup(codexSetup); return codexStarter.BringOnline(codexSetup); } diff --git a/CodexPlugin/CodexSetup.cs b/CodexPlugin/CodexSetup.cs index ff777ff..d6356e1 100644 --- a/CodexPlugin/CodexSetup.cs +++ b/CodexPlugin/CodexSetup.cs @@ -5,6 +5,7 @@ namespace CodexPlugin { public interface ICodexSetup { + ICodexSetup WithLogLevel(CodexLogLevel logLevel); ICodexSetup WithName(string name); ICodexSetup At(Location location); ICodexSetup WithBootstrapNode(IOnlineCodexNode node); @@ -22,12 +23,17 @@ namespace CodexPlugin { public int NumberOfNodes { get; } - public CodexSetup(int numberOfNodes, CodexLogLevel logLevel) - : base(logLevel) + public CodexSetup(int numberOfNodes) { NumberOfNodes = numberOfNodes; } + public ICodexSetup WithLogLevel(CodexLogLevel logLevel) + { + LogLevel = logLevel; + return this; + } + public ICodexSetup WithName(string name) { NameOverride = name; diff --git a/CodexPlugin/CodexStartupConfig.cs b/CodexPlugin/CodexStartupConfig.cs index e2ccb1f..56b41d9 100644 --- a/CodexPlugin/CodexStartupConfig.cs +++ b/CodexPlugin/CodexStartupConfig.cs @@ -5,14 +5,9 @@ namespace CodexPlugin { public class CodexStartupConfig { - public CodexStartupConfig(CodexLogLevel logLevel) - { - LogLevel = logLevel; - } - public string? NameOverride { get; set; } public Location Location { get; set; } - public CodexLogLevel LogLevel { get; } + public CodexLogLevel LogLevel { get; set; } public ByteSize? StorageQuota { get; set; } public bool MetricsEnabled { get; set; } //public MarketplaceInitialConfig? MarketplaceConfig { get; set; } diff --git a/Core/PluginTools.cs b/Core/PluginTools.cs index 522e481..704588a 100644 --- a/Core/PluginTools.cs +++ b/Core/PluginTools.cs @@ -62,8 +62,7 @@ namespace Core public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null) { - if (namespaceOverride != null) throw new Exception("Namespace override is not supported in the DistTest environment. (It would mess up automatic resource cleanup.)"); - return workflowCreator.CreateWorkflow(); + return workflowCreator.CreateWorkflow(namespaceOverride); } public IFileManager GetFileManager() diff --git a/DistTestCore/Configuration.cs b/DistTestCore/Configuration.cs index b76a380..b22415d 100644 --- a/DistTestCore/Configuration.cs +++ b/DistTestCore/Configuration.cs @@ -8,8 +8,6 @@ namespace DistTestCore private readonly string logPath; private readonly bool logDebug; private readonly string dataFilesPath; - //private readonly CodexLogLevel codexLogLevel; - private readonly string k8sNamespacePrefix; public Configuration() { @@ -17,28 +15,28 @@ namespace DistTestCore logPath = GetEnvVarOrDefault("LOGPATH", "CodexTestLogs"); logDebug = GetEnvVarOrDefault("LOGDEBUG", "false").ToLowerInvariant() == "true"; dataFilesPath = GetEnvVarOrDefault("DATAFILEPATH", "TestDataFiles"); - //codexLogLevel = ParseEnum.Parse(GetEnvVarOrDefault("LOGLEVEL", nameof(CodexLogLevel.Trace))); - k8sNamespacePrefix = "ct-"; } - public Configuration(string? kubeConfigFile, string logPath, bool logDebug, string dataFilesPath, /*CodexLogLevel codexLogLevel,*/ string k8sNamespacePrefix) + public Configuration(string? kubeConfigFile, string logPath, bool logDebug, string dataFilesPath) { this.kubeConfigFile = kubeConfigFile; this.logPath = logPath; this.logDebug = logDebug; this.dataFilesPath = dataFilesPath; - //this.codexLogLevel = codexLogLevel; - this.k8sNamespacePrefix = k8sNamespacePrefix; } public KubernetesWorkflow.Configuration GetK8sConfiguration(ITimeSet timeSet, string k8sNamespace) { - return new KubernetesWorkflow.Configuration( + var config = new KubernetesWorkflow.Configuration( kubeConfigFile: kubeConfigFile, operationTimeout: timeSet.K8sOperationTimeout(), retryDelay: timeSet.WaitForK8sServiceDelay(), kubernetesNamespace: k8sNamespace ); + + config.AllowNamespaceOverride = false; + + return config; } public Logging.LogConfig GetLogConfig() @@ -51,11 +49,6 @@ namespace DistTestCore return dataFilesPath; } - //public CodexLogLevel GetCodexLogLevel() - //{ - // return codexLogLevel; - //} - private static string GetEnvVarOrDefault(string varName, string defaultValue) { var v = Environment.GetEnvironmentVariable(varName); @@ -70,6 +63,4 @@ namespace DistTestCore return v; } } - - } diff --git a/DistTestCore/DistTest.cs b/DistTestCore/DistTest.cs index ac7063d..5ae23a4 100644 --- a/DistTestCore/DistTest.cs +++ b/DistTestCore/DistTest.cs @@ -113,59 +113,6 @@ namespace DistTestCore Get().GetFileManager().ScopedFiles(action); } - //public IOnlineCodexNode SetupCodexBootstrapNode() - //{ - // return SetupCodexBootstrapNode(s => { }); - //} - - //public virtual IOnlineCodexNode SetupCodexBootstrapNode(Action setup) - //{ - // return SetupCodexNode(s => - // { - // setup(s); - // s.WithName("Bootstrap"); - // }); - //} - - //public IOnlineCodexNode SetupCodexNode() - //{ - // return SetupCodexNode(s => { }); - //} - - //public IOnlineCodexNode SetupCodexNode(Action setup) - //{ - // return SetupCodexNodes(1, setup)[0]; - //} - - //public ICodexNodeGroup SetupCodexNodes(int numberOfNodes) - //{ - // return SetupCodexNodes(numberOfNodes, s => { }); - //} - - //public virtual ICodexNodeGroup SetupCodexNodes(int numberOfNodes, Action setup) - //{ - // var codexSetup = CreateCodexSetup(numberOfNodes); - - // setup(codexSetup); - - // return BringOnline(codexSetup); - //} - - //public ICodexNodeGroup BringOnline(ICodexSetup codexSetup) - //{ - // return Get().CodexStarter.BringOnline((CodexSetup)codexSetup); - //} - - //public IEnumerable GetAllOnlineCodexNodes() - //{ - // return Get().CodexStarter.RunningGroups.SelectMany(g => g.Nodes); - //} - - //public override T GetPlugin() - //{ - // return Get().GetPlugin(); - //} - public ILog GetTestLog() { return Get().Log; @@ -188,11 +135,6 @@ namespace DistTestCore Stopwatch.Measure(Get().Log, name, action); } - //protected CodexSetup CreateCodexSetup(int numberOfNodes) - //{ - // return new CodexSetup(numberOfNodes, configuration.GetCodexLogLevel()); - //} - protected TestLifecycle Get() { lock (lifecycleLock) @@ -293,37 +235,6 @@ namespace DistTestCore } } - //private void DownloadAllLogs(TestLifecycle lifecycle) - //{ - // OnEachCodexNode(lifecycle, node => - // { - // lifecycle.DownloadLog(node.CodexAccess.Container); - // }); - //} - - //private void DownloadAllMetrics(TestLifecycle lifecycle) - //{ - // var metricsDownloader = new MetricsDownloader(lifecycle.Log); - - // OnEachCodexNode(lifecycle, node => - // { - // var m = node.Metrics as MetricsAccess; - // if (m != null) - // { - // metricsDownloader.DownloadAllMetricsForNode(node.GetName(), m); - // } - // }); - //} - - //private void OnEachCodexNode(TestLifecycle lifecycle, Action action) - //{ - // var allNodes = lifecycle.CodexStarter.RunningGroups.SelectMany(g => g.Nodes); - // foreach (var node in allNodes) - // { - // action(node); - // } - //} - private string GetCurrentTestName() { return $"[{TestContext.CurrentContext.Test.Name}]"; diff --git a/DistTestCore/TestLifecycle.cs b/DistTestCore/TestLifecycle.cs index 4af6bc5..ef04186 100644 --- a/DistTestCore/TestLifecycle.cs +++ b/DistTestCore/TestLifecycle.cs @@ -45,29 +45,12 @@ namespace DistTestCore return entryPoint.Tools.GetFileManager(); } - //public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null) - //{ - // var subFile = Log.CreateSubfile(); - // var description = container.Name; - // var handler = new LogDownloadHandler(container, description, subFile); - - // Log.Log($"Downloading logs for {description} to file '{subFile.FullFilename}'"); - // //CodexStarter.DownloadLog(container, handler, tailLines); - - // return new DownloadedLog(subFile, description); - //} - public string GetTestDuration() { var testDuration = DateTime.UtcNow - testStart; return Time.FormatDuration(testDuration); } - ////public void SetCodexVersion(CodexDebugVersionResponse version) - ////{ - //// if (CodexVersion == null) CodexVersion = version; - ////} - //public ApplicationIds GetApplicationIds() //{ // //return new ApplicationIds( diff --git a/KubernetesWorkflow/Configuration.cs b/KubernetesWorkflow/Configuration.cs index 80505bf..2c7f440 100644 --- a/KubernetesWorkflow/Configuration.cs +++ b/KubernetesWorkflow/Configuration.cs @@ -14,5 +14,6 @@ public TimeSpan OperationTimeout { get; } public TimeSpan RetryDelay { get; } public string KubernetesNamespace { get; } + public bool AllowNamespaceOverride { get; set; } = true; } } diff --git a/KubernetesWorkflow/WorkflowCreator.cs b/KubernetesWorkflow/WorkflowCreator.cs index bc0edab..213db92 100644 --- a/KubernetesWorkflow/WorkflowCreator.cs +++ b/KubernetesWorkflow/WorkflowCreator.cs @@ -10,22 +10,33 @@ namespace KubernetesWorkflow private readonly KnownK8sPods knownPods = new KnownK8sPods(); private readonly K8sCluster cluster; private readonly ILog log; + private readonly Configuration configuration; private readonly string k8sNamespace; public WorkflowCreator(ILog log, Configuration configuration) { this.log = log; - + this.configuration = configuration; cluster = new K8sCluster(configuration); k8sNamespace = configuration.KubernetesNamespace.ToLowerInvariant(); } - public IStartupWorkflow CreateWorkflow() + public IStartupWorkflow CreateWorkflow(string? namespaceOverride = null) { var workflowNumberSource = new WorkflowNumberSource(numberSource.GetNextNumber(), containerNumberSource); - return new StartupWorkflow(log, workflowNumberSource, cluster, knownPods, k8sNamespace); + return new StartupWorkflow(log, workflowNumberSource, cluster, knownPods, GetNamespace(namespaceOverride)); + } + + private string GetNamespace(string? namespaceOverride) + { + if (namespaceOverride != null) + { + if (!configuration.AllowNamespaceOverride) throw new Exception("Namespace override is not allowed."); + return namespaceOverride; + } + return k8sNamespace; } } }