fix: prevent race condition with Docker network creation (#89)

This commit is contained in:
Evgenii Orlov
2025-07-10 17:51:08 +10:00
committed by GitHub
parent 31cd4c77e9
commit 10bbe9fbc5
3 changed files with 106 additions and 3 deletions
+8
View File
@@ -44,6 +44,9 @@ type networkController struct {
// dnsServer is the embedded internal DNS server for the cluster listening on the machine IP.
dnsServer *dns.Server
dnsResolver *dns.ClusterResolver
// networkReady is signalled when the Docker network is configured and ready for containers.
networkReady chan<- struct{}
}
func newNetworkController(
@@ -55,6 +58,7 @@ func newNetworkController(
caddyfileCtrl *caddyconfig.Controller,
dnsServer *dns.Server,
dnsResolver *dns.ClusterResolver,
networkReady chan<- struct{},
) (
*networkController, error,
) {
@@ -76,6 +80,7 @@ func newNetworkController(
caddyfileCtrl: caddyfileCtrl,
dnsServer: dnsServer,
dnsResolver: dnsResolver,
networkReady: networkReady,
}, nil
}
@@ -225,6 +230,9 @@ func (nc *networkController) prepareAndWatchDocker(ctx context.Context) error {
}
slog.Info("Docker network configured.")
// Signal that the Docker network is ready for containers
close(nc.networkReady)
slog.Info("Watching Docker containers and syncing them to cluster store.")
// Retry to watch and sync containers until the context is done.
boff := backoff.WithContext(backoff.NewExponentialBackOff(