...
1 package kclient
2
3 import (
4 "context"
5
6 kerrors "k8s.io/apimachinery/pkg/api/errors"
7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8 "k8s.io/apimachinery/pkg/watch"
9 )
10
11 type NoOpWatch struct{}
12
13 func (o NoOpWatch) Stop() {}
14
15 func (o NoOpWatch) ResultChan() <-chan watch.Event {
16 return make(chan watch.Event)
17 }
18
19
20
21 func (c *Client) PodWarningEventWatcher(ctx context.Context) (result watch.Interface, isForbidden bool, err error) {
22 selector := "involvedObject.kind=Pod,involvedObject.apiVersion=v1,type=Warning"
23 ns := c.GetCurrentNamespace()
24 result, err = c.GetClient().CoreV1().Events(ns).
25 Watch(ctx, metav1.ListOptions{
26 FieldSelector: selector,
27 })
28
29 if err != nil {
30 if kerrors.IsForbidden(err) {
31 return NoOpWatch{}, true, nil
32 }
33 return nil, false, err
34 }
35 return result, false, nil
36 }
37
View as plain text