diff --git a/machine.go b/machine.go index 64fd11b8..2b462985 100644 --- a/machine.go +++ b/machine.go @@ -353,13 +353,12 @@ func (h *Headscale) DeleteMachine(machine *Machine) error { } machine.Registered = false - namespaceID := machine.NamespaceID h.db.Save(&machine) // we mark it as unregistered, just in case if err := h.db.Delete(&machine).Error; err != nil { return err } - return h.RequestMapUpdates(namespaceID) + return nil } func (h *Headscale) TouchMachine(machine *Machine) error { @@ -377,12 +376,11 @@ func (h *Headscale) HardDeleteMachine(machine *Machine) error { return err } - namespaceID := machine.NamespaceID if err := h.db.Unscoped().Delete(&machine).Error; err != nil { return err } - return h.RequestMapUpdates(namespaceID) + return nil } // GetHostInfo returns a Hostinfo struct for the machine. @@ -530,7 +528,9 @@ func (machine Machine) toNode( addrs = append(addrs, ip) } - allowedIPs := append([]netaddr.IPPrefix{}, addrs...) // we append the node own IP, as it is required by the clients + allowedIPs := append( + []netaddr.IPPrefix{}, + addrs...) // we append the node own IP, as it is required by the clients if includeRoutes { routesStr := []string{} @@ -862,11 +862,6 @@ func (h *Headscale) EnableRoutes(machine *Machine, routeStrs ...string) error { machine.EnabledRoutes = datatypes.JSON(routes) h.db.Save(&machine) - err = h.RequestMapUpdates(machine.NamespaceID) - if err != nil { - return err - } - return nil } diff --git a/namespaces.go b/namespaces.go index 223455af..bdd440cf 100644 --- a/namespaces.go +++ b/namespaces.go @@ -1,9 +1,7 @@ package headscale import ( - "encoding/json" "errors" - "fmt" "strconv" "time" @@ -104,11 +102,6 @@ func (h *Headscale) RenameNamespace(oldName, newName string) error { return result.Error } - err = h.RequestMapUpdates(oldNamespace.ID) - if err != nil { - return err - } - return nil } @@ -187,54 +180,6 @@ func (h *Headscale) SetMachineNamespace(machine *Machine, namespaceName string) return nil } -// TODO(kradalby): Remove the need for this. -// RequestMapUpdates signals the KV worker to update the maps for this namespace. -func (h *Headscale) RequestMapUpdates(namespaceID uint) error { - namespace := Namespace{} - if err := h.db.First(&namespace, namespaceID).Error; err != nil { - return err - } - - namespacesPendingUpdates, err := h.getValue("namespaces_pending_updates") - if err != nil || namespacesPendingUpdates == "" { - err = h.setValue( - "namespaces_pending_updates", - fmt.Sprintf(`["%s"]`, namespace.Name), - ) - if err != nil { - return err - } - - return nil - } - names := []string{} - err = json.Unmarshal([]byte(namespacesPendingUpdates), &names) - if err != nil { - err = h.setValue( - "namespaces_pending_updates", - fmt.Sprintf(`["%s"]`, namespace.Name), - ) - if err != nil { - return err - } - - return nil - } - - names = append(names, namespace.Name) - data, err := json.Marshal(names) - if err != nil { - log.Error(). - Str("func", "RequestMapUpdates"). - Err(err). - Msg("Could not marshal namespaces_pending_updates") - - return err - } - - return h.setValue("namespaces_pending_updates", string(data)) -} - func (n *Namespace) toUser() *tailcfg.User { user := tailcfg.User{ ID: tailcfg.UserID(n.ID), diff --git a/routes.go b/routes.go index 448095a5..0065a03f 100644 --- a/routes.go +++ b/routes.go @@ -143,10 +143,5 @@ func (h *Headscale) EnableNodeRoute( machine.EnabledRoutes = datatypes.JSON(routes) h.db.Save(&machine) - err = h.RequestMapUpdates(machine.NamespaceID) - if err != nil { - return err - } - return nil } diff --git a/sharing.go b/sharing.go index be1689d5..caac5319 100644 --- a/sharing.go +++ b/sharing.go @@ -67,11 +67,6 @@ func (h *Headscale) RemoveSharedMachineFromNamespace( return errMachineNotShared } - err := h.RequestMapUpdates(namespace.ID) - if err != nil { - return err - } - return nil }