Skip to content

Commit 120adcd

Browse files
author
isaac
committed
Simplify error handling
- 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.
1 parent ebfd452 commit 120adcd

File tree

2 files changed

+27
-48
lines changed

2 files changed

+27
-48
lines changed

nginx-controller/controller/controller.go

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,8 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc
244244
lbc.syncQueue.enqueue(curSvc)
245245
return
246246
}
247-
// attempt to avoid enqueuing the ingress for this service
248-
oldSvc := old.(*api_v1.Service)
249-
if !reflect.DeepEqual(curSvc.Spec.Ports, oldSvc.Spec.Ports) ||
250-
!reflect.DeepEqual(curSvc.Spec.Type, oldSvc.Spec.Type) {
251-
glog.V(3).Infof("Service %v changed, syncing", curSvc.Name)
252-
lbc.enqueueIngressForService(curSvc)
253-
}
254-
247+
glog.V(3).Infof("Service %v changed, syncing", curSvc.Name)
248+
lbc.enqueueIngressForService(curSvc)
255249
}
256250
},
257251
}
@@ -444,7 +438,7 @@ func (lbc *LoadBalancerController) syncEndp(task Task) {
444438
ings := lbc.getIngressForEndpoints(obj)
445439

446440
var ingExes []*nginx.IngressEx
447-
var mergableIngressesBatch []*nginx.MergeableIngresses
441+
var mergableIngressesSlice []*nginx.MergeableIngresses
448442

449443
for i := range ings {
450444
if !lbc.isNginxIngress(&ings[i]) {
@@ -456,7 +450,7 @@ func (lbc *LoadBalancerController) syncEndp(task Task) {
456450
glog.Errorf("Ignoring Ingress %v(Minion): %v", ings[i].Name, err)
457451
continue
458452
}
459-
if !lbc.cnf.HasIngress(master) {
453+
if !lbc.cnf.HasMinion(master, &ings[i]) {
460454
continue
461455
}
462456
mergeableIngresses, err := lbc.createMergableIngresses(master)
@@ -465,7 +459,7 @@ func (lbc *LoadBalancerController) syncEndp(task Task) {
465459
continue
466460
}
467461

468-
mergableIngressesBatch = append(mergableIngressesBatch, mergeableIngresses)
462+
mergableIngressesSlice = append(mergableIngressesSlice, mergeableIngresses)
469463
continue
470464
}
471465
if !lbc.cnf.HasIngress(&ings[i]) {
@@ -480,19 +474,20 @@ func (lbc *LoadBalancerController) syncEndp(task Task) {
480474
ingExes = append(ingExes, ingEx)
481475
}
482476

483-
if len(ingExes) == 0 {
484-
return
477+
if len(ingExes) > 0 {
478+
glog.V(3).Infof("Updating Endpoints for %v", ingExes)
479+
err = lbc.cnf.UpdateEndpoints(ingExes)
480+
if err != nil {
481+
glog.Errorf("Error updating endpoints for %v: %v", ingExes, err)
482+
}
485483
}
486484

487-
glog.V(3).Infof("Updating Endpoints for %v", ingExes)
488-
lbc.cnf.UpdateEndpoints(ingExes)
489-
if err != nil {
490-
glog.Errorf("Error updating endpoints for %v: %v", ingExes, err)
491-
}
492-
glog.V(3).Infof("Updating Endpoints for %v", mergableIngressesBatch)
493-
err = lbc.cnf.UpdateEndpointsMergeableIngress(mergableIngressesBatch)
494-
if err != nil {
495-
glog.Errorf("Error updating endpoints for %v: %v", mergableIngressesBatch, err)
485+
if len(mergableIngressesSlice) > 0 {
486+
glog.V(3).Infof("Updating Endpoints for %v", mergableIngressesSlice)
487+
err = lbc.cnf.UpdateEndpointsMergeableIngress(mergableIngressesSlice)
488+
if err != nil {
489+
glog.Errorf("Error updating endpoints for %v: %v", mergableIngressesSlice, err)
490+
}
496491
}
497492
}
498493
}
@@ -1315,9 +1310,8 @@ func (lbc *LoadBalancerController) isNginxIngress(ing *extensions.Ingress) bool
13151310
return class == lbc.ingressClass
13161311
}
13171312
return class == lbc.ingressClass || class == ""
1318-
} else {
1319-
return !lbc.useIngressClassOnly
13201313
}
1314+
return !lbc.useIngressClassOnly
13211315
}
13221316

13231317
// isHealthCheckEnabled checks if health checks are enabled so we can only query pods if enabled.

nginx-controller/nginx/configurator.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -994,48 +994,33 @@ func (cnf *Configurator) UpdateEndpoints(ingExes []*IngressEx) error {
994994
}
995995

996996
// UpdateEndpointsMergeableIngress updates endpoints in NGINX configuration for a mergeable Ingress resource
997-
func (cnf *Configurator) UpdateEndpointsMergeableIngress(mergableIngressesBatch []*MergeableIngresses) error {
997+
func (cnf *Configurator) UpdateEndpointsMergeableIngress(mergableIngressesSlice []*MergeableIngresses) error {
998998
reloadPlus := false
999-
errors := []error{}
1000-
for i := range mergableIngressesBatch {
1001-
err := cnf.addOrUpdateMergeableIngress(mergableIngressesBatch[i])
999+
for i := range mergableIngressesSlice {
1000+
err := cnf.addOrUpdateMergeableIngress(mergableIngressesSlice[i])
10021001
if err != nil {
1003-
glog.V(3).Infof("Error adding or updating ingress %v/%v: %v", mergableIngressesBatch[i].Master.Ingress.Namespace, mergableIngressesBatch[i].Master.Ingress.Name, err)
1004-
errors = append(errors, err)
1005-
continue
1002+
return fmt.Errorf("Error adding or updating mergeableIngress %v/%v: %v", mergableIngressesSlice[i].Master.Ingress.Namespace, mergableIngressesSlice[i].Master.Ingress.Name, err)
10061003
}
10071004

10081005
if cnf.isPlus() {
1009-
for _, ing := range mergableIngressesBatch[i].Minions {
1006+
for _, ing := range mergableIngressesSlice[i].Minions {
10101007
err = cnf.updatePlusEndpoints(ing)
10111008
if err != nil {
10121009
glog.Warningf("Couldn't update the endpoints via the API: %v; reloading configuration instead", err)
1013-
errors = append(errors, err)
10141010
reloadPlus = true
1015-
break
10161011
}
10171012
}
10181013
}
10191014
}
10201015
if cnf.isPlus() && !reloadPlus {
1021-
return consolodiateErrors(errors)
1016+
glog.V(3).Info("No need to reload nginx")
1017+
return nil
10221018
}
10231019

10241020
if err := cnf.nginx.Reload(); err != nil {
1025-
return fmt.Errorf("Error reloading NGINX: %v. additional errors: %v", err, consolodiateErrors(errors))
1026-
}
1027-
return consolodiateErrors(errors)
1028-
}
1029-
1030-
func consolodiateErrors(errors []error) error {
1031-
errorString := ""
1032-
if len(errors) == 0 {
1033-
return nil
1021+
return fmt.Errorf("Error reloading NGINX when updating endpoints for %v: %v", mergableIngressesSlice, err)
10341022
}
1035-
for _, e := range errors {
1036-
errorString = errorString + e.Error()
1037-
}
1038-
return fmt.Errorf(errorString)
1023+
return nil
10391024
}
10401025

10411026
func (cnf *Configurator) updatePlusEndpoints(ingEx *IngressEx) error {

0 commit comments

Comments
 (0)