@@ -25,16 +25,24 @@ import (
2525
2626 "github.com/elastic/beats/libbeat/autodiscover/template"
2727 "github.com/elastic/beats/libbeat/common"
28+ "github.com/elastic/beats/libbeat/common/cfgwarn"
29+ "github.com/elastic/beats/libbeat/logp"
2830)
2931
3032// Config for kubernetes autodiscover provider
3133type Config struct {
3234 KubeConfig string `config:"kube_config"`
33- Host string `config:"host"`
3435 Namespace string `config:"namespace"`
3536 SyncPeriod time.Duration `config:"sync_period"`
3637 CleanupTimeout time.Duration `config:"cleanup_timeout" validate:"positive"`
3738
39+ // Needed when resource is a pod
40+ HostDeprecated string `config:"host"`
41+ Node string `config:"node"`
42+ // Scope can be either node or cluster.
43+ Scope string `config:"scope"`
44+ Resource string `config:"resource"`
45+
3846 Prefix string `config:"prefix"`
3947 Hints * common.Config `config:"hints"`
4048 Builders []* common.Config `config:"builders"`
@@ -45,6 +53,7 @@ type Config struct {
4553func defaultConfig () * Config {
4654 return & Config {
4755 SyncPeriod : 10 * time .Minute ,
56+ Resource : "pod" ,
4857 CleanupTimeout : 60 * time .Second ,
4958 Prefix : "co.elastic" ,
5059 }
@@ -61,5 +70,30 @@ func (c *Config) Validate() error {
6170 return fmt .Errorf ("no configs or hints defined for autodiscover provider" )
6271 }
6372
73+ // Check if host is being defined and change it to node instead.
74+ if c .Node == "" && c .HostDeprecated != "" {
75+ c .Node = c .HostDeprecated
76+ cfgwarn .Deprecate ("8.0" , "`host` will be deprecated, use `node` instead" )
77+ }
78+
79+ // Check if resource is either node or pod. If yes then default the scope to "node" if not provided.
80+ // Default the scope to "cluster" for everything else.
81+ switch c .Resource {
82+ case "node" , "pod" :
83+ if c .Scope == "" {
84+ c .Scope = "node"
85+ }
86+
87+ default :
88+ if c .Scope == "node" {
89+ logp .L ().Warnf ("can not set scope to `node` when using resource %s. resetting scope to `cluster`" , c .Resource )
90+ }
91+ c .Scope = "cluster"
92+ }
93+
94+ if c .Scope != "node" && c .Scope != "cluster" {
95+ return fmt .Errorf ("invalid `scope` configured. supported values are `node` and `cluster`" )
96+ }
97+
6498 return nil
6599}
0 commit comments