Skip to content

Commit 5d3c07e

Browse files
committed
kubelet: only emit one reboot event
There are cases when the kubelet is starting where networking, or other components can cause the kubelet to not post the status with the bootId. The failed status update will cause the Kubelet to queue the NodeRebooted warning and sometimes cause many events to be created. This fix wraps the recordEventFunc to only emit one message per kubelet instantiation.
1 parent 8a39b60 commit 5d3c07e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/kubelet/nodestatus/setters.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net"
2424
goruntime "runtime"
2525
"strings"
26+
"sync"
2627
"time"
2728

2829
cadvisorapiv1 "github.com/google/cadvisor/info/v1"
@@ -57,6 +58,9 @@ const (
5758
// Setters may partially mutate the node before returning an error.
5859
type Setter func(ctx context.Context, node *v1.Node) error
5960

61+
// Only emit one reboot event
62+
var rebootEvent sync.Once
63+
6064
// NodeAddress returns a Setter that updates address-related information on the node.
6165
func NodeAddress(nodeIPs []net.IP, // typically Kubelet.nodeIPs
6266
validateNodeIPFunc func(net.IP) error, // typically Kubelet.nodeIPValidator
@@ -250,6 +254,7 @@ func hasAddressType(addresses []v1.NodeAddress, addressType v1.NodeAddressType)
250254
}
251255
return false
252256
}
257+
253258
func hasAddressValue(addresses []v1.NodeAddress, addressValue string) bool {
254259
for _, address := range addresses {
255260
if address.Address == addressValue {
@@ -311,8 +316,12 @@ func MachineInfo(nodeName string,
311316
node.Status.NodeInfo.BootID != info.BootID {
312317
// TODO: This requires a transaction, either both node status is updated
313318
// 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+
})
316325
}
317326
node.Status.NodeInfo.BootID = info.BootID
318327

0 commit comments

Comments
 (0)