From 350f618d2a23cb7a4512f1846e209a8e36c32b8c Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:52:21 -0600 Subject: [PATCH] update --- internal/fullnode/stuck_detection.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/internal/fullnode/stuck_detection.go b/internal/fullnode/stuck_detection.go index 78dd0de7..0c95576d 100644 --- a/internal/fullnode/stuck_detection.go +++ b/internal/fullnode/stuck_detection.go @@ -3,23 +3,21 @@ package fullnode import ( "context" "fmt" - "io/ioutil" + "io" "strings" - "time" cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" "github.com/strangelove-ventures/cosmos-operator/internal/kube" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" ) type StuckPodDetection struct { - available func(pods []*corev1.Pod, minReady time.Duration, now time.Time) []*corev1.Pod - collector StatusCollector - computeRollout func(maxUnavail *intstr.IntOrString, desired, ready int) int + //available func(pods []*corev1.Pod, minReady time.Duration, now time.Time) []*corev1.Pod + collector StatusCollector + //computeRollout func(maxUnavail *intstr.IntOrString, desired, ready int) int } func NewStuckDetection(collector StatusCollector) DriftDetection { @@ -47,34 +45,34 @@ func (d StuckPodDetection) StuckPods(ctx context.Context, crd *cosmosv1.CosmosFu panic(err.Error()) } - getPodLogsLastLine(clientset, pods[0]) + testString := getPodLogsLastLine(clientset, pods[0]) + fmt.Println(testString) //MORE TODO HERE return []*corev1.Pod{} } -func getPodLogsLastLine(clientset *kubernetes.Clientset, pod *corev1.Pod) { +func getPodLogsLastLine(clientset *kubernetes.Clientset, pod *corev1.Pod) string { podLogOpts := corev1.PodLogOptions{} logRequest := clientset.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts) logStream, err := logRequest.Stream(context.Background()) if err != nil { fmt.Printf("Error getting logs for pod %s: %v\n", pod.Name, err) - return + return "" } defer logStream.Close() - logBytes, err := ioutil.ReadAll(logStream) + logBytes, err := io.ReadAll(logStream) if err != nil { fmt.Printf("Error reading logs for pod %s: %v\n", pod.Name, err) - return + return "" } logLines := strings.Split(strings.TrimRight(string(logBytes), "\n"), "\n") if len(logLines) > 0 { - fmt.Println("Last line of logs for pod", pod.Name+":", logLines[len(logLines)-1]) - } else { - fmt.Println("No logs found for pod", pod.Name) + return logLines[len(logLines)-1] } + return "" }