mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-25 05:35:52 -05:00
machine: isOutdated: handle machines without LastSuccefulUpdate set
This commit is contained in:
parent
a32175f791
commit
8f632e9062
10
machine.go
10
machine.go
@ -420,14 +420,18 @@ func (h *Headscale) isOutdated(machine *Machine) bool {
|
||||
}
|
||||
|
||||
lastChange := h.getLastStateChange(namespaces...)
|
||||
lastUpdate := machine.CreatedAt
|
||||
if machine.LastSuccessfulUpdate != nil {
|
||||
lastUpdate = *machine.LastSuccessfulUpdate
|
||||
}
|
||||
log.Trace().
|
||||
Caller().
|
||||
Str("machine", machine.Name).
|
||||
Time("last_successful_update", *machine.LastSuccessfulUpdate).
|
||||
Time("last_state_change", lastChange).
|
||||
Time("last_successful_update", lastChange).
|
||||
Time("last_state_change", lastUpdate).
|
||||
Msgf("Checking if %s is missing updates", machine.Name)
|
||||
|
||||
return machine.LastSuccessfulUpdate.Before(lastChange)
|
||||
return lastUpdate.Before(lastChange)
|
||||
}
|
||||
|
||||
func (machine Machine) String() string {
|
||||
|
12
poll.go
12
poll.go
@ -388,10 +388,14 @@ func (h *Headscale) PollNetMapStream(
|
||||
updateRequestsReceivedOnChannel.WithLabelValues(machine.Name, machine.Namespace.Name).
|
||||
Inc()
|
||||
if h.isOutdated(machine) {
|
||||
var lastUpdate time.Time
|
||||
if machine.LastSuccessfulUpdate != nil {
|
||||
lastUpdate = *machine.LastSuccessfulUpdate
|
||||
}
|
||||
log.Debug().
|
||||
Str("handler", "PollNetMapStream").
|
||||
Str("machine", machine.Name).
|
||||
Time("last_successful_update", *machine.LastSuccessfulUpdate).
|
||||
Time("last_successful_update", lastUpdate).
|
||||
Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)).
|
||||
Msgf("There has been updates since the last successful update to %s", machine.Name)
|
||||
data, err := h.getMapResponse(machineKey, mapRequest, machine)
|
||||
@ -448,10 +452,14 @@ func (h *Headscale) PollNetMapStream(
|
||||
|
||||
h.db.Save(&machine)
|
||||
} else {
|
||||
var lastUpdate time.Time
|
||||
if machine.LastSuccessfulUpdate != nil {
|
||||
lastUpdate = *machine.LastSuccessfulUpdate
|
||||
}
|
||||
log.Trace().
|
||||
Str("handler", "PollNetMapStream").
|
||||
Str("machine", machine.Name).
|
||||
Time("last_successful_update", *machine.LastSuccessfulUpdate).
|
||||
Time("last_successful_update", lastUpdate).
|
||||
Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)).
|
||||
Msgf("%s is up to date", machine.Name)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user