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

Fix NewContainerMetadataEnricher to use default config for kubernetes module. #16857

Merged
merged 2 commits into from
Mar 6, 2020
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.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

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