Skip to content

Commit

Permalink
Merge pull request #234 from jcmoraisjr/jm-reading-defback
Browse files Browse the repository at this point in the history
Optimize reading of default backend
  • Loading branch information
jcmoraisjr authored Oct 23, 2018
2 parents 94dbe14 + d053ec6 commit 00efb1b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/common/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ var (
type GenericController struct {
cfg *Configuration

defaultBackend *defaults.Backend

listers *ingress.StoreLister
cacheController *cacheController

Expand Down Expand Up @@ -190,7 +192,7 @@ func newIngressController(config *Configuration) *GenericController {
} else {
glog.Warning("Update of ingress status is disabled (flag --update-status=false was specified)")
}
ic.annotations = newAnnotationExtractor(ic)
ic.annotations = newAnnotationExtractor(&ic)

ic.cfg.Backend.SetListers(ic.listers)

Expand All @@ -210,8 +212,16 @@ func (ic GenericController) IngressClass() string {
}

// GetDefaultBackend returns the default backend
func (ic GenericController) GetDefaultBackend() defaults.Backend {
return ic.cfg.Backend.BackendDefaults()
func (ic *GenericController) GetDefaultBackend() defaults.Backend {
if ic.defaultBackend == nil {
defaultBackend := ic.cfg.Backend.BackendDefaults()
ic.defaultBackend = &defaultBackend
}
// this can cause a nil dereference due to nil assignment
// of ic.defaultBackend on syncIngress()
// we are safe here because all GetDefaultBackend() calls
// are in the same thread, coming from syncIngress()
return *ic.defaultBackend
}

// GetPublishService returns the configured service used to set ingress status
Expand Down Expand Up @@ -249,6 +259,10 @@ func (ic *GenericController) syncIngress(item interface{}) error {
return nil
}

// force reload of default backend data
// see GetDefaultBackend()
ic.defaultBackend = nil

if element, ok := item.(task.Element); ok {
if name, ok := element.Key.(string); ok {
if obj, exists, _ := ic.listers.Ingress.GetByKey(name); exists {
Expand Down

0 comments on commit 00efb1b

Please sign in to comment.