From ecd0e702616f5797f23f954ec3170a4ab5b31107 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 21 Aug 2024 10:45:17 +0200 Subject: [PATCH] fixes serialization issue of containerAdditionals --- .../Recipe/ContainerAdditionals.cs | 12 ++++++------ ProjectPlugins/CodexPlugin/CodexSetup.cs | 7 ++++--- ProjectPlugins/CodexPlugin/CodexStarter.cs | 9 +++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Framework/KubernetesWorkflow/Recipe/ContainerAdditionals.cs b/Framework/KubernetesWorkflow/Recipe/ContainerAdditionals.cs index 21fe249..5ec73a0 100644 --- a/Framework/KubernetesWorkflow/Recipe/ContainerAdditionals.cs +++ b/Framework/KubernetesWorkflow/Recipe/ContainerAdditionals.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace KubernetesWorkflow.Recipe { @@ -21,14 +22,13 @@ namespace KubernetesWorkflow.Recipe var typeName = GetTypeName(typeof(T)); var userData = Additionals.SingleOrDefault(a => a.Type == typeName); if (userData == null) return default; - var jobject = (JObject)userData.UserData; - return jobject.ToObject(); + return JsonConvert.DeserializeObject(userData.UserData); } private static Additional ConvertToAdditional(object userData) { var typeName = GetTypeName(userData.GetType()); - return new Additional(typeName, userData); + return new Additional(typeName, JsonConvert.SerializeObject(userData)); } private static string GetTypeName(Type type) @@ -41,13 +41,13 @@ namespace KubernetesWorkflow.Recipe public class Additional { - public Additional(string type, object userData) + public Additional(string type, string userData) { Type = type; UserData = userData; } public string Type { get; } - public object UserData { get; } + public string UserData { get; } } } diff --git a/ProjectPlugins/CodexPlugin/CodexSetup.cs b/ProjectPlugins/CodexPlugin/CodexSetup.cs index 44454c7..b8ef3bb 100644 --- a/ProjectPlugins/CodexPlugin/CodexSetup.cs +++ b/ProjectPlugins/CodexPlugin/CodexSetup.cs @@ -169,7 +169,7 @@ namespace CodexPlugin public bool IsValidator { get; private set; } public Ether InitialEth { get; private set; } = 0.Eth(); public TestToken InitialTestTokens { get; private set; } = 0.Tst(); - public EthAccountSetup EthAccountSetup { get; private set; } = new EthAccountSetup(); + public EthAccountSetup EthAccountSetup { get; } = new EthAccountSetup(); public IMarketplaceSetup AsStorageNode() { @@ -201,8 +201,8 @@ namespace CodexPlugin var result = "[(clientNode)"; // When marketplace is enabled, being a clientNode is implicit. result += IsStorageNode ? "(storageNode)" : "()"; result += IsValidator ? "(validator)" : "() "; - result += $"Address: '{EthAccountSetup}' "; - result += $"{InitialEth.Eth} / {InitialTestTokens}"; + result += $"Pinned address: '{EthAccountSetup}' "; + result += $"{InitialEth} / {InitialTestTokens}"; result += "] "; return result; } @@ -235,6 +235,7 @@ namespace CodexPlugin public override string ToString() { + if (!accounts.Any()) return "NoEthAccounts"; return string.Join(",", accounts.Select(a => a.ToString()).ToArray()); } } diff --git a/ProjectPlugins/CodexPlugin/CodexStarter.cs b/ProjectPlugins/CodexPlugin/CodexStarter.cs index 59edf4e..4c43372 100644 --- a/ProjectPlugins/CodexPlugin/CodexStarter.cs +++ b/ProjectPlugins/CodexPlugin/CodexStarter.cs @@ -1,5 +1,6 @@ using CodexPlugin.Hooks; using Core; +using GethPlugin; using KubernetesWorkflow; using KubernetesWorkflow.Types; using Logging; @@ -38,6 +39,7 @@ namespace CodexPlugin var podInfo = GetPodInfo(rc); var podInfos = string.Join(", ", rc.Containers.Select(c => $"Container: '{c.Name}' PodLabel: '{c.RunningPod.StartResult.Deployment.PodLabel}' runs at '{podInfo.K8SNodeName}'={podInfo.Ip}")); Log($"Started node with image '{containers.First().Containers.First().Recipe.Image}'. ({podInfos})"); + LogEthAddress(rc); } LogSeparator(); @@ -144,6 +146,13 @@ namespace CodexPlugin Log("----------------------------------------------------------------------------"); } + private void LogEthAddress(RunningPod rc) + { + var account = rc.Containers.First().Recipe.Additionals.Get(); + if (account == null) return; + Log($"{rc.Name} = {account}"); + } + private void Log(string message) { pluginTools.GetLog().Log(message);