Skip to content

Commit

Permalink
feat: emit event when robot server name and node name mismatch (#773)
Browse files Browse the repository at this point in the history
When the Robot server name is changed in the Robot console or via the
API the node might be deleted by the node-lifecycle-manager. We now emit
a warning event for this case.

---------

Co-authored-by: Julian Tölle <[email protected]>
  • Loading branch information
lukasmetzner and apricote authored Oct 31, 2024
1 parent dfc77b2 commit 7960ddc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hcloud/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 11 additions & 3 deletions hcloud/instances_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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 %q differs from Robot name %q",
node.ObjectMeta.Name,
server.Name,
)
return nil, nil
}

Expand Down

0 comments on commit 7960ddc

Please sign in to comment.