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 polling node when it is not ready and monitor by hostname #22666

Merged
merged 3 commits into from
Dec 1, 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 @@ -536,6 +536,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*

Expand Down
11 changes: 11 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


return ""
}

Expand Down
59 changes: 58 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ func TestEmitEvent_Node(t *testing.T) {
Address: "node1",
},
},
Conditions: []v1.NodeCondition{
{
Type: v1.NodeReady,
Status: v1.ConditionTrue,
},
},
},
},
Expected: bus.Event{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand Down