From a3bdb177e250581f973c54f1feb0a4f4d584b5f2 Mon Sep 17 00:00:00 2001 From: lukasmetzner Date: Thu, 31 Oct 2024 10:21:07 +0100 Subject: [PATCH 1/2] feat: emit event when robot server name and node name mismatch --- hcloud/instances.go | 2 +- hcloud/instances_util.go | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/hcloud/instances.go b/hcloud/instances.go index fa32023d..355cc31b 100644 --- a/hcloud/instances.go +++ b/hcloud/instances.go @@ -85,7 +85,7 @@ func (i *instances) lookupServer( if i.robotClient == nil { return nil, errMissingRobotClient } - server, err := getRobotServerByID(i.robotClient, int(serverID), node) + server, err := getRobotServerByID(i, int(serverID), node) if err != nil { return nil, fmt.Errorf("failed to get robot server \"%d\": %w", serverID, err) } diff --git a/hcloud/instances_util.go b/hcloud/instances_util.go index def5cf28..e5111aec 100644 --- a/hcloud/instances_util.go +++ b/hcloud/instances_util.go @@ -74,14 +74,14 @@ func getRobotServerByName(c robot.Client, node *corev1.Node) (server *hrobotmode return server, nil } -func getRobotServerByID(c robot.Client, id int, node *corev1.Node) (*hrobotmodels.Server, error) { +func getRobotServerByID(i *instances, id int, node *corev1.Node) (*hrobotmodels.Server, error) { const op = "hcloud/getRobotServerByID" - if c == nil { + if i.robotClient == nil { return nil, errMissingRobotClient } - server, err := c.ServerGet(id) + server, err := i.robotClient.ServerGet(id) if err != nil && !hrobotmodels.IsError(err, hrobotmodels.ErrorCodeServerNotFound) { return nil, fmt.Errorf("%s: %w", op, err) } @@ -92,6 +92,14 @@ func getRobotServerByID(c robot.Client, id int, node *corev1.Node) (*hrobotmodel // check whether name matches - otherwise this server does not belong to the respective node anymore if server.Name != node.Name { + i.recorder.Eventf( + node, + corev1.EventTypeWarning, + "PossibleNodeDeletion", + "Might be deleted by node-lifecycle-manager due to name mismatch; Node name \"%s\" differs from Robot name \"%s\"", + node.ObjectMeta.Name, + server.Name, + ) return nil, nil } From 9c81c2b2720f60f4ef340b53b9b8d2039282a551 Mon Sep 17 00:00:00 2001 From: Lukas Metzner Date: Thu, 31 Oct 2024 10:47:56 +0100 Subject: [PATCH 2/2] Update hcloud/instances_util.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Julian Tölle --- hcloud/instances_util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hcloud/instances_util.go b/hcloud/instances_util.go index e5111aec..b643e610 100644 --- a/hcloud/instances_util.go +++ b/hcloud/instances_util.go @@ -96,7 +96,7 @@ func getRobotServerByID(i *instances, id int, node *corev1.Node) (*hrobotmodels. node, corev1.EventTypeWarning, "PossibleNodeDeletion", - "Might be deleted by node-lifecycle-manager due to name mismatch; Node name \"%s\" differs from Robot name \"%s\"", + "Might be deleted by node-lifecycle-manager due to name mismatch; Node name %q differs from Robot name %q", node.ObjectMeta.Name, server.Name, )