Skip to content

Commit

Permalink
Simplify error handling
Browse files Browse the repository at this point in the history
- Most of the error handling in these batch update funcs can be removed.
The caller only logs the errors anyway.
- Fix a few rebase issues.
  • Loading branch information
isaac committed Sep 7, 2018
1 parent fc82d25 commit 74645a2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 44 deletions.
40 changes: 20 additions & 20 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand All @@ -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)
}
}
}
}
Expand Down Expand Up @@ -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.
Expand Down
33 changes: 9 additions & 24 deletions internal/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 74645a2

Please sign in to comment.