Validate isOutdated against all namespaces

This commit makes isOutdated validate a nodes necessity to update
against all namespaces, and not just the nodes own namespace (which made
more sense before).

getLastStateChange is now uses the passed namespaces as a filter,
meaning that not requesting any namespace will give you the total last
updated state.

In addition, the sync.Map is exchanged for a variant that uses generics
which allows us to remove some casting logic.
This commit is contained in:
Kristoffer Dalby 2022-05-30 12:39:41 +02:00
parent a992840c9b
commit a443255b3e
5 changed files with 28 additions and 12 deletions

View file

@ -9,7 +9,6 @@ import (
"strings"
"time"
mapset "github.com/deckarep/golang-set/v2"
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/rs/zerolog/log"
"google.golang.org/protobuf/types/known/timestamppb"
@ -469,10 +468,12 @@ func (h *Headscale) isOutdated(machine *Machine) bool {
return true
}
namespaceSet := mapset.NewSet[string]()
namespaceSet.Add(machine.Namespace.Name)
lastChange := h.getLastStateChange(namespaceSet.ToSlice()...)
// Get the last update from all headscale namespaces to compare with our nodes
// last update.
// TODO(kradalby): Only request updates from namespaces where we can talk to nodes
// This would mostly be for a bit of performance, and can be calculated based on
// ACLs.
lastChange := h.getLastStateChange()
lastUpdate := machine.CreatedAt
if machine.LastSuccessfulUpdate != nil {
lastUpdate = *machine.LastSuccessfulUpdate