Skip to content

Commit

Permalink
Allow nodes to call register on startup, even if previously registered (
Browse files Browse the repository at this point in the history
#3672)

More gracefully handles registration flow for compute nodes that are
already registered. Allows for re-registration of nodes by removing the
sentinel file (if any)
  • Loading branch information
rossjones committed Mar 21, 2024
1 parent 050b873 commit 0948775
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 6 additions & 7 deletions pkg/compute/management_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ func (m *ManagementClient) getNodeInfo(ctx context.Context) models.NodeInfo {
})
}

// RegisterNode sends a registration request to the requester node iff
// we have not got evidence (a local sentinel file) that we have already
// registered. Should we fail to register, we will return an error and
// expect the caller to exit.
// RegisterNode sends a registration request to the requester node. If we successfully
// register, a sentinel file is created to indicate that we are registered. If present
// the requester node will know it is already registered. If not present, it will
// attempt to register again, expecting the requester node to gracefully handle any
// previous registrations.
func (m *ManagementClient) RegisterNode(ctx context.Context) error {
// We only want to register this node if we haven't already
// been registered.
if m.registrationFile.Exists() {
log.Ctx(ctx).Debug().Msg("not registering with requester, already registered")
return nil
Expand All @@ -82,10 +81,10 @@ func (m *ManagementClient) RegisterNode(ctx context.Context) error {
}

if response.Accepted {
log.Ctx(ctx).Debug().Msg("register request accepted")
if err := m.registrationFile.Set(); err != nil {
return errors.Wrap(err, "failed to record local registration status")
}
log.Ctx(ctx).Debug().Msg("register request accepted")
} else {
// Might be an error, or might be rejected because it is in a pending
// state instead
Expand Down
4 changes: 3 additions & 1 deletion pkg/node/manager/node_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ func (n *NodeManager) Register(ctx context.Context, request requests.RegisterReq
}, nil
}

// Otherwise we'll allow the registration, but let the compute node
// that it has already been registered on a previous occasion.
return &requests.RegisterResponse{
Accepted: false,
Accepted: true,
Reason: "node already registered",
}, nil
}
Expand Down

0 comments on commit 0948775

Please sign in to comment.