Skip to content

Commit

Permalink
Refactor initial synchronization of ingress objects (#1891)
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored Jan 9, 2018
1 parent 313fdd2 commit 142b444
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions internal/ingress/controller/listers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"fmt"
"reflect"
"time"

"github.com/golang/glog"

Expand All @@ -42,22 +43,33 @@ type cacheController struct {
}

func (c *cacheController) Run(stopCh chan struct{}) {
go c.Ingress.Run(stopCh)
go c.Endpoint.Run(stopCh)
go c.Service.Run(stopCh)
go c.Secret.Run(stopCh)
go c.Configmap.Run(stopCh)

time.Sleep(1 * time.Second)
go c.Ingress.Run(stopCh)

// Wait for all involved caches to be synced, before processing items from the queue is started
if !cache.WaitForCacheSync(stopCh,
c.Ingress.HasSynced,
c.Endpoint.HasSynced,
c.Service.HasSynced,
c.Secret.HasSynced,
c.Configmap.HasSynced,
) {
runtime.HandleError(fmt.Errorf("Timed out waiting for caches to sync"))
}

// We need to wait before start syncing the ingress rules
// because the rules requires content from other listers
time.Sleep(1 * time.Second)
go c.Ingress.Run(stopCh)
if !cache.WaitForCacheSync(stopCh,
c.Ingress.HasSynced,
) {
runtime.HandleError(fmt.Errorf("Timed out waiting for caches to sync"))
}
}

func (n *NGINXController) createListers(stopCh chan struct{}) (*ingress.StoreLister, *cacheController) {
Expand Down Expand Up @@ -120,6 +132,9 @@ func (n *NGINXController) createListers(stopCh chan struct{}) (*ingress.StoreLis
}

secrEventHandler := cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
n.syncQueue.Enqueue(obj)
},
UpdateFunc: func(old, cur interface{}) {
if !reflect.DeepEqual(old, cur) {
sec := cur.(*apiv1.Secret)
Expand Down Expand Up @@ -147,7 +162,7 @@ func (n *NGINXController) createListers(stopCh chan struct{}) (*ingress.StoreLis
}
key := fmt.Sprintf("%v/%v", sec.Namespace, sec.Name)
n.sslCertTracker.Delete(key)
n.syncQueue.Enqueue(key)
n.syncQueue.Enqueue(obj)
},
}

Expand Down

0 comments on commit 142b444

Please sign in to comment.