Skip to content

Commit

Permalink
Fix NewContainerMetadataEnricher to use default config for kubernetes…
Browse files Browse the repository at this point in the history
… module. (elastic#16857)

* Fix code to use default config for resource metadata.

* Add changelog entry.

(cherry picked from commit 5c38912)
  • Loading branch information
blakerouse committed Mar 6, 2020
1 parent 57ed05a commit 5fa788e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
11 changes: 5 additions & 6 deletions libbeat/common/kubernetes/metadata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libbeat/common/kubernetes/metadata/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 4 additions & 1 deletion libbeat/common/kubernetes/metadata/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -109,7 +111,8 @@ func TestResource_Generate(t *testing.T) {
},
}

cfg := defaultConfig()
var cfg Config
ucfg.New().Unpack(&cfg)
metagen := &Resource{
config: &cfg,
}
Expand Down

0 comments on commit 5fa788e

Please sign in to comment.