diff --git a/cmd/nginx-ingress/main.go b/cmd/nginx-ingress/main.go index c05607291f..9876729e31 100644 --- a/cmd/nginx-ingress/main.go +++ b/cmd/nginx-ingress/main.go @@ -229,7 +229,6 @@ func main() { var nginxAPI *plus.NginxAPIController if *nginxPlus { - time.Sleep(500 * time.Millisecond) httpClient := getSocketClient() nginxAPI, err = plus.NewNginxAPIController(&httpClient, "http://nginx-plus-api/api", local) if err != nil { diff --git a/internal/nginx/nginx.go b/internal/nginx/nginx.go index 304fc1d955..9ec7046d86 100644 --- a/internal/nginx/nginx.go +++ b/internal/nginx/nginx.go @@ -319,18 +319,26 @@ func (nginx *Controller) Reload() error { // Start starts NGINX func (nginx *Controller) Start(done chan error) { - if !nginx.local { - cmd := exec.Command("nginx") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - if err := cmd.Start(); err != nil { - glog.Fatalf("Failed to start nginx: %v", err) - } - go func() { - done <- cmd.Wait() - }() - } else { - glog.V(3).Info("Starting nginx") + glog.V(3).Info("Starting nginx") + + if nginx.local { + return + } + + cmd := exec.Command("nginx") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Start(); err != nil { + glog.Fatalf("Failed to start nginx: %v", err) + } + + go func() { + done <- cmd.Wait() + }() + + err := nginx.verifyClient.WaitForCorrectVersion(nginx.configVersion) + if err != nil { + glog.Fatalf("Could not get newest config version: %v", err) } } diff --git a/internal/nginx/verify/client.go b/internal/nginx/verify/client.go index a5cd79c3fa..4674cd810d 100644 --- a/internal/nginx/verify/client.go +++ b/internal/nginx/verify/client.go @@ -60,16 +60,18 @@ func (c *Client) WaitForCorrectVersion(expectedVersion int) error { // This value needs tuning. maxRetries := 160 sleep := 25 * time.Millisecond - for i := 0; i < maxRetries; i++ { + for i := 1; i <= maxRetries; i++ { + time.Sleep(sleep) + version, err := c.GetConfigVersion() if err != nil { - return fmt.Errorf("unable to fetch version: %v", err) + glog.V(3).Infof("Unable to fetch version: %v", err) + continue } if version == expectedVersion { glog.V(3).Infof("success, version %v ensured. iterations: %v. took: %v", expectedVersion, i, time.Duration(i)*sleep) return nil } - time.Sleep(sleep) } return fmt.Errorf("could not get expected version: %v", expectedVersion) }