Skip to content

Commit

Permalink
Use NamedWatcher in Agent's k8s provider (#29095)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrsMark authored Nov 24, 2021
1 parent 606a7d2 commit db5de27
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions libbeat/common/kubernetes/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ func NewWatcher(client kubernetes.Interface, resource Resource, opts WatchOption
return NewNamedWatcher("", client, resource, opts, indexers)
}

// NewNamedWatcher does the same as NewWatcher, but also allows to name the k8s
// client's workqueue that is used by the watcher, unlike NewWatcher which sets
// the workqueue name to "". Workqueue name is important for exposing workqueue
// NewNamedWatcher initializes the watcher client to provide an events handler for
// resource from the cluster (filtered to the given node) and also allows to name the k8s
// client's workqueue that is used by the watcher. Workqueue name is important for exposing workqueue
// metrics, if it is empty, its metrics will not be logged by the k8s client.
func NewNamedWatcher(name string, client kubernetes.Interface, resource Resource, opts WatchOptions, indexers cache.Indexers) (Watcher, error) {
var store cache.Store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewNodeEventer(
logger *logp.Logger,
client k8s.Interface,
scope string) (Eventer, error) {
watcher, err := kubernetes.NewWatcher(client, &kubernetes.Node{}, kubernetes.WatchOptions{
watcher, err := kubernetes.NewNamedWatcher("agent-node", client, &kubernetes.Node{}, kubernetes.WatchOptions{
SyncTimeout: cfg.SyncPeriod,
Node: cfg.Node,
IsUpdated: isUpdated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewPodEventer(
logger *logp.Logger,
client k8s.Interface,
scope string) (Eventer, error) {
watcher, err := kubernetes.NewWatcher(client, &kubernetes.Pod{}, kubernetes.WatchOptions{
watcher, err := kubernetes.NewNamedWatcher("agent-pod", client, &kubernetes.Pod{}, kubernetes.WatchOptions{
SyncTimeout: cfg.SyncPeriod,
Node: cfg.Node,
Namespace: cfg.Namespace,
Expand All @@ -92,11 +92,11 @@ func NewPodEventer(
if metaConf == nil {
metaConf = metadata.GetDefaultResourceMetadataConfig()
}
nodeWatcher, err := kubernetes.NewWatcher(client, &kubernetes.Node{}, options, nil)
nodeWatcher, err := kubernetes.NewNamedWatcher("agent-node", client, &kubernetes.Node{}, options, nil)
if err != nil {
logger.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Node{}, err)
}
namespaceWatcher, err := kubernetes.NewWatcher(client, &kubernetes.Namespace{}, kubernetes.WatchOptions{
namespaceWatcher, err := kubernetes.NewNamedWatcher("agent-namespace", client, &kubernetes.Namespace{}, kubernetes.WatchOptions{
SyncTimeout: cfg.SyncPeriod,
}, nil)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewServiceEventer(
logger *logp.Logger,
client k8s.Interface,
scope string) (Eventer, error) {
watcher, err := kubernetes.NewWatcher(client, &kubernetes.Service{}, kubernetes.WatchOptions{
watcher, err := kubernetes.NewNamedWatcher("agent-service", client, &kubernetes.Service{}, kubernetes.WatchOptions{
SyncTimeout: cfg.SyncPeriod,
Node: cfg.Node,
HonorReSyncs: true,
Expand All @@ -54,7 +54,7 @@ func NewServiceEventer(
}

metaConf := metadata.GetDefaultResourceMetadataConfig()
namespaceWatcher, err := kubernetes.NewWatcher(client, &kubernetes.Namespace{}, kubernetes.WatchOptions{
namespaceWatcher, err := kubernetes.NewNamedWatcher("agent-namespace", client, &kubernetes.Namespace{}, kubernetes.WatchOptions{
SyncTimeout: cfg.SyncPeriod,
Namespace: cfg.Namespace,
}, nil)
Expand Down

0 comments on commit db5de27

Please sign in to comment.