Skip to content

Commit

Permalink
Fix potential panic when following logs, due to a nil pod watcher int…
Browse files Browse the repository at this point in the history
…erface returned by K8s client-go

Fixes #7140
  • Loading branch information
rm3l committed Jun 17, 2024
1 parent 88ea016 commit cf2e64a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/kclient/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kclient

import (
"context"
"errors"
"fmt"
"io"

Expand Down Expand Up @@ -186,10 +187,18 @@ func (c *Client) GetPodsMatchingSelector(selector string) (*corev1.PodList, erro

func (c *Client) PodWatcher(ctx context.Context, selector string) (watch.Interface, error) {
ns := c.GetCurrentNamespace()
return c.GetClient().CoreV1().Pods(ns).
w, err := c.GetClient().CoreV1().Pods(ns).
Watch(ctx, metav1.ListOptions{
LabelSelector: selector,
})
if err != nil {
return nil, err
}
if w == nil {
return nil, errors.New("got a nil pod watcher, which can happen in some edge cases, " +
"such as when there is a configuration issue or network failure during the creation of the watcher object")
}
return w, nil
}

func (c *Client) IsPodNameMatchingSelector(ctx context.Context, podname string, selector string) (bool, error) {
Expand Down

0 comments on commit cf2e64a

Please sign in to comment.