Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit cf2e64a

Browse files
committed
Fix potential panic when following logs, due to a nil pod watcher interface returned by K8s client-go
Fixes #7140
1 parent 88ea016 commit cf2e64a

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

pkg/kclient/pods.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kclient
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"io"
78

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

187188
func (c *Client) PodWatcher(ctx context.Context, selector string) (watch.Interface, error) {
188189
ns := c.GetCurrentNamespace()
189-
return c.GetClient().CoreV1().Pods(ns).
190+
w, err := c.GetClient().CoreV1().Pods(ns).
190191
Watch(ctx, metav1.ListOptions{
191192
LabelSelector: selector,
192193
})
194+
if err != nil {
195+
return nil, err
196+
}
197+
if w == nil {
198+
return nil, errors.New("got a nil pod watcher, which can happen in some edge cases, " +
199+
"such as when there is a configuration issue or network failure during the creation of the watcher object")
200+
}
201+
return w, nil
193202
}
194203

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

0 commit comments

Comments
 (0)