diff --git a/libbeat/processors/add_kubernetes_metadata/indexers.go b/libbeat/processors/add_kubernetes_metadata/indexers.go index f535253f151..e5db81cd6a0 100644 --- a/libbeat/processors/add_kubernetes_metadata/indexers.go +++ b/libbeat/processors/add_kubernetes_metadata/indexers.go @@ -142,7 +142,7 @@ func NewContainerIndexer(_ common.Config, metaGen kubernetes.MetaGenerator) (Ind func (c *ContainerIndexer) GetMetadata(pod *kubernetes.Pod) []MetadataIndex { var metadata []MetadataIndex for _, status := range append(pod.Status.ContainerStatuses, pod.Status.InitContainerStatuses...) { - cID := status.ContainerID + cID := status.GetContainerID() if cID == "" { continue } diff --git a/libbeat/processors/add_kubernetes_metadata/indexers_test.go b/libbeat/processors/add_kubernetes_metadata/indexers_test.go index 395f7e4b6ce..5e7741f7a73 100644 --- a/libbeat/processors/add_kubernetes_metadata/indexers_test.go +++ b/libbeat/processors/add_kubernetes_metadata/indexers_test.go @@ -28,7 +28,9 @@ func TestPodIndexer(t *testing.T) { "labelkey": "labelvalue", }, }, - Spec: kubernetes.PodSpec{}, + Spec: kubernetes.PodSpec{ + NodeName: "testnode", + }, } indexers := podIndexer.GetMetadata(&pod) @@ -43,6 +45,9 @@ func TestPodIndexer(t *testing.T) { "labels": common.MapStr{ "labelkey": "labelvalue", }, + "node": common.MapStr{ + "name": "testnode", + }, } assert.Equal(t, expected.String(), indexers[0].Data.String()) @@ -89,8 +94,11 @@ func TestContainerIndexer(t *testing.T) { "labels": common.MapStr{ "labelkey": "labelvalue", }, + "node": common.MapStr{ + "name": "testnode", + }, } - + pod.Spec.NodeName = "testnode" pod.Status.ContainerStatuses = []kubernetes.PodContainerStatus{ { Name: container, @@ -282,6 +290,9 @@ func TestIpPortIndexer(t *testing.T) { "labels": common.MapStr{ "labelkey": "labelvalue", }, + "node": common.MapStr{ + "name": "testnode", + }, } pod.Spec.Containers = []kubernetes.Container{ @@ -295,6 +306,7 @@ func TestIpPortIndexer(t *testing.T) { }, }, } + pod.Spec.NodeName = "testnode" indexers = ipIndexer.GetMetadata(&pod) assert.Equal(t, 2, len(indexers))