diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 52634fb2458..0d86377d89b 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, }