fix: Caddy config regeneration due to non-deterministic container serialisation (fixes #111)

This commit is contained in:
Pasha Sviderski
2026-04-15 16:49:01 +10:00
parent 39181708dd
commit 6e9acefbe6
8 changed files with 298 additions and 40 deletions
+12 -1
View File
@@ -4,7 +4,9 @@ import (
"context"
"fmt"
"log/slog"
"maps"
"net/netip"
"slices"
"sync"
"time"
@@ -102,12 +104,21 @@ func (r *ClusterResolver) updateServiceIPs(containers []store.ContainerRecord) {
containersCount++
}
// Sort each service's IPs so they have a deterministic order for comparison.
for _, ips := range newServiceIPs {
slices.SortFunc(ips, func(a, b netip.Addr) int { return a.Compare(b) })
}
// Skip the swap when the services or their container IPs haven't changed.
if maps.EqualFunc(r.serviceIPs, newServiceIPs, slices.Equal[[]netip.Addr]) {
return
}
// Update the serviceIPs map atomically.
r.mu.Lock()
r.serviceIPs = newServiceIPs
r.mu.Unlock()
r.log.Debug("DNS records updated.", "services", len(newServiceIPs)/3, "containers", containersCount)
r.log.Info("DNS records updated.", "services", len(newServiceIPs)/3, "containers", containersCount)
}
// Resolve returns IP addresses of the service containers.