From ee6bb942e5e4b7f7c4daee7c6e38a7d4738548a6 Mon Sep 17 00:00:00 2001 From: Corey O'Brien Date: Thu, 11 Oct 2018 23:47:50 -0400 Subject: [PATCH] Retry initial backend configuration --- internal/ingress/controller/controller.go | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/internal/ingress/controller/controller.go b/internal/ingress/controller/controller.go index b2109bd6b..052d9be73 100644 --- a/internal/ingress/controller/controller.go +++ b/internal/ingress/controller/controller.go @@ -185,17 +185,26 @@ func (n *NGINXController) syncIngress(interface{}) error { isFirstSync := n.runningConfig.Equal(&ingress.Configuration{}) go func(isFirstSync bool) { + maxAttempts := 1 if isFirstSync { - glog.Infof("Initial synchronization of the NGINX configuration.") - - // it takes time for NGINX to start listening on the configured ports + // For the initial sync it always takes some time for NGINX to + // start listening on the configured port (default 18080) + // For large configurations it might take a while so we loop + // and back off + maxAttempts = 15 time.Sleep(1 * time.Second) } - err := configureDynamically(pcfg, n.cfg.ListenPorts.Status, n.cfg.DynamicCertificatesEnabled) - if err == nil { - glog.Infof("Dynamic reconfiguration succeeded.") - } else { - glog.Warningf("Dynamic reconfiguration failed: %v", err) + + for i := 0; i < maxAttempts; i++ { + err := configureDynamically(pcfg, n.cfg.ListenPorts.Status, n.cfg.DynamicCertificatesEnabled) + if err == nil { + glog.Infof("Dynamic reconfiguration succeeded.") + break + } else { + glog.Warningf("Dynamic reconfiguration failed: %v", err) + // Sleep between retries backing off up to 120s total + time.Sleep(time.Duration(i+1) * time.Second) + } } }(isFirstSync)