mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-22 16:07:34 +00: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...)
|
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
12
poll.go
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user