Skip to content

Commit

Permalink
feat: emit event when robot server name and node name mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmetzner committed Oct 31, 2024
1 parent e6c0356 commit a8e9cbd
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 @@ -73,14 +73,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 @@ -91,6 +91,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
}

Expand Down

0 comments on commit a8e9cbd

Please sign in to comment.