Remove redundant caches

This commit removes the two extra caches (oidc, requested time) and uses
the new central registration cache instead. The requested time is
unified into the main machine object and the oidc key is just added to
the same cache, as a string with the state as a key instead of machine
key.
This commit is contained in:
Kristoffer Dalby
2022-02-28 22:42:30 +00:00
parent e64bee778f
commit 5e92ddad43
6 changed files with 27 additions and 84 deletions

View File

@@ -160,25 +160,10 @@ func (api headscaleV1APIServer) RegisterMachine(
Str("machine_key", request.GetKey()).
Msg("Registering machine")
// TODO(kradalby): Currently, if it fails to find a requested expiry, non will be set
// This means that if a user is to slow with register a machine, it will possibly not
// have the correct expiry.
requestedTime := time.Time{}
if requestedTimeIf, found := api.h.requestedExpiryCache.Get(request.GetKey()); found {
log.Trace().
Caller().
Str("machine", request.Key).
Msg("Expiry time found in cache, assigning to node")
if reqTime, ok := requestedTimeIf.(time.Time); ok {
requestedTime = reqTime
}
}
machine, err := api.h.RegisterMachineFromAuthCallback(
request.GetKey(),
request.GetNamespace(),
RegisterMethodCLI,
&requestedTime,
)
if err != nil {
return nil, err
@@ -418,7 +403,7 @@ func (api headscaleV1APIServer) DebugCreateMachine(
api.h.registrationCache.Set(
request.GetKey(),
newMachine,
requestedExpiryCacheExpiration,
registerCacheExpiration,
)
return &v1.DebugCreateMachineResponse{Machine: newMachine.toProto()}, nil