New static configuration loading system.

Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
This commit is contained in:
Ludovic Fernandez 2019-06-17 11:48:05 +02:00 committed by Traefiker Bot
parent d18edd6f77
commit 8d7eccad5d
165 changed files with 10894 additions and 6076 deletions

View file

@ -10,7 +10,6 @@ import (
"github.com/containous/traefik/pkg/provider/kubernetes/crd/generated/clientset/versioned"
"github.com/containous/traefik/pkg/provider/kubernetes/crd/generated/informers/externalversions"
"github.com/containous/traefik/pkg/provider/kubernetes/crd/traefik/v1alpha1"
"github.com/containous/traefik/pkg/provider/kubernetes/k8s"
corev1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
kubeerror "k8s.io/apimachinery/pkg/api/errors"
@ -45,7 +44,7 @@ func (reh *resourceEventHandler) OnDelete(obj interface{}) {
// WatchAll starts the watch of the Provider resources and updates the stores.
// The stores can then be accessed via the Get* functions.
type Client interface {
WatchAll(namespaces k8s.Namespaces, stopCh <-chan struct{}) (<-chan interface{}, error)
WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error)
GetIngressRoutes() []*v1alpha1.IngressRoute
GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP
@ -69,7 +68,7 @@ type clientWrapper struct {
labelSelector labels.Selector
isNamespaceAll bool
watchedNamespaces k8s.Namespaces
watchedNamespaces []string
}
func createClientFromConfig(c *rest.Config) (*clientWrapper, error) {
@ -144,12 +143,12 @@ func newExternalClusterClient(endpoint, token, caFilePath string) (*clientWrappe
}
// WatchAll starts namespace-specific controllers for all relevant kinds.
func (c *clientWrapper) WatchAll(namespaces k8s.Namespaces, stopCh <-chan struct{}) (<-chan interface{}, error) {
func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error) {
eventCh := make(chan interface{}, 1)
eventHandler := c.newResourceEventHandler(eventCh)
if len(namespaces) == 0 {
namespaces = k8s.Namespaces{metav1.NamespaceAll}
namespaces = []string{metav1.NamespaceAll}
c.isNamespaceAll = true
}
c.watchedNamespaces = namespaces

View file

@ -132,7 +132,7 @@ func (c clientMock) GetSecret(namespace, name string) (*corev1.Secret, bool, err
return nil, false, nil
}
func (c clientMock) WatchAll(namespaces k8s.Namespaces, stopCh <-chan struct{}) (<-chan interface{}, error) {
func (c clientMock) WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error) {
return c.watchChan, nil
}

View file

@ -18,7 +18,6 @@ import (
"github.com/containous/traefik/pkg/job"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider/kubernetes/crd/traefik/v1alpha1"
"github.com/containous/traefik/pkg/provider/kubernetes/k8s"
"github.com/containous/traefik/pkg/safe"
"github.com/containous/traefik/pkg/tls"
corev1 "k8s.io/api/core/v1"
@ -32,13 +31,13 @@ const (
// Provider holds configurations of the provider.
type Provider struct {
Endpoint string `description:"Kubernetes server endpoint (required for external cluster client)"`
Token string `description:"Kubernetes bearer token (not needed for in-cluster client)"`
CertAuthFilePath string `description:"Kubernetes certificate authority file path (not needed for in-cluster client)"`
DisablePassHostHeaders bool `description:"Kubernetes disable PassHost Headers" export:"true"`
Namespaces k8s.Namespaces `description:"Kubernetes namespaces" export:"true"`
LabelSelector string `description:"Kubernetes label selector to use" export:"true"`
IngressClass string `description:"Value of kubernetes.io/ingress.class annotation to watch for" export:"true"`
Endpoint string `description:"Kubernetes server endpoint (required for external cluster client)."`
Token string `description:"Kubernetes bearer token (not needed for in-cluster client)."`
CertAuthFilePath string `description:"Kubernetes certificate authority file path (not needed for in-cluster client)."`
DisablePassHostHeaders bool `description:"Kubernetes disable PassHost Headers." export:"true"`
Namespaces []string `description:"Kubernetes namespaces." export:"true"`
LabelSelector string `description:"Kubernetes label selector to use." export:"true"`
IngressClass string `description:"Value of kubernetes.io/ingress.class annotation to watch for." export:"true"`
lastConfiguration safe.Safe
}

View file

@ -7,7 +7,6 @@ import (
"time"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider/kubernetes/k8s"
corev1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
kubeerror "k8s.io/apimachinery/pkg/api/errors"
@ -42,7 +41,7 @@ func (reh *resourceEventHandler) OnDelete(obj interface{}) {
// WatchAll starts the watch of the Provider resources and updates the stores.
// The stores can then be accessed via the Get* functions.
type Client interface {
WatchAll(namespaces k8s.Namespaces, stopCh <-chan struct{}) (<-chan interface{}, error)
WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error)
GetIngresses() []*extensionsv1beta1.Ingress
GetService(namespace, name string) (*corev1.Service, bool, error)
GetSecret(namespace, name string) (*corev1.Secret, bool, error)
@ -55,7 +54,7 @@ type clientWrapper struct {
factories map[string]informers.SharedInformerFactory
ingressLabelSelector labels.Selector
isNamespaceAll bool
watchedNamespaces k8s.Namespaces
watchedNamespaces []string
}
// newInClusterClient returns a new Provider client that is expected to run
@ -122,12 +121,12 @@ func newClientImpl(clientset *kubernetes.Clientset) *clientWrapper {
}
// WatchAll starts namespace-specific controllers for all relevant kinds.
func (c *clientWrapper) WatchAll(namespaces k8s.Namespaces, stopCh <-chan struct{}) (<-chan interface{}, error) {
func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error) {
eventCh := make(chan interface{}, 1)
eventHandler := c.newResourceEventHandler(eventCh)
if len(namespaces) == 0 {
namespaces = k8s.Namespaces{metav1.NamespaceAll}
namespaces = []string{metav1.NamespaceAll}
c.isNamespaceAll = true
}

View file

@ -99,7 +99,7 @@ func (c clientMock) GetSecret(namespace, name string) (*corev1.Secret, bool, err
return nil, false, nil
}
func (c clientMock) WatchAll(namespaces k8s.Namespaces, stopCh <-chan struct{}) (<-chan interface{}, error) {
func (c clientMock) WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error) {
return c.watchChan, nil
}

View file

@ -17,7 +17,6 @@ import (
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/job"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider/kubernetes/k8s"
"github.com/containous/traefik/pkg/safe"
"github.com/containous/traefik/pkg/tls"
corev1 "k8s.io/api/core/v1"
@ -33,22 +32,22 @@ const (
// Provider holds configurations of the provider.
type Provider struct {
Endpoint string `description:"Kubernetes server endpoint (required for external cluster client)"`
Token string `description:"Kubernetes bearer token (not needed for in-cluster client)"`
CertAuthFilePath string `description:"Kubernetes certificate authority file path (not needed for in-cluster client)"`
DisablePassHostHeaders bool `description:"Kubernetes disable PassHost Headers" export:"true"`
Namespaces k8s.Namespaces `description:"Kubernetes namespaces" export:"true"`
LabelSelector string `description:"Kubernetes Ingress label selector to use" export:"true"`
IngressClass string `description:"Value of kubernetes.io/ingress.class annotation to watch for" export:"true"`
IngressEndpoint *EndpointIngress `description:"Kubernetes Ingress Endpoint"`
Endpoint string `description:"Kubernetes server endpoint (required for external cluster client)."`
Token string `description:"Kubernetes bearer token (not needed for in-cluster client)."`
CertAuthFilePath string `description:"Kubernetes certificate authority file path (not needed for in-cluster client)."`
DisablePassHostHeaders bool `description:"Kubernetes disable PassHost Headers." export:"true"`
Namespaces []string `description:"Kubernetes namespaces." export:"true"`
LabelSelector string `description:"Kubernetes Ingress label selector to use." export:"true"`
IngressClass string `description:"Value of kubernetes.io/ingress.class annotation to watch for." export:"true"`
IngressEndpoint *EndpointIngress `description:"Kubernetes Ingress Endpoint."`
lastConfiguration safe.Safe
}
// EndpointIngress holds the endpoint information for the Kubernetes provider
type EndpointIngress struct {
IP string `description:"IP used for Kubernetes Ingress endpoints"`
Hostname string `description:"Hostname used for Kubernetes Ingress endpoints"`
PublishedService string `description:"Published Kubernetes Service to copy status from"`
IP string `description:"IP used for Kubernetes Ingress endpoints."`
Hostname string `description:"Hostname used for Kubernetes Ingress endpoints."`
PublishedService string `description:"Published Kubernetes Service to copy status from."`
}
func (p *Provider) newK8sClient(ctx context.Context, ingressLabelSelector string) (*clientWrapper, error) {

View file

@ -1,32 +0,0 @@
package k8s
import (
"fmt"
"strings"
)
// Namespaces holds kubernetes namespaces.
type Namespaces []string
// Set adds strings elem into the the parser
// it splits str on , and ;.
func (ns *Namespaces) Set(str string) error {
fargs := func(c rune) bool {
return c == ',' || c == ';'
}
// get function
slice := strings.FieldsFunc(str, fargs)
*ns = append(*ns, slice...)
return nil
}
// Get []string.
func (ns *Namespaces) Get() interface{} { return *ns }
// String return slice in a string.
func (ns *Namespaces) String() string { return fmt.Sprintf("%v", *ns) }
// SetValue sets []string into the parser.
func (ns *Namespaces) SetValue(val interface{}) {
*ns = val.(Namespaces)
}