diff --git a/hscontrol/db/ip.go b/hscontrol/db/ip.go index 3fddcfd2..1c481ac0 100644 --- a/hscontrol/db/ip.go +++ b/hscontrol/db/ip.go @@ -337,3 +337,12 @@ func (db *HSDatabase) BackfillNodeIPs(i *IPAllocator) ([]string, error) { return ret, err } + +func (i *IPAllocator) FreeIPs(ips []netip.Addr) { + i.mu.Lock() + defer i.mu.Unlock() + + for _, ip := range ips { + i.usedIPs.Remove(ip) + } +} diff --git a/hscontrol/state/state.go b/hscontrol/state/state.go index c340adc2..f85acf51 100644 --- a/hscontrol/state/state.go +++ b/hscontrol/state/state.go @@ -423,6 +423,8 @@ func (s *State) DeleteNode(node types.NodeView) (change.ChangeSet, error) { return change.EmptySet, err } + s.ipAlloc.FreeIPs(node.IPs()) + c := change.NodeRemoved(node.ID()) // Check if policy manager needs updating after node deletion