Nodelifecycle: Emit event when deletion failed

The nodelifecycle controller emits an event before it deletes a node.
Failures doing so for example due to a webhook are pretty hidden though,
as they are only logged in the controller-manager.

This change makes us emit an event for failing to delete a node
including the error as well.
This commit is contained in:
Alvaro Aleman 2024-03-09 11:51:36 -05:00
parent d3d06c3c7e
commit b2eb6e7d03

View File

@ -42,7 +42,8 @@ import (
)
const (
deleteNodeEvent = "DeletingNode"
deleteNodeEvent = "DeletingNode"
deleteNodeFailedEvent = "DeletingNodeFailed"
)
var ShutdownTaint = &v1.Taint{
@ -175,6 +176,8 @@ func (c *CloudNodeLifecycleController) MonitorNodes(ctx context.Context) {
if err := c.kubeClient.CoreV1().Nodes().Delete(ctx, node.Name, metav1.DeleteOptions{}); err != nil {
klog.Errorf("unable to delete node %q: %v", node.Name, err)
c.recorder.Eventf(ref, v1.EventTypeWarning, deleteNodeFailedEvent,
"Failed deleting node %s: %v", node.Name, err)
}
} else {
// Node exists. We need to check this to get taint working in similar in all cloudproviders