From 95405778fcd54aa34674876bf68284955612b48d Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:28:08 -0600 Subject: [PATCH] Update --- internal/fullnode/stuck_detection.go | 41 ++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/internal/fullnode/stuck_detection.go b/internal/fullnode/stuck_detection.go index 64cbaa6d..25d5ff8f 100644 --- a/internal/fullnode/stuck_detection.go +++ b/internal/fullnode/stuck_detection.go @@ -35,26 +35,37 @@ func (d StuckPodDetection) StuckPods(ctx context.Context, crd *cosmosv1.CosmosFu pods := d.collector.Collect(ctx, client.ObjectKeyFromObject(crd)).Synced().Pods() - fmt.Println(pods[0]) + for i, pod := range pods { - config, err := rest.InClusterConfig() - if err != nil { - panic(err.Error()) - } + config, err := rest.InClusterConfig() + if err != nil { + panic(err.Error()) + } - clientset, err := kubernetes.NewForConfig(config) - if err != nil { - panic(err.Error()) - } + clientset, err := kubernetes.NewForConfig(config) + if err != nil { + panic(err.Error()) + } + + testString := getPodLogsLastLine(clientset, pod) + fmt.Println(testString) + podIsStuck := isPodStuck(testString) - testString := getPodLogsLastLine(clientset, pods[0]) - fmt.Println(testString) + //MORE TODO HERE + if podIsStuck { + pods = removeElement(pods, i) + } - //MORE TODO HERE + } return []*corev1.Pod{} } + +func isPodStuck(testString string) bool { + return strings.Contains(inputString, "SignerListener: Connected") +} + func getPodLogsLastLine(clientset *kubernetes.Clientset, pod *corev1.Pod) string { podLogOpts := corev1.PodLogOptions{} logRequest := clientset.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts) @@ -78,3 +89,9 @@ func getPodLogsLastLine(clientset *kubernetes.Clientset, pod *corev1.Pod) string } return "" } + +} + +func removeElement(slice []*corev1.Pod, index int) []*corev1.Pod { + return append(slice[:index], slice[index+1:]...) +} \ No newline at end of file