@@ -23,6 +23,7 @@ import (
23
23
"net"
24
24
goruntime "runtime"
25
25
"strings"
26
+ "sync"
26
27
"time"
27
28
28
29
cadvisorapiv1 "github.com/google/cadvisor/info/v1"
@@ -57,6 +58,9 @@ const (
57
58
// Setters may partially mutate the node before returning an error.
58
59
type Setter func (ctx context.Context , node * v1.Node ) error
59
60
61
+ // Only emit one reboot event
62
+ var rebootEvent sync.Once
63
+
60
64
// NodeAddress returns a Setter that updates address-related information on the node.
61
65
func NodeAddress (nodeIPs []net.IP , // typically Kubelet.nodeIPs
62
66
validateNodeIPFunc func (net.IP ) error , // typically Kubelet.nodeIPValidator
@@ -250,6 +254,7 @@ func hasAddressType(addresses []v1.NodeAddress, addressType v1.NodeAddressType)
250
254
}
251
255
return false
252
256
}
257
+
253
258
func hasAddressValue (addresses []v1.NodeAddress , addressValue string ) bool {
254
259
for _ , address := range addresses {
255
260
if address .Address == addressValue {
@@ -311,8 +316,12 @@ func MachineInfo(nodeName string,
311
316
node .Status .NodeInfo .BootID != info .BootID {
312
317
// TODO: This requires a transaction, either both node status is updated
313
318
// and event is recorded or neither should happen, see issue #6055.
314
- recordEventFunc (v1 .EventTypeWarning , events .NodeRebooted ,
315
- fmt .Sprintf ("Node %s has been rebooted, boot id: %s" , nodeName , info .BootID ))
319
+ //
320
+ // Only emit one reboot event. recordEventFunc queues events and can emit many superfluous reboot events
321
+ rebootEvent .Do (func () {
322
+ recordEventFunc (v1 .EventTypeWarning , events .NodeRebooted ,
323
+ fmt .Sprintf ("Node %s has been rebooted, boot id: %s" , nodeName , info .BootID ))
324
+ })
316
325
}
317
326
node .Status .NodeInfo .BootID = info .BootID
318
327
0 commit comments