Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit event when robot server name and node name mismatch #773

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading