From cceb7e9c015c82438cb7fc42b81ac64939fb1d91 Mon Sep 17 00:00:00 2001 From: GLYASAI Date: Sat, 1 Dec 2018 16:40:01 +0800 Subject: [PATCH] [FIX] fix bug: open() "/usr/local/openresty/nginx/html/update-upstreams" failed --- gateway/controller/openresty/service.go | 28 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/gateway/controller/openresty/service.go b/gateway/controller/openresty/service.go index c33111096..81443c34a 100644 --- a/gateway/controller/openresty/service.go +++ b/gateway/controller/openresty/service.go @@ -238,21 +238,22 @@ func (osvc *OrService) UpdatePools(pools []*v1.Pool) error { } upstream.Servers = append(upstream.Servers, server) } - if len(upstream.Servers) == 0 { - continue - } + //if len(upstream.Servers) == 0 { + // continue + //} upstreams = append(upstreams, upstream) } - if len(upstreams) == 0 { - // TODO - return nil - } + //if len(upstreams) == 0 { + // logrus.Warningf("empty upstreams: %v", pools) + // return nil + //} return osvc.updateUpstreams(upstreams) } // updateUpstreams updates the upstreams in ngx.shared.dict by post func (osvc *OrService) updateUpstreams(upstream []*Upstream) error { url := fmt.Sprintf("http://127.0.0.1:%v/update-upstreams", osvc.AuxiliaryPort) + osvc.WaitPluginReadyWithURL(url) data, _ := json.Marshal(upstream) logrus.Debugf("request contest of update-upstreams is %v", string(data)) @@ -316,6 +317,19 @@ func (osvc *OrService) WaitPluginReady() { } } +// WaitPluginReady waits for the specified url to be ready +func (osvc *OrService) WaitPluginReadyWithURL(url string) { + for { + resp, err := http.Get(url) + if err == nil && resp.StatusCode == 200 { + logrus.Info("Nginx is ready") + break + } + logrus.Infof("Nginx is not ready yet: %v", err) + time.Sleep(1 * time.Second) + } +} + // newRbdServers creates new configuration file for Rainbond servers func (osvc *OrService) newRbdServers() error { cfgPath := "/run/nginx/rainbond"