Tidy
This commit is contained in:
parent
be99d25fb2
commit
3288b488d3
|
@ -179,11 +179,7 @@ func (pw *PodWatcher) removePod(podName string) {
|
||||||
func copyPodLogs(ctx context.Context, wg *sync.WaitGroup, client KubernetesClient, pod *corev1.Pod, container string, logStream chan string) *streamError {
|
func copyPodLogs(ctx context.Context, wg *sync.WaitGroup, client KubernetesClient, pod *corev1.Pod, container string, logStream chan string) *streamError {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
podLogOpts := corev1.PodLogOptions{
|
req := client.Typed.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &corev1.PodLogOptions{Follow: true, Container: container})
|
||||||
Follow: true,
|
|
||||||
Container: container,
|
|
||||||
}
|
|
||||||
req := client.Typed.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts)
|
|
||||||
logs, err := req.Stream(ctx)
|
logs, err := req.Stream(ctx)
|
||||||
|
|
||||||
// If one container is still being created, do not treat this as a fatal error.
|
// If one container is still being created, do not treat this as a fatal error.
|
||||||
|
|
|
@ -95,7 +95,6 @@ func (w *Watcher) Watch(ctx context.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer watcher.Stop()
|
defer watcher.Stop()
|
||||||
|
|
||||||
ticker := time.NewTicker(time.Second)
|
ticker := time.NewTicker(time.Second)
|
||||||
|
@ -112,7 +111,6 @@ func (w *Watcher) Watch(ctx context.Context) error {
|
||||||
switch evt.Type {
|
switch evt.Type {
|
||||||
case watch.Added, watch.Modified:
|
case watch.Added, watch.Modified:
|
||||||
resource := evt.Object.(*unstructured.Unstructured)
|
resource := evt.Object.(*unstructured.Unstructured)
|
||||||
uid := resource.GetUID()
|
|
||||||
// TODO: handle matchExpressions
|
// TODO: handle matchExpressions
|
||||||
selectorAsMap, ok, err := unstructured.NestedStringMap(resource.Object, "spec", "selector", "matchLabels")
|
selectorAsMap, ok, err := unstructured.NestedStringMap(resource.Object, "spec", "selector", "matchLabels")
|
||||||
if !ok || err != nil {
|
if !ok || err != nil {
|
||||||
|
@ -121,12 +119,12 @@ func (w *Watcher) Watch(ctx context.Context) error {
|
||||||
w.logger.Printf("warning: unable to parse matchLabels: ok = %t, err = %v", ok, err)
|
w.logger.Printf("warning: unable to parse matchLabels: ok = %t, err = %v", ok, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
selector := labels.SelectorFromSet(selectorAsMap)
|
|
||||||
w.addDeployment(ctx, uid, selector)
|
|
||||||
|
|
||||||
|
w.addDeployment(ctx, resource.GetUID(), labels.SelectorFromSet(selectorAsMap))
|
||||||
case watch.Deleted:
|
case watch.Deleted:
|
||||||
w.removeDeployment()
|
w.removeDeployment()
|
||||||
}
|
}
|
||||||
|
// errChan is never closed.
|
||||||
case err := <-w.errChan:
|
case err := <-w.errChan:
|
||||||
return err
|
return err
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|
Loading…
Reference in New Issue