Allow to disable Kubernetes cluster scope resources discovery
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
parent
930f84850b
commit
a50345bf8d
18 changed files with 349 additions and 153 deletions
|
@ -57,10 +57,12 @@ type clientWrapper struct {
|
|||
csCrd traefikclientset.Interface
|
||||
csKube kclientset.Interface
|
||||
|
||||
factoryClusterScope kinformers.SharedInformerFactory
|
||||
factoriesCrd map[string]traefikinformers.SharedInformerFactory
|
||||
factoriesKube map[string]kinformers.SharedInformerFactory
|
||||
factoriesSecret map[string]kinformers.SharedInformerFactory
|
||||
clusterScopeFactory kinformers.SharedInformerFactory
|
||||
disableClusterScopeInformer bool
|
||||
|
||||
factoriesCrd map[string]traefikinformers.SharedInformerFactory
|
||||
factoriesKube map[string]kinformers.SharedInformerFactory
|
||||
factoriesSecret map[string]kinformers.SharedInformerFactory
|
||||
|
||||
labelSelector string
|
||||
|
||||
|
@ -237,18 +239,11 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<
|
|||
c.factoriesSecret[ns] = factorySecret
|
||||
}
|
||||
|
||||
c.factoryClusterScope = kinformers.NewSharedInformerFactory(c.csKube, resyncPeriod)
|
||||
_, err := c.factoryClusterScope.Core().V1().Nodes().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, ns := range namespaces {
|
||||
c.factoriesCrd[ns].Start(stopCh)
|
||||
c.factoriesKube[ns].Start(stopCh)
|
||||
c.factoriesSecret[ns].Start(stopCh)
|
||||
}
|
||||
c.factoryClusterScope.Start(stopCh)
|
||||
|
||||
for _, ns := range namespaces {
|
||||
for t, ok := range c.factoriesCrd[ns].WaitForCacheSync(stopCh) {
|
||||
|
@ -270,9 +265,19 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<
|
|||
}
|
||||
}
|
||||
|
||||
for t, ok := range c.factoryClusterScope.WaitForCacheSync(stopCh) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("timed out waiting for controller caches to sync %s", t.String())
|
||||
if !c.disableClusterScopeInformer {
|
||||
c.clusterScopeFactory = kinformers.NewSharedInformerFactory(c.csKube, resyncPeriod)
|
||||
_, err := c.clusterScopeFactory.Core().V1().Nodes().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.clusterScopeFactory.Start(stopCh)
|
||||
|
||||
for t, ok := range c.clusterScopeFactory.WaitForCacheSync(stopCh) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("timed out waiting for controller caches to sync %s", t.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,7 +479,7 @@ func (c *clientWrapper) GetSecret(namespace, name string) (*corev1.Secret, bool,
|
|||
}
|
||||
|
||||
func (c *clientWrapper) GetNodes() ([]*corev1.Node, bool, error) {
|
||||
nodes, err := c.factoryClusterScope.Core().V1().Nodes().Lister().List(labels.Everything())
|
||||
nodes, err := c.clusterScopeFactory.Core().V1().Nodes().Lister().List(labels.Everything())
|
||||
exist, err := translateNotFoundError(err)
|
||||
return nodes, exist, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue