@@ -3,9 +3,7 @@ package kubernetes
3
3
import (
4
4
"bufio"
5
5
"context"
6
- "fmt"
7
6
corev1 "k8s.io/api/core/v1"
8
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
7
"k8s.io/client-go/kubernetes"
10
8
"lunchpail.io/pkg/observe/events"
11
9
"strings"
@@ -18,18 +16,18 @@ type LogLine struct {
18
16
Message string
19
17
}
20
18
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 {
22
20
clientset , _ , err := Client ()
23
21
if err != nil {
24
22
return err
25
23
}
26
24
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
+ }()
31
29
32
- return streamLogUpdatesForPod ( podName , namespace , component , onlyInfo , clientset , c )
30
+ return nil
33
31
}
34
32
35
33
func streamLogUpdatesForWorker (podName , namespace string , c chan events.Message ) error {
@@ -97,24 +95,3 @@ func streamLogUpdatesForPod(podName, namespace string, component events.Componen
97
95
98
96
return nil
99
97
}
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
- }
0 commit comments