Introduce traefik.io API Group CRDs

This commit is contained in:
Romain 2023-03-20 15:38:08 +01:00 committed by GitHub
parent b3f162a8a6
commit 7af9d16208
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
298 changed files with 16218 additions and 582 deletions

View file

@ -11,7 +11,7 @@ import (
"github.com/traefik/traefik/v2/pkg/log"
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned"
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/informers/externalversions"
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/k8s"
"github.com/traefik/traefik/v2/pkg/version"
corev1 "k8s.io/api/core/v1"
@ -173,6 +173,8 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<
factoryCrd.Traefik().V1alpha1().TLSStores().Informer().AddEventHandler(eventHandler)
factoryCrd.Traefik().V1alpha1().TraefikServices().Informer().AddEventHandler(eventHandler)
addContainousInformers(factoryCrd, eventHandler)
factoryKube := informers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, informers.WithNamespace(ns))
factoryKube.Core().V1().Services().Informer().AddEventHandler(eventHandler)
factoryKube.Core().V1().Endpoints().Informer().AddEventHandler(eventHandler)
@ -225,7 +227,7 @@ func (c *clientWrapper) GetIngressRoutes() []*v1alpha1.IngressRoute {
result = append(result, ings...)
}
return result
return c.appendContainousIngressRoutes(result)
}
func (c *clientWrapper) GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP {
@ -239,7 +241,7 @@ func (c *clientWrapper) GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP {
result = append(result, ings...)
}
return result
return c.appendContainousIngressRouteTCPs(result)
}
func (c *clientWrapper) GetIngressRouteUDPs() []*v1alpha1.IngressRouteUDP {
@ -253,7 +255,7 @@ func (c *clientWrapper) GetIngressRouteUDPs() []*v1alpha1.IngressRouteUDP {
result = append(result, ings...)
}
return result
return c.appendContainousIngressRouteUDPs(result)
}
func (c *clientWrapper) GetMiddlewares() []*v1alpha1.Middleware {
@ -267,7 +269,7 @@ func (c *clientWrapper) GetMiddlewares() []*v1alpha1.Middleware {
result = append(result, middlewares...)
}
return result
return c.appendContainousMiddlewares(result)
}
func (c *clientWrapper) GetMiddlewareTCPs() []*v1alpha1.MiddlewareTCP {
@ -281,7 +283,7 @@ func (c *clientWrapper) GetMiddlewareTCPs() []*v1alpha1.MiddlewareTCP {
result = append(result, middlewares...)
}
return result
return c.appendContainousMiddlewareTCPs(result)
}
// GetTraefikService returns the named service from the given namespace.
@ -293,6 +295,10 @@ func (c *clientWrapper) GetTraefikService(namespace, name string) (*v1alpha1.Tra
service, err := c.factoriesCrd[c.lookupNamespace(namespace)].Traefik().V1alpha1().TraefikServices().Lister().TraefikServices(namespace).Get(name)
exist, err := translateNotFoundError(err)
if !exist {
return c.getContainousTraefikService(namespace, name)
}
return service, exist, err
}
@ -300,17 +306,17 @@ func (c *clientWrapper) GetTraefikServices() []*v1alpha1.TraefikService {
var result []*v1alpha1.TraefikService
for ns, factory := range c.factoriesCrd {
ings, err := factory.Traefik().V1alpha1().TraefikServices().Lister().List(labels.Everything())
traefikServices, err := factory.Traefik().V1alpha1().TraefikServices().Lister().List(labels.Everything())
if err != nil {
log.Errorf("Failed to list Traefik services in namespace %s: %v", ns, err)
}
result = append(result, ings...)
result = append(result, traefikServices...)
}
return result
return c.appendContainousTraefikServices(result)
}
// GetServersTransport returns all ServersTransport.
// GetServersTransports returns all ServersTransport.
func (c *clientWrapper) GetServersTransports() []*v1alpha1.ServersTransport {
var result []*v1alpha1.ServersTransport
@ -322,7 +328,7 @@ func (c *clientWrapper) GetServersTransports() []*v1alpha1.ServersTransport {
result = append(result, serversTransports...)
}
return result
return c.appendContainousServersTransport(result)
}
// GetTLSOptions returns all TLS options.
@ -337,7 +343,7 @@ func (c *clientWrapper) GetTLSOptions() []*v1alpha1.TLSOption {
result = append(result, options...)
}
return result
return c.appendContainousTLSOptions(result)
}
// GetTLSStores returns all TLS stores.
@ -352,7 +358,7 @@ func (c *clientWrapper) GetTLSStores() []*v1alpha1.TLSStore {
result = append(result, stores...)
}
return result
return c.appendContainousTLSStores(result)
}
// GetService returns the named service from the given namespace.
@ -401,15 +407,6 @@ func (c *clientWrapper) lookupNamespace(ns string) string {
return ns
}
// translateNotFoundError will translate a "not found" error to a boolean return
// value which indicates if the resource exists and a nil error.
func translateNotFoundError(err error) (bool, error) {
if kubeerror.IsNotFound(err) {
return false, nil
}
return err == nil, err
}
// isWatchedNamespace checks to ensure that the namespace is being watched before we request
// it to ensure we don't panic by requesting an out-of-watch object.
func (c *clientWrapper) isWatchedNamespace(ns string) bool {
@ -423,3 +420,12 @@ func (c *clientWrapper) isWatchedNamespace(ns string) bool {
}
return false
}
// translateNotFoundError will translate a "not found" error to a boolean return
// value which indicates if the resource exists and a nil error.
func translateNotFoundError(err error) (bool, error) {
if kubeerror.IsNotFound(err) {
return false, nil
}
return err == nil, err
}