From 5c3891277f3a1fc76342125df79b5e081c47f72e 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. --- 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 17f9dde6567..da3ddf7fe46 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -65,6 +65,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Fix k8s pods labels broken schema. {pull}16480[16480] - Fix k8s pods annotations broken schema. {pull}16554[16554] - Upgrade go-ucfg to latest v0.8.3. {pull}16450{16450} +- 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, }