From 096282ae1aa4d1a4ce65148bba430a07a062eb99 Mon Sep 17 00:00:00 2001 From: benbierens Date: Fri, 10 Nov 2023 15:23:16 +0100 Subject: [PATCH] Fixes debug/peer serialization. Adds retry for pod-finding. --- Framework/KubernetesWorkflow/K8sController.cs | 19 ++++++++++++++++++- Framework/KubernetesWorkflow/RunningPod.cs | 9 --------- ProjectPlugins/CodexPlugin/CodexApiTypes.cs | 7 +------ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Framework/KubernetesWorkflow/K8sController.cs b/Framework/KubernetesWorkflow/K8sController.cs index a8fcfa45..0ff862ef 100644 --- a/Framework/KubernetesWorkflow/K8sController.cs +++ b/Framework/KubernetesWorkflow/K8sController.cs @@ -623,11 +623,28 @@ namespace KubernetesWorkflow } private V1Pod GetPodForDeployment(RunningDeployment deployment) + { + return Time.Retry(() => GetPodForDeplomentInternal(deployment), + maxRetries: 2, + retryTime: TimeSpan.FromSeconds(10), + description: "Find pod by label for deployment."); + } + + private V1Pod GetPodForDeplomentInternal(RunningDeployment deployment) { var allPods = client.Run(c => c.ListNamespacedPod(K8sNamespace)); var pods = allPods.Items.Where(p => p.GetLabel(PodLabelKey) == deployment.PodLabel).ToArray(); - if (pods.Length != 1) throw new Exception("Expected to find only 1 pod by podLabel."); + if (pods.Length != 1) + { + var allLabels = allPods.Items.Select(p => + { + var labels = string.Join(",", p.Labels().Select(l => $"{l.Key}={l.Value}")); + return $"pod:'{p.Name()}' has labels: [{labels}]"; + }); + throw new Exception($"Expected to find 1 pod by podLabel '{deployment.PodLabel}'. Found: {pods.Length}. " + + $"Total number of pods: {allPods.Items.Count}. Their labels: {string.Join(Environment.NewLine, allLabels)}"); + } return pods[0]; } diff --git a/Framework/KubernetesWorkflow/RunningPod.cs b/Framework/KubernetesWorkflow/RunningPod.cs index cdda1dc0..f0dfc6cb 100644 --- a/Framework/KubernetesWorkflow/RunningPod.cs +++ b/Framework/KubernetesWorkflow/RunningPod.cs @@ -75,15 +75,6 @@ namespace KubernetesWorkflow public string Name { get; } public string PodLabel { get; } - - public V1Pod GetPod(K8sClient client, string k8sNamespace) - { - var allPods = client.Run(c => c.ListNamespacedPod(k8sNamespace)); - var pods = allPods.Items.Where(p => p.GetLabel(K8sController.PodLabelKey) == PodLabel).ToArray(); - - if (pods.Length != 1) throw new Exception("Expected to find only 1 pod by podLabel."); - return pods[0]; - } } public class RunningService diff --git a/ProjectPlugins/CodexPlugin/CodexApiTypes.cs b/ProjectPlugins/CodexPlugin/CodexApiTypes.cs index 03e112f2..af523833 100644 --- a/ProjectPlugins/CodexPlugin/CodexApiTypes.cs +++ b/ProjectPlugins/CodexPlugin/CodexApiTypes.cs @@ -76,12 +76,7 @@ namespace CodexPlugin public string peerId { get; set; } = string.Empty; public long seqNo { get; set; } - public CodexDebugPeerAddressResponse[] addresses { get; set; } = Array.Empty(); - } - - public class CodexDebugPeerAddressResponse - { - public string address { get; set; } = string.Empty; + public string[] addresses { get; set; } = Array.Empty(); } public class CodexDebugThresholdBreaches