Skip to content

Commit e50d428

Browse files
committed
fix: status UI hangs with a blank screen; shows no pool updates
Signed-off-by: Nick Mitchell <[email protected]>
1 parent a81e5d6 commit e50d428

File tree

2 files changed

+11
-33
lines changed

2 files changed

+11
-33
lines changed

pkg/be/kubernetes/logs.go

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package kubernetes
33
import (
44
"bufio"
55
"context"
6-
"fmt"
76
corev1 "k8s.io/api/core/v1"
8-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
97
"k8s.io/client-go/kubernetes"
108
"lunchpail.io/pkg/observe/events"
119
"strings"
@@ -18,18 +16,18 @@ type LogLine struct {
1816
Message string
1917
}
2018

21-
func streamLogUpdatesForComponent(run, namespace string, component events.Component, onlyInfo bool, c chan events.Message) error {
19+
func streamLogUpdatesForComponent(podName, namespace string, component events.Component, onlyInfo bool, c chan events.Message) error {
2220
clientset, _, err := Client()
2321
if err != nil {
2422
return err
2523
}
2624

27-
podName, err := findPodName(run, namespace, component, clientset)
28-
if err != nil {
29-
return err
30-
}
25+
// TODO leak?
26+
go func() error {
27+
return streamLogUpdatesForPod(podName, namespace, component, onlyInfo, clientset, c)
28+
}()
3129

32-
return streamLogUpdatesForPod(podName, namespace, component, onlyInfo, clientset, c)
30+
return nil
3331
}
3432

3533
func streamLogUpdatesForWorker(podName, namespace string, c chan events.Message) error {
@@ -97,24 +95,3 @@ func streamLogUpdatesForPod(podName, namespace string, component events.Componen
9795

9896
return nil
9997
}
100-
101-
func findPodName(run, namespace string, component events.Component, clientset *kubernetes.Clientset) (string, error) {
102-
for {
103-
listOptions := metav1.ListOptions{
104-
LabelSelector: "app.kubernetes.io/component=" + string(component) + ",app.kubernetes.io/instance=" + run,
105-
}
106-
107-
if pods, err := clientset.
108-
CoreV1().
109-
Pods(namespace).
110-
List(context.Background(), listOptions); err != nil {
111-
return "", err
112-
} else if len(pods.Items) == 0 {
113-
time.Sleep(1 * time.Second)
114-
} else if len(pods.Items) != 1 {
115-
return "", fmt.Errorf("Multiple %v instances found for run=%s namespace=%s\n", component, run, namespace)
116-
} else {
117-
return pods.Items[0].Name, nil
118-
}
119-
}
120-
}

pkg/be/kubernetes/updates.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ func startWatching(app, run, namespace string) (watch.Interface, error) {
2121

2222
timeout := timeoutSeconds
2323
podWatcher, err := clientset.CoreV1().Pods(namespace).Watch(context.Background(), metav1.ListOptions{
24-
TimeoutSeconds: &timeout,
25-
LabelSelector: "app.kubernetes.io/component,app.kubernetes.io/instance=" + run,
24+
TimeoutSeconds: &timeout,
25+
ResourceVersion: "",
26+
LabelSelector: "app.kubernetes.io/component,app.kubernetes.io/instance=" + run,
2627
})
2728
if err != nil {
2829
return nil, err
@@ -86,15 +87,15 @@ func updateFromPod(pod *v1.Pod, what watch.EventType, cc chan events.ComponentUp
8687
switch component {
8788
case string(events.WorkStealerComponent):
8889
if what == watch.Added {
89-
// new worker pod. start streaming its logs
90+
// new workerstealer pod. start streaming its logs
9091
if err := streamLogUpdatesForComponent(pod.Name, pod.Namespace, events.WorkStealerComponent, true, cm); err != nil {
9192
return err
9293
}
9394
}
9495
cc <- events.WorkStealerUpdate(pod.Namespace, "Kubernetes", workerStatus, what)
9596
case string(events.DispatcherComponent):
9697
if what == watch.Added {
97-
// new worker pod. start streaming its logs
98+
// new dispatcher pod. start streaming its logs
9899
if err := streamLogUpdatesForComponent(pod.Name, pod.Namespace, events.DispatcherComponent, false, cm); err != nil {
99100
return err
100101
}

0 commit comments

Comments
 (0)