diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index c94dc62b826..6cf5d840158 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -537,6 +537,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Added Kafka version 2.2 to the list of supported versions. {pull}22328[22328] - Add support for ephemeral containers in kubernetes autodiscover and `add_kubernetes_metadata`. {pull}22389[22389] {pull}22439[22439] - Added support for wildcard fields and keyword fallback in beats setup commands. {pull}22521[22521] +- Fix polling node when it is not ready and monitor by hostname {pull}22666[22666] *Auditbeat* diff --git a/libbeat/autodiscover/providers/kubernetes/node.go b/libbeat/autodiscover/providers/kubernetes/node.go index 95e23b33d2a..0f37ade6b5a 100644 --- a/libbeat/autodiscover/providers/kubernetes/node.go +++ b/libbeat/autodiscover/providers/kubernetes/node.go @@ -168,6 +168,11 @@ func (n *node) emit(node *kubernetes.Node, flag string) { return } + // If the node is not in ready state then dont monitor it unless its a stop event + if !isNodeReady(node) && flag != "stop" { + return + } + eventID := fmt.Sprint(node.GetObjectMeta().GetUID()) meta := n.metagen.Generate(node) @@ -237,6 +242,12 @@ func getAddress(node *kubernetes.Node) string { } } + for _, address := range node.Status.Addresses { + if address.Type == v1.NodeHostName && address.Address != "" { + return address.Address + } + } + return "" } diff --git a/libbeat/autodiscover/providers/kubernetes/node_test.go b/libbeat/autodiscover/providers/kubernetes/node_test.go index 518a0121578..6eb22b185e1 100644 --- a/libbeat/autodiscover/providers/kubernetes/node_test.go +++ b/libbeat/autodiscover/providers/kubernetes/node_test.go @@ -156,6 +156,12 @@ func TestEmitEvent_Node(t *testing.T) { Address: "node1", }, }, + Conditions: []v1.NodeCondition{ + { + Type: v1.NodeReady, + Status: v1.ConditionTrue, + }, + }, }, }, Expected: bus.Event{ @@ -183,6 +189,57 @@ func TestEmitEvent_Node(t *testing.T) { "config": []*common.Config{}, }, }, + { + Message: "Test node start with just node name", + Flag: "start", + Node: &kubernetes.Node{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + UID: types.UID(uid), + Labels: map[string]string{}, + Annotations: map[string]string{}, + }, + TypeMeta: typeMeta, + Status: v1.NodeStatus{ + Addresses: []v1.NodeAddress{ + { + Type: v1.NodeHostName, + Address: "node1", + }, + }, + Conditions: []v1.NodeCondition{ + { + Type: v1.NodeReady, + Status: v1.ConditionTrue, + }, + }, + }, + }, + Expected: bus.Event{ + "start": true, + "host": "node1", + "id": uid, + "provider": UUID, + "kubernetes": common.MapStr{ + "node": common.MapStr{ + "name": "metricbeat", + "uid": "005f3b90-4b9d-12f8-acf0-31020a840133", + "hostname": "node1", + }, + "annotations": common.MapStr{}, + }, + "meta": common.MapStr{ + "kubernetes": common.MapStr{ + "node": common.MapStr{ + "name": "metricbeat", + "uid": "005f3b90-4b9d-12f8-acf0-31020a840133", + "hostname": "node1", + }, + }, + }, + "config": []*common.Config{}, + }, + }, { Message: "Test service without host", Flag: "start", @@ -221,7 +278,7 @@ func TestEmitEvent_Node(t *testing.T) { }, Expected: bus.Event{ "stop": true, - "host": "", + "host": "node1", "id": uid, "provider": UUID, "kubernetes": common.MapStr{