From 1b63ca355f4e71865ee699a89b85d341be07791e Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Fri, 12 Oct 2018 14:08:31 -0300 Subject: [PATCH] Improve dynamic lua confguration --- internal/ingress/controller/controller.go | 44 ++++++++++------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/internal/ingress/controller/controller.go b/internal/ingress/controller/controller.go index 2f2b63ec23..33c8ac5a56 100644 --- a/internal/ingress/controller/controller.go +++ b/internal/ingress/controller/controller.go @@ -184,35 +184,27 @@ func (n *NGINXController) syncIngress(interface{}) error { n.metricCollector.SetSSLExpireTime(servers) } - isFirstSync := n.runningConfig.Equal(&ingress.Configuration{}) - go func(isFirstSync bool) { - steps := 1 - if isFirstSync { - // 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 - steps = 10 - time.Sleep(1 * time.Second) - } + retry := wait.Backoff{ + Steps: 15, + Duration: 1 * time.Second, + Factor: 0.8, + Jitter: 0.1, + } - retry := wait.Backoff{ - Steps: steps, - Duration: 1 * time.Second, - Factor: 1.5, - Jitter: 0.1, + err := wait.ExponentialBackoff(retry, func() (bool, error) { + err := configureDynamically(pcfg, n.cfg.ListenPorts.Status, n.cfg.DynamicCertificatesEnabled) + if err == nil { + glog.V(2).Infof("Dynamic reconfiguration succeeded.") + return true, nil } - wait.ExponentialBackoff(retry, func() (bool, error) { - err := configureDynamically(pcfg, n.cfg.ListenPorts.Status, n.cfg.DynamicCertificatesEnabled) - if err == nil { - glog.Infof("Dynamic reconfiguration succeeded.") - return true, nil - } - glog.Warningf("Dynamic reconfiguration failed: %v", err) - return false, nil - }) - }(isFirstSync) + glog.Warningf("Dynamic reconfiguration failed: %v", err) + return false, err + }) + if err != nil { + glog.Errorf("Unexpected failure reconfiguring NGINX:\n%v", err) + return err + } ri := getRemovedIngresses(n.runningConfig, pcfg) re := getRemovedHosts(n.runningConfig, pcfg)