Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vimystic committed Apr 2, 2024
1 parent ba39b77 commit 350f618
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions internal/fullnode/stuck_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ""
}

0 comments on commit 350f618

Please sign in to comment.