Cleanup of kubernetesWorkflow assembly.

This commit is contained in:
benbierens 2023-11-12 10:07:23 +01:00
parent b78f527c39
commit ed56d9edcc
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
63 changed files with 301 additions and 242 deletions

View File

@ -1,4 +1,5 @@
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
namespace Core namespace Core
{ {

View File

@ -54,16 +54,4 @@ namespace KubernetesWorkflow
} }
} }
} }
public class K8sNodeLabel
{
public K8sNodeLabel(string key, string value)
{
Key = key;
Value = value;
}
public string Key { get; }
public string Value { get; }
}
} }

View File

@ -1,5 +1,7 @@
using k8s; using k8s;
using k8s.Models; using k8s.Models;
using KubernetesWorkflow.Recipe;
using KubernetesWorkflow.Types;
using Logging; using Logging;
using Utils; using Utils;

View File

@ -1,4 +1,7 @@
namespace KubernetesWorkflow using KubernetesWorkflow.Recipe;
using KubernetesWorkflow.Types;
namespace KubernetesWorkflow
{ {
public interface IK8sHooks public interface IK8sHooks
{ {

View File

@ -1,4 +1,6 @@
namespace KubernetesWorkflow using KubernetesWorkflow.Types;
namespace KubernetesWorkflow
{ {
public interface ILocation public interface ILocation
{ {

View File

@ -1,4 +1,5 @@
using Logging; using KubernetesWorkflow.Types;
using Logging;
namespace KubernetesWorkflow namespace KubernetesWorkflow
{ {

View File

@ -0,0 +1,23 @@
namespace KubernetesWorkflow
{
public interface ILogHandler
{
void Log(Stream log);
}
public abstract class LogHandler : ILogHandler
{
public void Log(Stream log)
{
using var reader = new StreamReader(log);
var line = reader.ReadLine();
while (line != null)
{
ProcessLine(line);
line = reader.ReadLine();
}
}
protected abstract void ProcessLine(string line);
}
}

View File

@ -1,6 +1,6 @@
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace KubernetesWorkflow namespace KubernetesWorkflow.Recipe
{ {
public class ContainerAdditionals public class ContainerAdditionals
{ {
@ -20,7 +20,7 @@ namespace KubernetesWorkflow
{ {
var typeName = GetTypeName(typeof(T)); var typeName = GetTypeName(typeof(T));
var userData = Additionals.SingleOrDefault(a => a.Type == typeName); var userData = Additionals.SingleOrDefault(a => a.Type == typeName);
if (userData == null) return default(T); if (userData == null) return default;
var jobject = (JObject)userData.UserData; var jobject = (JObject)userData.UserData;
return jobject.ToObject<T>(); return jobject.ToObject<T>();
} }

View File

@ -1,4 +1,4 @@
namespace KubernetesWorkflow namespace KubernetesWorkflow.Recipe
{ {
public class ContainerRecipe public class ContainerRecipe
{ {

View File

@ -1,6 +1,6 @@
using Utils; using Utils;
namespace KubernetesWorkflow namespace KubernetesWorkflow.Recipe
{ {
public abstract class ContainerRecipeFactory public abstract class ContainerRecipeFactory
{ {

View File

@ -1,6 +1,6 @@
using Utils; using Utils;
namespace KubernetesWorkflow namespace KubernetesWorkflow.Recipe
{ {
public class ContainerResources public class ContainerResources
{ {

View File

@ -1,4 +1,4 @@
namespace KubernetesWorkflow namespace KubernetesWorkflow.Recipe
{ {
public class PodAnnotations public class PodAnnotations
{ {

View File

@ -1,4 +1,4 @@
namespace KubernetesWorkflow namespace KubernetesWorkflow.Recipe
{ {
public class PodLabels public class PodLabels
{ {

View File

@ -1,7 +1,7 @@
using System.Globalization; using System.Globalization;
using Utils; using Utils;
namespace KubernetesWorkflow namespace KubernetesWorkflow.Recipe
{ {
public class RecipeComponentFactory public class RecipeComponentFactory
{ {

View File

@ -1,113 +0,0 @@
using Logging;
using Newtonsoft.Json;
using Utils;
namespace KubernetesWorkflow
{
public class RunningContainers
{
public RunningContainers(StartupConfig startupConfig, StartResult startResult, RunningContainer[] containers)
{
StartupConfig = startupConfig;
StartResult = startResult;
Containers = containers;
foreach (var c in containers) c.RunningContainers = this;
}
public StartupConfig StartupConfig { get; }
public StartResult StartResult { get; }
public RunningContainer[] Containers { get; }
[JsonIgnore]
public string Name
{
get { return $"{Containers.Length}x '{Containers.First().Name}'"; }
}
public string Describe()
{
return string.Join(",", Containers.Select(c => c.Name));
}
}
public class RunningContainer
{
public RunningContainer(string name, ContainerRecipe recipe, ContainerAddress[] addresses)
{
Name = name;
Recipe = recipe;
Addresses = addresses;
}
public string Name { get; }
public ContainerRecipe Recipe { get; }
public ContainerAddress[] Addresses { get; }
[JsonIgnore]
public RunningContainers RunningContainers { get; internal set; } = null!;
public Address GetAddress(ILog log, string portTag)
{
var addresses = Addresses.Where(a => a.PortTag == portTag).ToArray();
if (!addresses.Any()) throw new Exception("No addresses found for portTag: " + portTag);
var select = SelectAddress(addresses);
log.Log($"Container '{Name}' selected for tag '{portTag}' address: '{select}'");
return select.Address;
}
public Address GetInternalAddress(string portTag)
{
var containerAddress = Addresses.Single(a => a.PortTag == portTag && a.IsInteral);
return containerAddress.Address;
}
private ContainerAddress SelectAddress(ContainerAddress[] addresses)
{
var location = RunnerLocationUtils.GetRunnerLocation();
if (location == RunnerLocation.InternalToCluster)
{
return addresses.Single(a => a.IsInteral);
}
if (location == RunnerLocation.ExternalToCluster)
{
return addresses.Single(a => !a.IsInteral);
}
throw new Exception("Running location not known.");
}
}
public class ContainerAddress
{
public ContainerAddress(string portTag, Address address, bool isInteral)
{
PortTag = portTag;
Address = address;
IsInteral = isInteral;
}
public string PortTag { get; }
public Address Address { get; }
public bool IsInteral { get; }
public override string ToString()
{
var indicator = IsInteral ? "int" : "ext";
return $"{indicator} {PortTag} -> '{Address}'";
}
}
public static class RunningContainersExtensions
{
public static RunningContainer[] Containers(this RunningContainers[] runningContainers)
{
return runningContainers.SelectMany(c => c.Containers).ToArray();
}
public static string Describe(this RunningContainers[] runningContainers)
{
return string.Join(",", runningContainers.Select(c => c.Describe()));
}
}
}

View File

@ -1,5 +1,7 @@
using k8s; using k8s;
using k8s.Models; using k8s.Models;
using KubernetesWorkflow.Recipe;
using KubernetesWorkflow.Types;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace KubernetesWorkflow namespace KubernetesWorkflow
@ -64,67 +66,4 @@ namespace KubernetesWorkflow
return Array.Empty<Port>(); return Array.Empty<Port>();
} }
} }
public class RunningDeployment
{
public RunningDeployment(string name, string podLabel)
{
Name = name;
PodLabel = podLabel;
}
public string Name { get; }
public string PodLabel { get; }
}
public class RunningService
{
public RunningService(string name, List<ContainerRecipePortMapEntry> result)
{
Name = name;
Result = result;
}
public string Name { get; }
public List<ContainerRecipePortMapEntry> Result { get; }
public Port? GetServicePortForRecipeAndTag(ContainerRecipe recipe, string tag)
{
return GetServicePortsForRecipe(recipe).SingleOrDefault(p => p.Tag == tag);
}
public Port[] GetServicePortsForRecipe(ContainerRecipe recipe)
{
return Result
.Where(p => p.RecipeNumber == recipe.Number)
.SelectMany(p => p.Ports)
.ToArray();
}
}
public class ContainerRecipePortMapEntry
{
public ContainerRecipePortMapEntry(int recipeNumber, Port[] ports)
{
RecipeNumber = recipeNumber;
Ports = ports;
}
public int RecipeNumber { get; }
public Port[] Ports { get; }
}
public class PodInfo
{
public PodInfo(string name, string ip, string k8sNodeName)
{
Name = name;
Ip = ip;
K8SNodeName = k8sNodeName;
}
public string Name { get; }
public string Ip { get; }
public string K8SNodeName { get; }
}
} }

View File

@ -1,4 +1,6 @@
using Logging; using KubernetesWorkflow.Recipe;
using KubernetesWorkflow.Types;
using Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Utils; using Utils;
@ -241,25 +243,4 @@ namespace KubernetesWorkflow
} }
} }
} }
public interface ILogHandler
{
void Log(Stream log);
}
public abstract class LogHandler : ILogHandler
{
public void Log(Stream log)
{
using var reader = new StreamReader(log);
var line = reader.ReadLine();
while (line != null)
{
ProcessLine(line);
line = reader.ReadLine();
}
}
protected abstract void ProcessLine(string line);
}
} }

View File

@ -0,0 +1,24 @@
using Utils;
namespace KubernetesWorkflow.Types
{
public class ContainerAddress
{
public ContainerAddress(string portTag, Address address, bool isInteral)
{
PortTag = portTag;
Address = address;
IsInteral = isInteral;
}
public string PortTag { get; }
public Address Address { get; }
public bool IsInteral { get; }
public override string ToString()
{
var indicator = IsInteral ? "int" : "ext";
return $"{indicator} {PortTag} -> '{Address}'";
}
}
}

View File

@ -0,0 +1,16 @@
using KubernetesWorkflow.Recipe;
namespace KubernetesWorkflow.Types
{
public class ContainerRecipePortMapEntry
{
public ContainerRecipePortMapEntry(int recipeNumber, Port[] ports)
{
RecipeNumber = recipeNumber;
Ports = ports;
}
public int RecipeNumber { get; }
public Port[] Ports { get; }
}
}

View File

@ -0,0 +1,14 @@
namespace KubernetesWorkflow.Types
{
public class K8sNodeLabel
{
public K8sNodeLabel(string key, string value)
{
Key = key;
Value = value;
}
public string Key { get; }
public string Value { get; }
}
}

View File

@ -0,0 +1,16 @@
namespace KubernetesWorkflow.Types
{
public class PodInfo
{
public PodInfo(string name, string ip, string k8sNodeName)
{
Name = name;
Ip = ip;
K8SNodeName = k8sNodeName;
}
public string Name { get; }
public string Ip { get; }
public string K8SNodeName { get; }
}
}

View File

@ -0,0 +1,54 @@
using KubernetesWorkflow.Recipe;
using Logging;
using Newtonsoft.Json;
using Utils;
namespace KubernetesWorkflow.Types
{
public class RunningContainer
{
public RunningContainer(string name, ContainerRecipe recipe, ContainerAddress[] addresses)
{
Name = name;
Recipe = recipe;
Addresses = addresses;
}
public string Name { get; }
public ContainerRecipe Recipe { get; }
public ContainerAddress[] Addresses { get; }
[JsonIgnore]
public RunningContainers RunningContainers { get; internal set; } = null!;
public Address GetAddress(ILog log, string portTag)
{
var addresses = Addresses.Where(a => a.PortTag == portTag).ToArray();
if (!addresses.Any()) throw new Exception("No addresses found for portTag: " + portTag);
var select = SelectAddress(addresses);
log.Debug($"Container '{Name}' selected for tag '{portTag}' address: '{select}'");
return select.Address;
}
public Address GetInternalAddress(string portTag)
{
var containerAddress = Addresses.Single(a => a.PortTag == portTag && a.IsInteral);
return containerAddress.Address;
}
private ContainerAddress SelectAddress(ContainerAddress[] addresses)
{
var location = RunnerLocationUtils.GetRunnerLocation();
if (location == RunnerLocation.InternalToCluster)
{
return addresses.Single(a => a.IsInteral);
}
if (location == RunnerLocation.ExternalToCluster)
{
return addresses.Single(a => !a.IsInteral);
}
throw new Exception("Running location not known.");
}
}
}

View File

@ -0,0 +1,44 @@
using Newtonsoft.Json;
namespace KubernetesWorkflow.Types
{
public class RunningContainers
{
public RunningContainers(StartupConfig startupConfig, StartResult startResult, RunningContainer[] containers)
{
StartupConfig = startupConfig;
StartResult = startResult;
Containers = containers;
foreach (var c in containers) c.RunningContainers = this;
}
public StartupConfig StartupConfig { get; }
public StartResult StartResult { get; }
public RunningContainer[] Containers { get; }
[JsonIgnore]
public string Name
{
get { return $"{Containers.Length}x '{Containers.First().Name}'"; }
}
public string Describe()
{
return string.Join(",", Containers.Select(c => c.Name));
}
}
public static class RunningContainersExtensions
{
public static RunningContainer[] Containers(this RunningContainers[] runningContainers)
{
return runningContainers.SelectMany(c => c.Containers).ToArray();
}
public static string Describe(this RunningContainers[] runningContainers)
{
return string.Join(",", runningContainers.Select(c => c.Describe()));
}
}
}

View File

@ -0,0 +1,14 @@
namespace KubernetesWorkflow.Types
{
public class RunningDeployment
{
public RunningDeployment(string name, string podLabel)
{
Name = name;
PodLabel = podLabel;
}
public string Name { get; }
public string PodLabel { get; }
}
}

View File

@ -0,0 +1,29 @@
using KubernetesWorkflow.Recipe;
namespace KubernetesWorkflow.Types
{
public class RunningService
{
public RunningService(string name, List<ContainerRecipePortMapEntry> result)
{
Name = name;
Result = result;
}
public string Name { get; }
public List<ContainerRecipePortMapEntry> Result { get; }
public Port? GetServicePortForRecipeAndTag(ContainerRecipe recipe, string tag)
{
return GetServicePortsForRecipe(recipe).SingleOrDefault(p => p.Tag == tag);
}
public Port[] GetServicePortsForRecipe(ContainerRecipe recipe)
{
return Result
.Where(p => p.RecipeNumber == recipe.Number)
.SelectMany(p => p.Ports)
.ToArray();
}
}
}

View File

@ -1,5 +1,6 @@
using GethPlugin; using GethPlugin;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Recipe;
using Logging; using Logging;
namespace CodexContractsPlugin namespace CodexContractsPlugin

View File

@ -1,6 +1,7 @@
using Core; using Core;
using GethPlugin; using GethPlugin;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
using Logging; using Logging;
using Utils; using Utils;

View File

@ -1,4 +1,5 @@
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
using Logging; using Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;

View File

@ -1,5 +1,6 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
namespace CodexDiscordBotPlugin namespace CodexDiscordBotPlugin
{ {

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
namespace CodexDiscordBotPlugin namespace CodexDiscordBotPlugin
{ {

View File

@ -1,4 +1,5 @@
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Recipe;
using Utils; using Utils;
namespace CodexDiscordBotPlugin namespace CodexDiscordBotPlugin

View File

@ -1,5 +1,6 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
using Utils; using Utils;
namespace CodexPlugin namespace CodexPlugin

View File

@ -1,5 +1,6 @@
using GethPlugin; using GethPlugin;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Recipe;
using Utils; using Utils;
namespace CodexPlugin namespace CodexPlugin

View File

@ -1,6 +1,6 @@
using CodexContractsPlugin; using CodexContractsPlugin;
using GethPlugin; using GethPlugin;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
namespace CodexPlugin namespace CodexPlugin
{ {

View File

@ -2,6 +2,7 @@
using FileUtils; using FileUtils;
using GethPlugin; using GethPlugin;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
using Logging; using Logging;
using MetricsPlugin; using MetricsPlugin;
using Utils; using Utils;

View File

@ -1,6 +1,7 @@
using Core; using Core;
using GethPlugin; using GethPlugin;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
namespace CodexPlugin namespace CodexPlugin
{ {

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
using MetricsPlugin; using MetricsPlugin;
using System.Collections; using System.Collections;

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
namespace CodexPlugin namespace CodexPlugin
{ {

View File

@ -1,5 +1,6 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
using Logging; using Logging;
namespace CodexPlugin namespace CodexPlugin

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
namespace CodexPlugin namespace CodexPlugin
{ {

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
namespace DeployAndRunPlugin namespace DeployAndRunPlugin
{ {

View File

@ -1,4 +1,5 @@
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Recipe;
namespace DeployAndRunPlugin namespace DeployAndRunPlugin
{ {

View File

@ -1,5 +1,6 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
namespace DeployAndRunPlugin namespace DeployAndRunPlugin
{ {

View File

@ -1,4 +1,5 @@
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
using Logging; using Logging;
using Utils; using Utils;

View File

@ -1,4 +1,5 @@
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Recipe;
namespace GethPlugin namespace GethPlugin
{ {

View File

@ -1,5 +1,6 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Recipe;
using KubernetesWorkflow.Types;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace GethPlugin namespace GethPlugin

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
using Logging; using Logging;
using Nethereum.Contracts; using Nethereum.Contracts;
using NethereumWorkflow; using NethereumWorkflow;

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
using Logging; using Logging;
namespace MetricsPlugin namespace MetricsPlugin

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
using Utils; using Utils;
namespace MetricsPlugin namespace MetricsPlugin

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
using Logging; using Logging;
namespace MetricsPlugin namespace MetricsPlugin

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
using Logging; using Logging;
using System.Globalization; using System.Globalization;

View File

@ -1,4 +1,4 @@
using KubernetesWorkflow; using KubernetesWorkflow.Types;
namespace MetricsPlugin namespace MetricsPlugin
{ {

View File

@ -1,4 +1,5 @@
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Recipe;
namespace MetricsPlugin namespace MetricsPlugin
{ {

View File

@ -1,5 +1,6 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Types;
using Logging; using Logging;
using System.Text; using System.Text;

View File

@ -1,5 +1,5 @@
using Core; using Core;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
using Logging; using Logging;
using Utils; using Utils;

View File

@ -1,9 +1,9 @@
using KubernetesWorkflow; using NUnit.Framework;
using NUnit.Framework;
using Logging; using Logging;
using Utils; using Utils;
using Core; using Core;
using CodexPlugin; using CodexPlugin;
using KubernetesWorkflow.Types;
namespace ContinuousTests namespace ContinuousTests
{ {

View File

@ -1,11 +1,11 @@
using Logging; using Logging;
using Utils; using Utils;
using KubernetesWorkflow;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using System.Reflection; using System.Reflection;
using CodexPlugin; using CodexPlugin;
using DistTestCore.Logs; using DistTestCore.Logs;
using Core; using Core;
using KubernetesWorkflow.Types;
namespace ContinuousTests namespace ContinuousTests
{ {

View File

@ -1,7 +1,7 @@
using CodexContractsPlugin; using CodexContractsPlugin;
using CodexPlugin; using CodexPlugin;
using GethPlugin; using GethPlugin;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
using Logging; using Logging;
using MetricsPlugin; using MetricsPlugin;
using NUnit.Framework; using NUnit.Framework;

View File

@ -2,6 +2,8 @@
using DistTestCore.Logs; using DistTestCore.Logs;
using FileUtils; using FileUtils;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Recipe;
using KubernetesWorkflow.Types;
using Utils; using Utils;
namespace DistTestCore namespace DistTestCore

View File

@ -3,7 +3,7 @@ using CodexDiscordBotPlugin;
using CodexPlugin; using CodexPlugin;
using Core; using Core;
using GethPlugin; using GethPlugin;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
using Logging; using Logging;
using MetricsPlugin; using MetricsPlugin;

View File

@ -1,5 +1,7 @@
using DistTestCore; using DistTestCore;
using KubernetesWorkflow; using KubernetesWorkflow;
using KubernetesWorkflow.Recipe;
using KubernetesWorkflow.Types;
namespace CodexNetDeployer namespace CodexNetDeployer
{ {

View File

@ -1,4 +1,4 @@
using KubernetesWorkflow; using KubernetesWorkflow.Types;
namespace TestClusterStarter namespace TestClusterStarter
{ {

View File

@ -1,7 +1,7 @@
using ArgsUniform; using ArgsUniform;
using Core; using Core;
using DeployAndRunPlugin; using DeployAndRunPlugin;
using KubernetesWorkflow; using KubernetesWorkflow.Types;
using Logging; using Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using TestClusterStarter; using TestClusterStarter;