cs-codex-dist-tests/DistTestCore/Configuration.cs

74 lines
2.4 KiB
C#
Raw Normal View History

2023-09-12 11:32:06 +00:00
using Core;
using KubernetesWorkflow;
2023-04-12 14:06:04 +00:00
namespace DistTestCore
{
public class Configuration
{
private readonly string? kubeConfigFile;
private readonly string logPath;
private readonly bool logDebug;
private readonly string dataFilesPath;
public Configuration()
{
kubeConfigFile = GetNullableEnvVarOrDefault("KUBECONFIG", null);
logPath = GetEnvVarOrDefault("LOGPATH", "CodexTestLogs");
2023-07-17 06:54:07 +00:00
logDebug = GetEnvVarOrDefault("LOGDEBUG", "false").ToLowerInvariant() == "true";
dataFilesPath = GetEnvVarOrDefault("DATAFILEPATH", "TestDataFiles");
2023-06-22 08:17:12 +00:00
}
public Configuration(string? kubeConfigFile, string logPath, bool logDebug, string dataFilesPath)
2023-06-22 08:17:12 +00:00
{
this.kubeConfigFile = kubeConfigFile;
this.logPath = logPath;
this.logDebug = logDebug;
this.dataFilesPath = dataFilesPath;
}
public KubernetesWorkflow.Configuration GetK8sConfiguration(ITimeSet timeSet, string k8sNamespace)
{
return GetK8sConfiguration(timeSet, new DoNothingK8sHooks(), k8sNamespace);
}
public KubernetesWorkflow.Configuration GetK8sConfiguration(ITimeSet timeSet, IK8sHooks hooks, string k8sNamespace)
2023-04-12 14:06:04 +00:00
{
var config = new KubernetesWorkflow.Configuration(
kubeConfigFile: kubeConfigFile,
operationTimeout: timeSet.K8sOperationTimeout(),
retryDelay: timeSet.WaitForK8sServiceDelay(),
kubernetesNamespace: k8sNamespace
2023-04-12 14:06:04 +00:00
);
config.AllowNamespaceOverride = false;
config.Hooks = hooks;
return config;
2023-04-12 14:06:04 +00:00
}
public Logging.LogConfig GetLogConfig()
{
return new Logging.LogConfig(logPath, debugEnabled: logDebug);
2023-04-12 14:06:04 +00:00
}
public string GetFileManagerFolder()
{
return dataFilesPath;
2023-04-12 14:06:04 +00:00
}
2023-05-31 11:34:12 +00:00
private static string GetEnvVarOrDefault(string varName, string defaultValue)
{
var v = Environment.GetEnvironmentVariable(varName);
if (v == null) return defaultValue;
return v;
}
private static string? GetNullableEnvVarOrDefault(string varName, string? defaultValue)
{
var v = Environment.GetEnvironmentVariable(varName);
if (v == null) return defaultValue;
return v;
}
}
2023-04-12 14:06:04 +00:00
}