-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor kubernetes autodiscover to enable different resource based discovery #14738
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0caf06b
Refactor kubernetes autodiscover to enable different resource based d…
vjsamuel 9276832
Add scope variable to ensure that metricbeat can be run cluster wide
vjsamuel c9b37f4
Add support for node level discovery
vjsamuel f435850
Add service autodiscover and fix metadata for node autodiscover
vjsamuel 090a881
Add test cases for node and service autodiscover
vjsamuel 228348f
Make node as the configuration to pin to a kube node
vjsamuel a911a01
Update docs with scope and resource configurations for kube autodiscover
vjsamuel c636e80
Incorporating review comments
vjsamuel f99f54c
change deploy manifests to use node
vjsamuel 2ad6ef9
Add changelog
vjsamuel e043a08
Update libbeat/docs/shared-autodiscover.asciidoc
vjsamuel 25154d4
Make hound happy
vjsamuel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,16 +25,24 @@ import ( | |
|
||
"github.com/elastic/beats/libbeat/autodiscover/template" | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/common/cfgwarn" | ||
"github.com/elastic/beats/libbeat/logp" | ||
) | ||
|
||
// Config for kubernetes autodiscover provider | ||
type Config struct { | ||
KubeConfig string `config:"kube_config"` | ||
Host string `config:"host"` | ||
Namespace string `config:"namespace"` | ||
SyncPeriod time.Duration `config:"sync_period"` | ||
CleanupTimeout time.Duration `config:"cleanup_timeout" validate:"positive"` | ||
|
||
// Needed when resource is a pod | ||
HostDeprecated string `config:"host"` | ||
Node string `config:"node"` | ||
// Scope can be either node or cluster. | ||
Scope string `config:"scope"` | ||
Resource string `config:"resource"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. both scope and resource are new, could you update the docs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated docs. |
||
|
||
Prefix string `config:"prefix"` | ||
Hints *common.Config `config:"hints"` | ||
Builders []*common.Config `config:"builders"` | ||
|
@@ -45,6 +53,7 @@ type Config struct { | |
func defaultConfig() *Config { | ||
return &Config{ | ||
SyncPeriod: 10 * time.Minute, | ||
Resource: "pod", | ||
CleanupTimeout: 60 * time.Second, | ||
Prefix: "co.elastic", | ||
} | ||
|
@@ -61,5 +70,30 @@ func (c *Config) Validate() error { | |
return fmt.Errorf("no configs or hints defined for autodiscover provider") | ||
} | ||
|
||
// Check if host is being defined and change it to node instead. | ||
if c.Node == "" && c.HostDeprecated != "" { | ||
c.Node = c.HostDeprecated | ||
cfgwarn.Deprecate("8.0", "`host` will be deprecated, use `node` instead") | ||
} | ||
|
||
// Check if resource is either node or pod. If yes then default the scope to "node" if not provided. | ||
// Default the scope to "cluster" for everything else. | ||
switch c.Resource { | ||
case "node", "pod": | ||
if c.Scope == "" { | ||
c.Scope = "node" | ||
} | ||
|
||
default: | ||
if c.Scope == "node" { | ||
logp.L().Warnf("can not set scope to `node` when using resource %s. resetting scope to `cluster`", c.Resource) | ||
} | ||
c.Scope = "cluster" | ||
} | ||
|
||
if c.Scope != "node" && c.Scope != "cluster" { | ||
return fmt.Errorf("invalid `scope` configured. supported values are `node` and `cluster`") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would also solve #10578 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can happen in a different PR but I think we should extend this setting to
add_kubernetes_metadata
processor. I'm unsure about the other (resource
), probably not worth it until we see the need.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will create follow up PR