diff --git a/kubernetes/metadata/namespace.go b/kubernetes/metadata/namespace.go index 2e63cbc66..01302f713 100644 --- a/kubernetes/metadata/namespace.go +++ b/kubernetes/metadata/namespace.go @@ -43,10 +43,12 @@ func NewNamespaceMetadataGenerator(cfg *config.C, namespaces cache.Store, client // Generate generates pod metadata from a resource object // Metadata map is in the following form: -// { -// "kubernetes": {}, -// "some.ecs.field": "asdf" -// } +// +// { +// "kubernetes": {}, +// "some.ecs.field": "asdf" +// } +// // All Kubernetes fields that need to be stored under kuberentes. prefix are populetad by // GenerateK8s method while fields that are part of ECS are generated by GenerateECS method func (n *namespace) Generate(obj kubernetes.Resource, opts ...FieldOptions) mapstr.M { diff --git a/kubernetes/metadata/node.go b/kubernetes/metadata/node.go index 69d408c91..1b8184162 100644 --- a/kubernetes/metadata/node.go +++ b/kubernetes/metadata/node.go @@ -42,10 +42,12 @@ func NewNodeMetadataGenerator(cfg *config.C, nodes cache.Store, client k8s.Inter // Generate generates node metadata from a resource object // Metadata map is in the following form: -// { -// "kubernetes": {}, -// "some.ecs.field": "asdf" -// } +// +// { +// "kubernetes": {}, +// "some.ecs.field": "asdf" +// } +// // All Kubernetes fields that need to be stored under kuberentes. prefix are populetad by // GenerateK8s method while fields that are part of ECS are generated by GenerateECS method func (n *node) Generate(obj kubernetes.Resource, opts ...FieldOptions) mapstr.M { diff --git a/kubernetes/util.go b/kubernetes/util.go index 3bd2fe2d5..040ce9348 100644 --- a/kubernetes/util.go +++ b/kubernetes/util.go @@ -21,7 +21,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "os" "strings" @@ -200,7 +199,7 @@ func (hd *DefaultDiscoveryUtils) GetMachineID() string { "/etc/machine-id", "/var/lib/dbus/machine-id", } { - id, err := ioutil.ReadFile(file) + id, err := os.ReadFile(file) if err == nil { return strings.TrimSpace(string(id)) } @@ -221,7 +220,7 @@ func (hd *DefaultDiscoveryUtils) GetPodName() (string, error) { // InClusterNamespace gets namespace from serviceaccount when beat is in cluster. // code borrowed from client-go with some changes. func InClusterNamespace() (string, error) { // get namespace associated with the service account token, if available - data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") + data, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace") if err != nil { return "", err } diff --git a/kubernetes/watcher.go b/kubernetes/watcher.go index 9b02c93f2..8090d97d8 100644 --- a/kubernetes/watcher.go +++ b/kubernetes/watcher.go @@ -145,7 +145,7 @@ func NewNamedWatcher(name string, client kubernetes.Interface, resource Resource handler: NoOpEventHandlerFuncs{}, } - w.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ + _, err = w.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(o interface{}) { w.enqueue(o, add) }, @@ -175,6 +175,9 @@ func NewNamedWatcher(name string, client kubernetes.Interface, resource Resource } }, }) + if err != nil { + return nil, err + } return w, nil }