Commit 50d736ab authored by Geoff Simmons's avatar Geoff Simmons

Controller doesn't watch namespaces when restricted to one namespace.

parent 81a73994
......@@ -238,9 +238,9 @@ func main() {
informers.WithTweakListOptions(ingressTLSSecrets))
ingController, err := controller.NewIngressController(log,
*ingressClassF, kubeClient, vController, hController,
informerFactory, vcrInformerFactory, vsecrInformerFactory,
tsecrInformerFactory, *incomplRetryDelayF)
*ingressClassF, *namespaceF, kubeClient, vController,
hController, informerFactory, vcrInformerFactory,
vsecrInformerFactory, tsecrInformerFactory, *incomplRetryDelayF)
if err != nil {
log.Fatalf("Could not initialize controller: %v", err)
os.Exit(-1)
......
......@@ -129,6 +129,7 @@ type IngressController struct {
ctx context.Context
cancel context.CancelFunc
recorder record.EventRecorder
namespace string
}
// NewIngressController creates a controller.
......@@ -143,6 +144,7 @@ type IngressController struct {
func NewIngressController(
log *logrus.Logger,
ingClass string,
namespace string,
kubeClient kubernetes.Interface,
vc *varnish.Controller,
hc *haproxy.Controller,
......@@ -154,8 +156,9 @@ func NewIngressController(
) (*IngressController, error) {
ingc := IngressController{
log: log,
client: kubeClient,
log: log,
client: kubeClient,
namespace: namespace,
}
InitMetrics()
......@@ -182,7 +185,6 @@ func NewIngressController(
ing: infFactory.Extensions().V1beta1().Ingresses().Informer(),
svc: infFactory.Core().V1().Services().Informer(),
endp: infFactory.Core().V1().Endpoints().Informer(),
ns: infFactory.Core().V1().Namespaces().Informer(),
vsecr: vsecrInfFactory.Core().V1().Secrets().Informer(),
tsecr: tsecrInfFactory.Core().V1().Secrets().Informer(),
vcfg: vcrInfFactory.Ingress().V1alpha1().VarnishConfigs().
......@@ -205,10 +207,14 @@ func NewIngressController(
ingc.informers.vcfg.AddEventHandler(evtFuncs)
ingc.informers.bcfg.AddEventHandler(evtFuncs)
nsDeleteFunc := cache.ResourceEventHandlerFuncs{
DeleteFunc: ingc.deleteNs,
if namespace == api_v1.NamespaceAll {
ingc.informers.ns =
infFactory.Core().V1().Namespaces().Informer()
nsDeleteFunc := cache.ResourceEventHandlerFuncs{
DeleteFunc: ingc.deleteNs,
}
ingc.informers.ns.AddEventHandler(nsDeleteFunc)
}
ingc.informers.ns.AddEventHandler(nsDeleteFunc)
ingc.listers = &Listers{
ing: infFactory.Extensions().V1beta1().Ingresses().Lister(),
......@@ -393,7 +399,9 @@ func (ingc *IngressController) Run(readyFile string, metricsPort uint16) {
go ingc.informers.vsecr.Run(ingc.ctx.Done())
go ingc.informers.vcfg.Run(ingc.ctx.Done())
go ingc.informers.bcfg.Run(ingc.ctx.Done())
go ingc.informers.ns.Run(ingc.ctx.Done())
if ingc.namespace == api_v1.NamespaceAll {
go ingc.informers.ns.Run(ingc.ctx.Done())
}
ingc.log.Infof("Starting metrics listener at port %d", metricsPort)
go ServeMetrics(ingc.log, metricsPort)
......@@ -416,8 +424,7 @@ func (ingc *IngressController) Run(readyFile string, metricsPort uint16) {
ingc.log.Infof("Created ready file %s", readyFile)
}
ingc.log.Info("Waiting for caches to sync")
if ok := cache.WaitForCacheSync(ingc.ctx.Done(),
syncs := []cache.InformerSynced{
ingc.informers.ing.HasSynced,
ingc.informers.svc.HasSynced,
ingc.informers.endp.HasSynced,
......@@ -425,8 +432,13 @@ func (ingc *IngressController) Run(readyFile string, metricsPort uint16) {
ingc.informers.vsecr.HasSynced,
ingc.informers.vcfg.HasSynced,
ingc.informers.bcfg.HasSynced,
ingc.informers.ns.HasSynced); !ok {
}
if ingc.namespace == api_v1.NamespaceAll {
syncs = append(syncs, ingc.informers.ns.HasSynced)
}
ingc.log.Info("Waiting for caches to sync")
if ok := cache.WaitForCacheSync(ingc.ctx.Done(), syncs...); !ok {
err := fmt.Errorf("Failed waiting for caches to sync")
utilruntime.HandleError(err)
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment