Skip to content
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

Remove hard-coded namespace from k8s config #5482

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Do not require template if index change and template disabled {pull}5319[5319]
- Correctly send configured `Host` header to the remote server. {issue}4842[4842]
- Fix missing ACK in redis output. {issue}5404[5404]
- Change add_kubernetes_metadata to attempt detection of namespace. {pull}5482[5482]

*Auditbeat*

Expand Down
3 changes: 1 addition & 2 deletions libbeat/processors/add_kubernetes_metadata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ type Enabled struct {

type PluginConfig []map[string]common.Config

func defaultKuberentesAnnotatorConfig() kubeAnnotatorConfig {
func defaultKubernetesAnnotatorConfig() kubeAnnotatorConfig {
return kubeAnnotatorConfig{
InCluster: true,
SyncPeriod: 1 * time.Second,
CleanupTimeout: 60 * time.Second,
Namespace: "kube-system",
Copy link
Contributor

@exekias exekias Oct 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best if we remove Namespace field from kubeAnnotatorConfig, and move all references to client.Namespace

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I considered doing that initially as well. Will adjust now!

DefaultMatchers: Enabled{true},
DefaultIndexers: Enabled{true},
}
Expand Down
8 changes: 4 additions & 4 deletions libbeat/processors/add_kubernetes_metadata/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {
func newKubernetesAnnotator(cfg *common.Config) (processors.Processor, error) {
cfgwarn.Beta("The kubernetes processor is beta")

config := defaultKuberentesAnnotatorConfig()
config := defaultKubernetesAnnotatorConfig()

err := cfg.Unpack(&config)
if err != nil {
Expand Down Expand Up @@ -87,7 +87,7 @@ func newKubernetesAnnotator(cfg *common.Config) (processors.Processor, error) {
if config.InCluster == true {
client, err = k8s.NewInClusterClient()
if err != nil {
return nil, fmt.Errorf("Unable to get in cluster configuration")
return nil, fmt.Errorf("Unable to get in cluster configuration: %v", err)
}
} else {
data, err := ioutil.ReadFile(config.KubeConfig)
Expand All @@ -109,11 +109,11 @@ func newKubernetesAnnotator(cfg *common.Config) (processors.Processor, error) {
ctx := context.Background()
if config.Host == "" {
podName := os.Getenv("HOSTNAME")
logp.Info("Using pod name %s and namespace %s", podName, config.Namespace)
logp.Info("Using pod name %s and namespace %s", podName, client.Namespace)
if podName == "localhost" {
config.Host = "localhost"
} else {
pod, error := client.CoreV1().GetPod(ctx, podName, config.Namespace)
pod, error := client.CoreV1().GetPod(ctx, podName, client.Namespace)
if error != nil {
logp.Err("Querying for pod failed with error: ", error.Error())
logp.Info("Unable to find pod, setting host to localhost")
Expand Down