diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 6fd9c5934e..706afc7859 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -278,19 +278,19 @@ func (lbc *LoadBalancerController) syncEndpoint(task queue.Task) { ings := lbc.getIngressForEndpoints(obj) var ingExes []*nginx.IngressEx - var mergableIngressesBatch []*nginx.MergeableIngresses + var mergableIngressesSlice []*nginx.MergeableIngresses for i := range ings { - if !lbc.isNginxIngress(&ings[i]) { + if !lbc.IsNginxIngress(&ings[i]) { continue } - if isMinion(&ings[i]) { - master, err := lbc.findMasterForMinion(&ings[i]) + if utils.IsMinion(&ings[i]) { + master, err := lbc.FindMasterForMinion(&ings[i]) if err != nil { glog.Errorf("Ignoring Ingress %v(Minion): %v", ings[i].Name, err) continue } - if !lbc.configurator.HasIngress(master) { + if !lbc.configurator.HasMinion(master, &ings[i]) { continue } mergeableIngresses, err := lbc.createMergableIngresses(master) @@ -299,10 +299,10 @@ func (lbc *LoadBalancerController) syncEndpoint(task queue.Task) { continue } - mergableIngressesBatch = append(mergableIngressesBatch, mergeableIngresses) + mergableIngressesSlice = append(mergableIngressesSlice, mergeableIngresses) continue } - if !lbc.cnf.HasIngress(&ings[i]) { + if !lbc.configurator.HasIngress(&ings[i]) { continue } ingEx, err := lbc.createIngress(&ings[i]) @@ -313,19 +313,20 @@ func (lbc *LoadBalancerController) syncEndpoint(task queue.Task) { ingExes = append(ingExes, ingEx) } - if len(ingExes) == 0 { - return + if len(ingExes) > 0 { + glog.V(3).Infof("Updating Endpoints for %v", ingExes) + err = lbc.configurator.UpdateEndpoints(ingExes) + if err != nil { + glog.Errorf("Error updating endpoints for %v: %v", ingExes, err) + } } - glog.V(3).Infof("Updating Endpoints for %v", ingExes) - lbc.cnf.UpdateEndpoints(ingExes) - if err != nil { - glog.Errorf("Error updating endpoints for %v: %v", ingExes, err) - } - glog.V(3).Infof("Updating Endpoints for %v", mergableIngressesBatch) - err = lbc.cnf.UpdateEndpointsMergeableIngress(mergableIngressesBatch) - if err != nil { - glog.Errorf("Error updating endpoints for %v: %v", mergableIngressesBatch, err) + if len(mergableIngressesSlice) > 0 { + glog.V(3).Infof("Updating Endpoints for %v", mergableIngressesSlice) + err = lbc.configurator.UpdateEndpointsMergeableIngress(mergableIngressesSlice) + if err != nil { + glog.Errorf("Error updating endpoints for %v: %v", mergableIngressesSlice, err) + } } } } @@ -1138,9 +1139,8 @@ func (lbc *LoadBalancerController) IsNginxIngress(ing *extensions.Ingress) bool return class == lbc.ingressClass } return class == lbc.ingressClass || class == "" - } else { - return !lbc.useIngressClassOnly } + return !lbc.useIngressClassOnly } // isHealthCheckEnabled checks if health checks are enabled so we can only query pods if enabled. diff --git a/internal/nginx/configurator.go b/internal/nginx/configurator.go index b01689d2a2..8e2ab6f472 100644 --- a/internal/nginx/configurator.go +++ b/internal/nginx/configurator.go @@ -994,48 +994,33 @@ func (cnf *Configurator) UpdateEndpoints(ingExes []*IngressEx) error { } // UpdateEndpointsMergeableIngress updates endpoints in NGINX configuration for a mergeable Ingress resource -func (cnf *Configurator) UpdateEndpointsMergeableIngress(mergableIngressesBatch []*MergeableIngresses) error { +func (cnf *Configurator) UpdateEndpointsMergeableIngress(mergableIngressesSlice []*MergeableIngresses) error { reloadPlus := false - errors := []error{} - for i := range mergableIngressesBatch { - err := cnf.addOrUpdateMergeableIngress(mergableIngressesBatch[i]) + for i := range mergableIngressesSlice { + err := cnf.addOrUpdateMergeableIngress(mergableIngressesSlice[i]) if err != nil { - glog.V(3).Infof("Error adding or updating ingress %v/%v: %v", mergableIngressesBatch[i].Master.Ingress.Namespace, mergableIngressesBatch[i].Master.Ingress.Name, err) - errors = append(errors, err) - continue + return fmt.Errorf("Error adding or updating mergeableIngress %v/%v: %v", mergableIngressesSlice[i].Master.Ingress.Namespace, mergableIngressesSlice[i].Master.Ingress.Name, err) } if cnf.isPlus() { - for _, ing := range mergableIngressesBatch[i].Minions { + for _, ing := range mergableIngressesSlice[i].Minions { err = cnf.updatePlusEndpoints(ing) if err != nil { glog.Warningf("Couldn't update the endpoints via the API: %v; reloading configuration instead", err) - errors = append(errors, err) reloadPlus = true - break } } } } if cnf.isPlus() && !reloadPlus { - return consolodiateErrors(errors) + glog.V(3).Info("No need to reload nginx") + return nil } if err := cnf.nginx.Reload(); err != nil { - return fmt.Errorf("Error reloading NGINX: %v. additional errors: %v", err, consolodiateErrors(errors)) - } - return consolodiateErrors(errors) -} - -func consolodiateErrors(errors []error) error { - errorString := "" - if len(errors) == 0 { - return nil + return fmt.Errorf("Error reloading NGINX when updating endpoints for %v: %v", mergableIngressesSlice, err) } - for _, e := range errors { - errorString = errorString + e.Error() - } - return fmt.Errorf(errorString) + return nil } func (cnf *Configurator) updatePlusEndpoints(ingEx *IngressEx) error {