Skip to content

Commit 09008c8

Browse files
authored
Fix polling node when it is not ready and monitor by hostname (#22666)
1 parent 5038ccf commit 09008c8

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
537537
- Added Kafka version 2.2 to the list of supported versions. {pull}22328[22328]
538538
- Add support for ephemeral containers in kubernetes autodiscover and `add_kubernetes_metadata`. {pull}22389[22389] {pull}22439[22439]
539539
- Added support for wildcard fields and keyword fallback in beats setup commands. {pull}22521[22521]
540+
- Fix polling node when it is not ready and monitor by hostname {pull}22666[22666]
540541

541542
*Auditbeat*
542543

libbeat/autodiscover/providers/kubernetes/node.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ func (n *node) emit(node *kubernetes.Node, flag string) {
168168
return
169169
}
170170

171+
// If the node is not in ready state then dont monitor it unless its a stop event
172+
if !isNodeReady(node) && flag != "stop" {
173+
return
174+
}
175+
171176
eventID := fmt.Sprint(node.GetObjectMeta().GetUID())
172177
meta := n.metagen.Generate(node)
173178

@@ -237,6 +242,12 @@ func getAddress(node *kubernetes.Node) string {
237242
}
238243
}
239244

245+
for _, address := range node.Status.Addresses {
246+
if address.Type == v1.NodeHostName && address.Address != "" {
247+
return address.Address
248+
}
249+
}
250+
240251
return ""
241252
}
242253

libbeat/autodiscover/providers/kubernetes/node_test.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ func TestEmitEvent_Node(t *testing.T) {
156156
Address: "node1",
157157
},
158158
},
159+
Conditions: []v1.NodeCondition{
160+
{
161+
Type: v1.NodeReady,
162+
Status: v1.ConditionTrue,
163+
},
164+
},
159165
},
160166
},
161167
Expected: bus.Event{
@@ -183,6 +189,57 @@ func TestEmitEvent_Node(t *testing.T) {
183189
"config": []*common.Config{},
184190
},
185191
},
192+
{
193+
Message: "Test node start with just node name",
194+
Flag: "start",
195+
Node: &kubernetes.Node{
196+
ObjectMeta: metav1.ObjectMeta{
197+
Name: name,
198+
UID: types.UID(uid),
199+
Labels: map[string]string{},
200+
Annotations: map[string]string{},
201+
},
202+
TypeMeta: typeMeta,
203+
Status: v1.NodeStatus{
204+
Addresses: []v1.NodeAddress{
205+
{
206+
Type: v1.NodeHostName,
207+
Address: "node1",
208+
},
209+
},
210+
Conditions: []v1.NodeCondition{
211+
{
212+
Type: v1.NodeReady,
213+
Status: v1.ConditionTrue,
214+
},
215+
},
216+
},
217+
},
218+
Expected: bus.Event{
219+
"start": true,
220+
"host": "node1",
221+
"id": uid,
222+
"provider": UUID,
223+
"kubernetes": common.MapStr{
224+
"node": common.MapStr{
225+
"name": "metricbeat",
226+
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
227+
"hostname": "node1",
228+
},
229+
"annotations": common.MapStr{},
230+
},
231+
"meta": common.MapStr{
232+
"kubernetes": common.MapStr{
233+
"node": common.MapStr{
234+
"name": "metricbeat",
235+
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
236+
"hostname": "node1",
237+
},
238+
},
239+
},
240+
"config": []*common.Config{},
241+
},
242+
},
186243
{
187244
Message: "Test service without host",
188245
Flag: "start",
@@ -221,7 +278,7 @@ func TestEmitEvent_Node(t *testing.T) {
221278
},
222279
Expected: bus.Event{
223280
"stop": true,
224-
"host": "",
281+
"host": "node1",
225282
"id": uid,
226283
"provider": UUID,
227284
"kubernetes": common.MapStr{

0 commit comments

Comments
 (0)