From 5fa788e8242dd81aefe27c1b360bf8302e41bd1e Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Fri, 6 Mar 2020 08:39:54 -0500 Subject: [PATCH] Fix NewContainerMetadataEnricher to use default config for kubernetes module. (#16857) * Fix code to use default config for resource metadata. * Add changelog entry. (cherry picked from commit 5c3891277f3a1fc76342125df79b5e081c47f72e) --- CHANGELOG.next.asciidoc | 1 + libbeat/common/kubernetes/metadata/config.go | 11 +++++------ libbeat/common/kubernetes/metadata/resource.go | 2 +- libbeat/common/kubernetes/metadata/resource_test.go | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 585d7eddb56..2d0bff7d42a 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -83,6 +83,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Fix k8s pods annotations broken schema. {pull}16554[16554] - Upgrade go-ucfg to latest v0.8.3. {pull}16450{16450} - Add `ssl.ca_sha256` option to the supported TLS option, this allow to check that a specific certificate is used as part of the verified chain. {issue}15717[15717] +- Fix `NewContainerMetadataEnricher` to use default config for kubernetes module. {pull}16857[16857] *Auditbeat* diff --git a/libbeat/common/kubernetes/metadata/config.go b/libbeat/common/kubernetes/metadata/config.go index 3d3a028d13c..bbded35bf01 100644 --- a/libbeat/common/kubernetes/metadata/config.go +++ b/libbeat/common/kubernetes/metadata/config.go @@ -38,12 +38,11 @@ type AddResourceMetadataConfig struct { Namespace *common.Config `config:"namespace"` } -func defaultConfig() Config { - return Config{ - IncludeCreatorMetadata: true, - LabelsDedot: true, - AnnotationsDedot: true, - } +// InitDefaults initializes the defaults for the config. +func (c *Config) InitDefaults() { + c.IncludeCreatorMetadata = true + c.LabelsDedot = true + c.AnnotationsDedot = true } // Unmarshal unpacks a Config into the metagen Config diff --git a/libbeat/common/kubernetes/metadata/resource.go b/libbeat/common/kubernetes/metadata/resource.go index d9610a32f37..e4f4b8ca028 100644 --- a/libbeat/common/kubernetes/metadata/resource.go +++ b/libbeat/common/kubernetes/metadata/resource.go @@ -34,7 +34,7 @@ type Resource struct { // NewResourceMetadataGenerator creates a metadata generator for a generic resource func NewResourceMetadataGenerator(cfg *common.Config) *Resource { - config := defaultConfig() + var config Config config.Unmarshal(cfg) return &Resource{ diff --git a/libbeat/common/kubernetes/metadata/resource_test.go b/libbeat/common/kubernetes/metadata/resource_test.go index 01e7280a4f5..6df542742f0 100644 --- a/libbeat/common/kubernetes/metadata/resource_test.go +++ b/libbeat/common/kubernetes/metadata/resource_test.go @@ -25,6 +25,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "github.com/elastic/go-ucfg" + "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/libbeat/common/kubernetes" ) @@ -109,7 +111,8 @@ func TestResource_Generate(t *testing.T) { }, } - cfg := defaultConfig() + var cfg Config + ucfg.New().Unpack(&cfg) metagen := &Resource{ config: &cfg, }