machine: isOutdated: handle machines without LastSuccefulUpdate set

This commit is contained in:
Csaba Sarkadi 2022-01-15 16:20:14 +01:00
parent a32175f791
commit 8f632e9062
2 changed files with 17 additions and 5 deletions

View File

@ -420,14 +420,18 @@ func (h *Headscale) isOutdated(machine *Machine) bool {
} }
lastChange := h.getLastStateChange(namespaces...) lastChange := h.getLastStateChange(namespaces...)
lastUpdate := machine.CreatedAt
if machine.LastSuccessfulUpdate != nil {
lastUpdate = *machine.LastSuccessfulUpdate
}
log.Trace(). log.Trace().
Caller(). Caller().
Str("machine", machine.Name). Str("machine", machine.Name).
Time("last_successful_update", *machine.LastSuccessfulUpdate). Time("last_successful_update", lastChange).
Time("last_state_change", lastChange). Time("last_state_change", lastUpdate).
Msgf("Checking if %s is missing updates", machine.Name) Msgf("Checking if %s is missing updates", machine.Name)
return machine.LastSuccessfulUpdate.Before(lastChange) return lastUpdate.Before(lastChange)
} }
func (machine Machine) String() string { func (machine Machine) String() string {

12
poll.go
View File

@ -388,10 +388,14 @@ func (h *Headscale) PollNetMapStream(
updateRequestsReceivedOnChannel.WithLabelValues(machine.Name, machine.Namespace.Name). updateRequestsReceivedOnChannel.WithLabelValues(machine.Name, machine.Namespace.Name).
Inc() Inc()
if h.isOutdated(machine) { if h.isOutdated(machine) {
var lastUpdate time.Time
if machine.LastSuccessfulUpdate != nil {
lastUpdate = *machine.LastSuccessfulUpdate
}
log.Debug(). log.Debug().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Str("machine", machine.Name). Str("machine", machine.Name).
Time("last_successful_update", *machine.LastSuccessfulUpdate). Time("last_successful_update", lastUpdate).
Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)). Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)).
Msgf("There has been updates since the last successful update to %s", machine.Name) Msgf("There has been updates since the last successful update to %s", machine.Name)
data, err := h.getMapResponse(machineKey, mapRequest, machine) data, err := h.getMapResponse(machineKey, mapRequest, machine)
@ -448,10 +452,14 @@ func (h *Headscale) PollNetMapStream(
h.db.Save(&machine) h.db.Save(&machine)
} else { } else {
var lastUpdate time.Time
if machine.LastSuccessfulUpdate != nil {
lastUpdate = *machine.LastSuccessfulUpdate
}
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Str("machine", machine.Name). Str("machine", machine.Name).
Time("last_successful_update", *machine.LastSuccessfulUpdate). Time("last_successful_update", lastUpdate).
Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)). Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)).
Msgf("%s is up to date", machine.Name) Msgf("%s is up to date", machine.Name)
} }