"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/provider/kubernetes/crd/client.go" between
traefik-v2.3.2.src.tar.gz and traefik-v2.3.3.src.tar.gz

About: Traefik is a cloud native edge router, a reverse proxy and load balancer for HTTP and TCP-based applications.

client.go  (traefik-v2.3.2.src):client.go  (traefik-v2.3.3.src)
skipping to change at line 64 skipping to change at line 64
GetTLSOptions() []*v1alpha1.TLSOption GetTLSOptions() []*v1alpha1.TLSOption
GetTLSStores() []*v1alpha1.TLSStore GetTLSStores() []*v1alpha1.TLSStore
GetService(namespace, name string) (*corev1.Service, bool, error) GetService(namespace, name string) (*corev1.Service, bool, error)
GetSecret(namespace, name string) (*corev1.Secret, bool, error) GetSecret(namespace, name string) (*corev1.Secret, bool, error)
GetEndpoints(namespace, name string) (*corev1.Endpoints, bool, error) GetEndpoints(namespace, name string) (*corev1.Endpoints, bool, error)
} }
// TODO: add tests for the clientWrapper (and its methods) itself. // TODO: add tests for the clientWrapper (and its methods) itself.
type clientWrapper struct { type clientWrapper struct {
csCrd *versioned.Clientset csCrd versioned.Interface
csKube *kubernetes.Clientset csKube kubernetes.Interface
factoriesCrd map[string]externalversions.SharedInformerFactory factoriesCrd map[string]externalversions.SharedInformerFactory
factoriesKube map[string]informers.SharedInformerFactory factoriesKube map[string]informers.SharedInformerFactory
factoriesSecret map[string]informers.SharedInformerFactory
labelSelector labels.Selector labelSelector labels.Selector
isNamespaceAll bool isNamespaceAll bool
watchedNamespaces []string watchedNamespaces []string
} }
func createClientFromConfig(c *rest.Config) (*clientWrapper, error) { func createClientFromConfig(c *rest.Config) (*clientWrapper, error) {
csCrd, err := versioned.NewForConfig(c) csCrd, err := versioned.NewForConfig(c)
if err != nil { if err != nil {
skipping to change at line 90 skipping to change at line 91
} }
csKube, err := kubernetes.NewForConfig(c) csKube, err := kubernetes.NewForConfig(c)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return newClientImpl(csKube, csCrd), nil return newClientImpl(csKube, csCrd), nil
} }
func newClientImpl(csKube *kubernetes.Clientset, csCrd *versioned.Clientset) *cl ientWrapper { func newClientImpl(csKube kubernetes.Interface, csCrd versioned.Interface) *clie ntWrapper {
return &clientWrapper{ return &clientWrapper{
csCrd: csCrd, csCrd: csCrd,
csKube: csKube, csKube: csKube,
factoriesCrd: make(map[string]externalversions.SharedInformerFac factoriesCrd: make(map[string]externalversions.SharedInformerF
tory), actory),
factoriesKube: make(map[string]informers.SharedInformerFactory), factoriesKube: make(map[string]informers.SharedInformerFactory)
,
factoriesSecret: make(map[string]informers.SharedInformerFactory)
,
} }
} }
// newInClusterClient returns a new Provider client that is expected to run // newInClusterClient returns a new Provider client that is expected to run
// inside the cluster. // inside the cluster.
func newInClusterClient(endpoint string) (*clientWrapper, error) { func newInClusterClient(endpoint string) (*clientWrapper, error) {
config, err := rest.InClusterConfig() config, err := rest.InClusterConfig()
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create in-cluster configuration : %w", err) return nil, fmt.Errorf("failed to create in-cluster configuration : %w", err)
} }
skipping to change at line 158 skipping to change at line 160
func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (< -chan interface{}, error) { func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (< -chan interface{}, error) {
eventCh := make(chan interface{}, 1) eventCh := make(chan interface{}, 1)
eventHandler := c.newResourceEventHandler(eventCh) eventHandler := c.newResourceEventHandler(eventCh)
if len(namespaces) == 0 { if len(namespaces) == 0 {
namespaces = []string{metav1.NamespaceAll} namespaces = []string{metav1.NamespaceAll}
c.isNamespaceAll = true c.isNamespaceAll = true
} }
c.watchedNamespaces = namespaces c.watchedNamespaces = namespaces
notOwnedByHelm := func(opts *metav1.ListOptions) {
opts.LabelSelector = "owner!=helm"
}
for _, ns := range namespaces { for _, ns := range namespaces {
factoryCrd := externalversions.NewSharedInformerFactoryWithOption s(c.csCrd, resyncPeriod, externalversions.WithNamespace(ns)) factoryCrd := externalversions.NewSharedInformerFactoryWithOption s(c.csCrd, resyncPeriod, externalversions.WithNamespace(ns))
factoryCrd.Traefik().V1alpha1().IngressRoutes().Informer().AddEve ntHandler(eventHandler) factoryCrd.Traefik().V1alpha1().IngressRoutes().Informer().AddEve ntHandler(eventHandler)
factoryCrd.Traefik().V1alpha1().Middlewares().Informer().AddEvent Handler(eventHandler) factoryCrd.Traefik().V1alpha1().Middlewares().Informer().AddEvent Handler(eventHandler)
factoryCrd.Traefik().V1alpha1().IngressRouteTCPs().Informer().Add EventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().IngressRouteTCPs().Informer().Add EventHandler(eventHandler)
factoryCrd.Traefik().V1alpha1().IngressRouteUDPs().Informer().Add EventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().IngressRouteUDPs().Informer().Add EventHandler(eventHandler)
factoryCrd.Traefik().V1alpha1().TLSOptions().Informer().AddEventH andler(eventHandler) factoryCrd.Traefik().V1alpha1().TLSOptions().Informer().AddEventH andler(eventHandler)
factoryCrd.Traefik().V1alpha1().TLSStores().Informer().AddEventHa ndler(eventHandler) factoryCrd.Traefik().V1alpha1().TLSStores().Informer().AddEventHa ndler(eventHandler)
factoryCrd.Traefik().V1alpha1().TraefikServices().Informer().AddE ventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().TraefikServices().Informer().AddE ventHandler(eventHandler)
factoryKube := informers.NewSharedInformerFactoryWithOptions(c.cs Kube, resyncPeriod, informers.WithNamespace(ns)) factoryKube := informers.NewSharedInformerFactoryWithOptions(c.cs Kube, resyncPeriod, informers.WithNamespace(ns))
factoryKube.Extensions().V1beta1().Ingresses().Informer().AddEven tHandler(eventHandler) factoryKube.Extensions().V1beta1().Ingresses().Informer().AddEven tHandler(eventHandler)
factoryKube.Core().V1().Services().Informer().AddEventHandler(eve ntHandler) factoryKube.Core().V1().Services().Informer().AddEventHandler(eve ntHandler)
factoryKube.Core().V1().Endpoints().Informer().AddEventHandler(ev entHandler) factoryKube.Core().V1().Endpoints().Informer().AddEventHandler(ev entHandler)
factoryKube.Core().V1().Secrets().Informer().AddEventHandler(even
tHandler) factorySecret := informers.NewSharedInformerFactoryWithOptions(c.
csKube, resyncPeriod, informers.WithNamespace(ns), informers.WithTweakListOption
s(notOwnedByHelm))
factorySecret.Core().V1().Secrets().Informer().AddEventHandler(ev
entHandler)
c.factoriesCrd[ns] = factoryCrd c.factoriesCrd[ns] = factoryCrd
c.factoriesKube[ns] = factoryKube c.factoriesKube[ns] = factoryKube
c.factoriesSecret[ns] = factorySecret
} }
for _, ns := range namespaces { for _, ns := range namespaces {
c.factoriesCrd[ns].Start(stopCh) c.factoriesCrd[ns].Start(stopCh)
c.factoriesKube[ns].Start(stopCh) c.factoriesKube[ns].Start(stopCh)
c.factoriesSecret[ns].Start(stopCh)
} }
for _, ns := range namespaces { for _, ns := range namespaces {
for t, ok := range c.factoriesCrd[ns].WaitForCacheSync(stopCh) { for t, ok := range c.factoriesCrd[ns].WaitForCacheSync(stopCh) {
if !ok { if !ok {
return nil, fmt.Errorf("timed out waiting for con troller caches to sync %s in namespace %q", t.String(), ns) return nil, fmt.Errorf("timed out waiting for con troller caches to sync %s in namespace %q", t.String(), ns)
} }
} }
for t, ok := range c.factoriesKube[ns].WaitForCacheSync(stopCh) { for t, ok := range c.factoriesKube[ns].WaitForCacheSync(stopCh) {
if !ok { if !ok {
return nil, fmt.Errorf("timed out waiting for con troller caches to sync %s in namespace %q", t.String(), ns) return nil, fmt.Errorf("timed out waiting for con troller caches to sync %s in namespace %q", t.String(), ns)
} }
} }
for t, ok := range c.factoriesSecret[ns].WaitForCacheSync(stopCh)
{
if !ok {
return nil, fmt.Errorf("timed out waiting for con
troller caches to sync %s in namespace %q", t.String(), ns)
}
}
} }
return eventCh, nil return eventCh, nil
} }
func (c *clientWrapper) GetIngressRoutes() []*v1alpha1.IngressRoute { func (c *clientWrapper) GetIngressRoutes() []*v1alpha1.IngressRoute {
var result []*v1alpha1.IngressRoute var result []*v1alpha1.IngressRoute
for ns, factory := range c.factoriesCrd { for ns, factory := range c.factoriesCrd {
ings, err := factory.Traefik().V1alpha1().IngressRoutes().Lister( ).List(c.labelSelector) ings, err := factory.Traefik().V1alpha1().IngressRoutes().Lister( ).List(c.labelSelector)
skipping to change at line 340 skipping to change at line 356
exist, err := translateNotFoundError(err) exist, err := translateNotFoundError(err)
return endpoint, exist, err return endpoint, exist, err
} }
// GetSecret returns the named secret from the given namespace. // GetSecret returns the named secret from the given namespace.
func (c *clientWrapper) GetSecret(namespace, name string) (*corev1.Secret, bool, error) { func (c *clientWrapper) GetSecret(namespace, name string) (*corev1.Secret, bool, error) {
if !c.isWatchedNamespace(namespace) { if !c.isWatchedNamespace(namespace) {
return nil, false, fmt.Errorf("failed to get secret %s/%s: namesp ace is not within watched namespaces", namespace, name) return nil, false, fmt.Errorf("failed to get secret %s/%s: namesp ace is not within watched namespaces", namespace, name)
} }
secret, err := c.factoriesKube[c.lookupNamespace(namespace)].Core().V1(). Secrets().Lister().Secrets(namespace).Get(name) secret, err := c.factoriesSecret[c.lookupNamespace(namespace)].Core().V1( ).Secrets().Lister().Secrets(namespace).Get(name)
exist, err := translateNotFoundError(err) exist, err := translateNotFoundError(err)
return secret, exist, err return secret, exist, err
} }
// lookupNamespace returns the lookup namespace key for the given namespace. // lookupNamespace returns the lookup namespace key for the given namespace.
// When listening on all namespaces, it returns the client-go identifier ("") // When listening on all namespaces, it returns the client-go identifier ("")
// for all-namespaces. Otherwise, it returns the given namespace. // for all-namespaces. Otherwise, it returns the given namespace.
// The distinction is necessary because we index all informers on the special // The distinction is necessary because we index all informers on the special
// identifier iff all-namespaces are requested but receive specific namespace // identifier iff all-namespaces are requested but receive specific namespace
// identifiers from the Kubernetes API, so we have to bridge this gap. // identifiers from the Kubernetes API, so we have to bridge this gap.
 End of changes. 10 change blocks. 
13 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)