New logger for the Traefik logs
This commit is contained in:
parent
27c02b5a56
commit
56f7515ecd
297 changed files with 2337 additions and 1934 deletions
|
@ -8,7 +8,7 @@ import (
|
|||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/rs/zerolog/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"
|
||||
|
@ -220,7 +220,7 @@ func (c *clientWrapper) GetIngressRoutes() []*v1alpha1.IngressRoute {
|
|||
for ns, factory := range c.factoriesCrd {
|
||||
ings, err := factory.Traefik().V1alpha1().IngressRoutes().Lister().List(labels.Everything())
|
||||
if err != nil {
|
||||
log.Errorf("Failed to list ingress routes in namespace %s: %v", ns, err)
|
||||
log.Error().Err(err).Msgf("Failed to list ingress routes in namespace %s", ns)
|
||||
}
|
||||
result = append(result, ings...)
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ func (c *clientWrapper) GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP {
|
|||
for ns, factory := range c.factoriesCrd {
|
||||
ings, err := factory.Traefik().V1alpha1().IngressRouteTCPs().Lister().List(labels.Everything())
|
||||
if err != nil {
|
||||
log.Errorf("Failed to list tcp ingress routes in namespace %s: %v", ns, err)
|
||||
log.Error().Err(err).Msgf("Failed to list tcp ingress routes in namespace %s", ns)
|
||||
}
|
||||
result = append(result, ings...)
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ func (c *clientWrapper) GetIngressRouteUDPs() []*v1alpha1.IngressRouteUDP {
|
|||
for ns, factory := range c.factoriesCrd {
|
||||
ings, err := factory.Traefik().V1alpha1().IngressRouteUDPs().Lister().List(labels.Everything())
|
||||
if err != nil {
|
||||
log.Errorf("Failed to list udp ingress routes in namespace %s: %v", ns, err)
|
||||
log.Error().Err(err).Msgf("Failed to list udp ingress routes in namespace %s", ns)
|
||||
}
|
||||
result = append(result, ings...)
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ func (c *clientWrapper) GetMiddlewares() []*v1alpha1.Middleware {
|
|||
for ns, factory := range c.factoriesCrd {
|
||||
middlewares, err := factory.Traefik().V1alpha1().Middlewares().Lister().List(labels.Everything())
|
||||
if err != nil {
|
||||
log.Errorf("Failed to list middlewares in namespace %s: %v", ns, err)
|
||||
log.Error().Err(err).Msgf("Failed to list middlewares in namespace %s", ns)
|
||||
}
|
||||
result = append(result, middlewares...)
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ func (c *clientWrapper) GetMiddlewareTCPs() []*v1alpha1.MiddlewareTCP {
|
|||
for ns, factory := range c.factoriesCrd {
|
||||
middlewares, err := factory.Traefik().V1alpha1().MiddlewareTCPs().Lister().List(labels.Everything())
|
||||
if err != nil {
|
||||
log.Errorf("Failed to list TCP middlewares in namespace %s: %v", ns, err)
|
||||
log.Error().Err(err).Msgf("Failed to list TCP middlewares in namespace %s", ns)
|
||||
}
|
||||
result = append(result, middlewares...)
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ func (c *clientWrapper) GetTraefikServices() []*v1alpha1.TraefikService {
|
|||
for ns, factory := range c.factoriesCrd {
|
||||
ings, 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)
|
||||
log.Error().Err(err).Msgf("Failed to list Traefik services in namespace %s", ns)
|
||||
}
|
||||
result = append(result, ings...)
|
||||
}
|
||||
|
@ -310,14 +310,14 @@ func (c *clientWrapper) GetTraefikServices() []*v1alpha1.TraefikService {
|
|||
return result
|
||||
}
|
||||
|
||||
// GetServersTransport returns all ServersTransport.
|
||||
// GetServersTransports returns all ServersTransport.
|
||||
func (c *clientWrapper) GetServersTransports() []*v1alpha1.ServersTransport {
|
||||
var result []*v1alpha1.ServersTransport
|
||||
|
||||
for ns, factory := range c.factoriesCrd {
|
||||
serversTransports, err := factory.Traefik().V1alpha1().ServersTransports().Lister().List(labels.Everything())
|
||||
if err != nil {
|
||||
log.Errorf("Failed to list servers transport in namespace %s: %v", ns, err)
|
||||
log.Error().Err(err).Msgf("Failed to list servers transport in namespace %s", ns)
|
||||
}
|
||||
result = append(result, serversTransports...)
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ func (c *clientWrapper) GetTLSOptions() []*v1alpha1.TLSOption {
|
|||
for ns, factory := range c.factoriesCrd {
|
||||
options, err := factory.Traefik().V1alpha1().TLSOptions().Lister().List(labels.Everything())
|
||||
if err != nil {
|
||||
log.Errorf("Failed to list tls options in namespace %s: %v", ns, err)
|
||||
log.Error().Err(err).Msgf("Failed to list tls options in namespace %s", ns)
|
||||
}
|
||||
result = append(result, options...)
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ func (c *clientWrapper) GetTLSStores() []*v1alpha1.TLSStore {
|
|||
for ns, factory := range c.factoriesCrd {
|
||||
stores, err := factory.Traefik().V1alpha1().TLSStores().Lister().List(labels.Everything())
|
||||
if err != nil {
|
||||
log.Errorf("Failed to list tls stores in namespace %s: %v", ns, err)
|
||||
log.Error().Err(err).Msgf("Failed to list tls stores in namespace %s", ns)
|
||||
}
|
||||
result = append(result, stores...)
|
||||
}
|
||||
|
|
|
@ -17,10 +17,11 @@ import (
|
|||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/mitchellh/hashstructure"
|
||||
"github.com/rs/zerolog/log"
|
||||
ptypes "github.com/traefik/paerser/types"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/job"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/logs"
|
||||
"github.com/traefik/traefik/v2/pkg/provider"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/pkg/safe"
|
||||
|
@ -62,7 +63,7 @@ func (p *Provider) newK8sClient(ctx context.Context) (*clientWrapper, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid label selector: %q", p.LabelSelector)
|
||||
}
|
||||
log.FromContext(ctx).Infof("label selector is: %q", p.LabelSelector)
|
||||
log.Ctx(ctx).Info().Msgf("label selector is: %q", p.LabelSelector)
|
||||
|
||||
withEndpoint := ""
|
||||
if p.Endpoint != "" {
|
||||
|
@ -72,13 +73,13 @@ func (p *Provider) newK8sClient(ctx context.Context) (*clientWrapper, error) {
|
|||
var client *clientWrapper
|
||||
switch {
|
||||
case os.Getenv("KUBERNETES_SERVICE_HOST") != "" && os.Getenv("KUBERNETES_SERVICE_PORT") != "":
|
||||
log.FromContext(ctx).Infof("Creating in-cluster Provider client%s", withEndpoint)
|
||||
log.Ctx(ctx).Info().Msgf("Creating in-cluster Provider client%s", withEndpoint)
|
||||
client, err = newInClusterClient(p.Endpoint)
|
||||
case os.Getenv("KUBECONFIG") != "":
|
||||
log.FromContext(ctx).Infof("Creating cluster-external Provider client from KUBECONFIG %s", os.Getenv("KUBECONFIG"))
|
||||
log.Ctx(ctx).Info().Msgf("Creating cluster-external Provider client from KUBECONFIG %s", os.Getenv("KUBECONFIG"))
|
||||
client, err = newExternalClusterClientFromFile(os.Getenv("KUBECONFIG"))
|
||||
default:
|
||||
log.FromContext(ctx).Infof("Creating cluster-external Provider client%s", withEndpoint)
|
||||
log.Ctx(ctx).Info().Msgf("Creating cluster-external Provider client%s", withEndpoint)
|
||||
client, err = newExternalClusterClient(p.Endpoint, p.Token, p.CertAuthFilePath)
|
||||
}
|
||||
|
||||
|
@ -98,8 +99,8 @@ func (p *Provider) Init() error {
|
|||
// Provide allows the k8s provider to provide configurations to traefik
|
||||
// using the given configuration channel.
|
||||
func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error {
|
||||
ctxLog := log.With(context.Background(), log.Str(log.ProviderName, providerName))
|
||||
logger := log.FromContext(ctxLog)
|
||||
logger := log.With().Str(logs.ProviderName, providerName).Logger()
|
||||
ctxLog := logger.WithContext(context.Background())
|
||||
|
||||
k8sClient, err := p.newK8sClient(ctxLog)
|
||||
if err != nil {
|
||||
|
@ -107,18 +108,18 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.
|
|||
}
|
||||
|
||||
if p.AllowCrossNamespace {
|
||||
logger.Warn("Cross-namespace reference between IngressRoutes and resources is enabled, please ensure that this is expected (see AllowCrossNamespace option)")
|
||||
logger.Warn().Msg("Cross-namespace reference between IngressRoutes and resources is enabled, please ensure that this is expected (see AllowCrossNamespace option)")
|
||||
}
|
||||
|
||||
if p.AllowExternalNameServices {
|
||||
logger.Warn("ExternalName service loading is enabled, please ensure that this is expected (see AllowExternalNameServices option)")
|
||||
logger.Warn().Msg("ExternalName service loading is enabled, please ensure that this is expected (see AllowExternalNameServices option)")
|
||||
}
|
||||
|
||||
pool.GoCtx(func(ctxPool context.Context) {
|
||||
operation := func() error {
|
||||
eventsChan, err := k8sClient.WatchAll(p.Namespaces, ctxPool.Done())
|
||||
if err != nil {
|
||||
logger.Errorf("Error watching kubernetes events: %v", err)
|
||||
logger.Error().Err(err).Msg("Error watching kubernetes events")
|
||||
timer := time.NewTimer(1 * time.Second)
|
||||
select {
|
||||
case <-timer.C:
|
||||
|
@ -147,9 +148,9 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.
|
|||
confHash, err := hashstructure.Hash(conf, nil)
|
||||
switch {
|
||||
case err != nil:
|
||||
logger.Error("Unable to hash the configuration")
|
||||
logger.Error().Err(err).Msg("Unable to hash the configuration")
|
||||
case p.lastConfiguration.Get() == confHash:
|
||||
logger.Debugf("Skipping Kubernetes event kind %T", event)
|
||||
logger.Debug().Msgf("Skipping Kubernetes event kind %T", event)
|
||||
default:
|
||||
p.lastConfiguration.Set(confHash)
|
||||
configurationChan <- dynamic.Message{
|
||||
|
@ -167,11 +168,11 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.
|
|||
}
|
||||
|
||||
notify := func(err error, time time.Duration) {
|
||||
logger.Errorf("Provider connection error: %v; retrying in %s", err, time)
|
||||
logger.Error().Err(err).Msgf("Provider connection error, retrying in %s", time)
|
||||
}
|
||||
err := backoff.RetryNotify(safe.OperationWithRecover(operation), backoff.WithContext(job.NewBackOff(backoff.NewExponentialBackOff()), ctxPool), notify)
|
||||
if err != nil {
|
||||
logger.Errorf("Cannot connect to Provider: %v", err)
|
||||
logger.Error().Err(err).Msg("Cannot connect to Provider")
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -200,29 +201,30 @@ func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client)
|
|||
|
||||
for _, middleware := range client.GetMiddlewares() {
|
||||
id := provider.Normalize(makeID(middleware.Namespace, middleware.Name))
|
||||
ctxMid := log.With(ctx, log.Str(log.MiddlewareName, id))
|
||||
logger := log.Ctx(ctx).With().Str(logs.MiddlewareName, id).Logger()
|
||||
ctxMid := logger.WithContext(ctx)
|
||||
|
||||
basicAuth, err := createBasicAuthMiddleware(client, middleware.Namespace, middleware.Spec.BasicAuth)
|
||||
if err != nil {
|
||||
log.FromContext(ctxMid).Errorf("Error while reading basic auth middleware: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading basic auth middleware")
|
||||
continue
|
||||
}
|
||||
|
||||
digestAuth, err := createDigestAuthMiddleware(client, middleware.Namespace, middleware.Spec.DigestAuth)
|
||||
if err != nil {
|
||||
log.FromContext(ctxMid).Errorf("Error while reading digest auth middleware: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading digest auth middleware")
|
||||
continue
|
||||
}
|
||||
|
||||
forwardAuth, err := createForwardAuthMiddleware(client, middleware.Namespace, middleware.Spec.ForwardAuth)
|
||||
if err != nil {
|
||||
log.FromContext(ctxMid).Errorf("Error while reading forward auth middleware: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading forward auth middleware")
|
||||
continue
|
||||
}
|
||||
|
||||
errorPage, errorPageService, err := p.createErrorPageMiddleware(client, middleware.Namespace, middleware.Spec.Errors)
|
||||
if err != nil {
|
||||
log.FromContext(ctxMid).Errorf("Error while reading error page middleware: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading error page middleware")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -234,25 +236,25 @@ func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client)
|
|||
|
||||
plugin, err := createPluginMiddleware(client, middleware.Namespace, middleware.Spec.Plugin)
|
||||
if err != nil {
|
||||
log.FromContext(ctxMid).Errorf("Error while reading plugins middleware: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading plugins middleware")
|
||||
continue
|
||||
}
|
||||
|
||||
rateLimit, err := createRateLimitMiddleware(middleware.Spec.RateLimit)
|
||||
if err != nil {
|
||||
log.FromContext(ctxMid).Errorf("Error while reading rateLimit middleware: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading rateLimit middleware")
|
||||
continue
|
||||
}
|
||||
|
||||
retry, err := createRetryMiddleware(middleware.Spec.Retry)
|
||||
if err != nil {
|
||||
log.FromContext(ctxMid).Errorf("Error while reading retry middleware: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading retry middleware")
|
||||
continue
|
||||
}
|
||||
|
||||
circuitBreaker, err := createCircuitBreakerMiddleware(middleware.Spec.CircuitBreaker)
|
||||
if err != nil {
|
||||
log.FromContext(ctxMid).Errorf("Error while reading circuit breaker middleware: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading circuit breaker middleware")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -298,20 +300,20 @@ func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client)
|
|||
for _, service := range client.GetTraefikServices() {
|
||||
err := cb.buildTraefikService(ctx, service, conf.HTTP.Services)
|
||||
if err != nil {
|
||||
log.FromContext(ctx).WithField(log.ServiceName, service.Name).
|
||||
Errorf("Error while building TraefikService: %v", err)
|
||||
log.Ctx(ctx).Error().Str(logs.ServiceName, service.Name).Err(err).
|
||||
Msg("Error while building TraefikService")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
for _, serversTransport := range client.GetServersTransports() {
|
||||
logger := log.FromContext(ctx).WithField(log.ServersTransportName, serversTransport.Name)
|
||||
logger := log.Ctx(ctx).With().Str(logs.ServersTransportName, serversTransport.Name).Logger()
|
||||
|
||||
var rootCAs []tls.FileOrContent
|
||||
for _, secret := range serversTransport.Spec.RootCAsSecrets {
|
||||
caSecret, err := loadCASecret(serversTransport.Namespace, secret, client)
|
||||
if err != nil {
|
||||
logger.Errorf("Error while loading rootCAs %s: %v", secret, err)
|
||||
logger.Error().Err(err).Msgf("Error while loading rootCAs %s", secret)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -322,7 +324,7 @@ func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client)
|
|||
for _, secret := range serversTransport.Spec.CertificatesSecrets {
|
||||
tlsSecret, tlsKey, err := loadAuthTLSSecret(serversTransport.Namespace, secret, client)
|
||||
if err != nil {
|
||||
logger.Errorf("Error while loading certificates %s: %v", secret, err)
|
||||
logger.Error().Err(err).Msgf("Error while loading certificates %s", secret)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -339,35 +341,35 @@ func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client)
|
|||
if serversTransport.Spec.ForwardingTimeouts.DialTimeout != nil {
|
||||
err := forwardingTimeout.DialTimeout.Set(serversTransport.Spec.ForwardingTimeouts.DialTimeout.String())
|
||||
if err != nil {
|
||||
logger.Errorf("Error while reading DialTimeout: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading DialTimeout")
|
||||
}
|
||||
}
|
||||
|
||||
if serversTransport.Spec.ForwardingTimeouts.ResponseHeaderTimeout != nil {
|
||||
err := forwardingTimeout.ResponseHeaderTimeout.Set(serversTransport.Spec.ForwardingTimeouts.ResponseHeaderTimeout.String())
|
||||
if err != nil {
|
||||
logger.Errorf("Error while reading ResponseHeaderTimeout: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading ResponseHeaderTimeout")
|
||||
}
|
||||
}
|
||||
|
||||
if serversTransport.Spec.ForwardingTimeouts.IdleConnTimeout != nil {
|
||||
err := forwardingTimeout.IdleConnTimeout.Set(serversTransport.Spec.ForwardingTimeouts.IdleConnTimeout.String())
|
||||
if err != nil {
|
||||
logger.Errorf("Error while reading IdleConnTimeout: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading IdleConnTimeout")
|
||||
}
|
||||
}
|
||||
|
||||
if serversTransport.Spec.ForwardingTimeouts.ReadIdleTimeout != nil {
|
||||
err := forwardingTimeout.ReadIdleTimeout.Set(serversTransport.Spec.ForwardingTimeouts.ReadIdleTimeout.String())
|
||||
if err != nil {
|
||||
logger.Errorf("Error while reading ReadIdleTimeout: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading ReadIdleTimeout")
|
||||
}
|
||||
}
|
||||
|
||||
if serversTransport.Spec.ForwardingTimeouts.PingTimeout != nil {
|
||||
err := forwardingTimeout.PingTimeout.Set(serversTransport.Spec.ForwardingTimeouts.PingTimeout.String())
|
||||
if err != nil {
|
||||
logger.Errorf("Error while reading PingTimeout: %v", err)
|
||||
logger.Error().Err(err).Msg("Error while reading PingTimeout")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -414,8 +416,8 @@ func getServicePort(svc *corev1.Service, port intstr.IntOrString) (*corev1.Servi
|
|||
}
|
||||
|
||||
if hasValidPort {
|
||||
log.WithoutContext().
|
||||
Warnf("The port %s from IngressRoute doesn't match with ports defined in the ExternalName service %s/%s.", port, svc.Namespace, svc.Name)
|
||||
log.Warn().Msgf("The port %s from IngressRoute doesn't match with ports defined in the ExternalName service %s/%s.",
|
||||
&port, svc.Namespace, svc.Name)
|
||||
}
|
||||
|
||||
return &corev1.ServicePort{Port: port.IntVal}, nil
|
||||
|
@ -811,8 +813,7 @@ func createChainMiddleware(ctx context.Context, namespace string, chain *v1alpha
|
|||
for _, mi := range chain.Middlewares {
|
||||
if strings.Contains(mi.Name, providerNamespaceSeparator) {
|
||||
if len(mi.Namespace) > 0 {
|
||||
log.FromContext(ctx).
|
||||
Warnf("namespace %q is ignored in cross-provider context", mi.Namespace)
|
||||
log.Ctx(ctx).Warn().Msgf("namespace %q is ignored in cross-provider context", mi.Namespace)
|
||||
}
|
||||
mds = append(mds, mi.Name)
|
||||
continue
|
||||
|
@ -838,24 +839,24 @@ func buildTLSOptions(ctx context.Context, client Client) map[string]tls.Options
|
|||
var nsDefault []string
|
||||
|
||||
for _, tlsOption := range tlsOptionsCRD {
|
||||
logger := log.FromContext(log.With(ctx, log.Str("tlsOption", tlsOption.Name), log.Str("namespace", tlsOption.Namespace)))
|
||||
logger := log.Ctx(ctx).With().Str("tlsOption", tlsOption.Name).Str("namespace", tlsOption.Namespace).Logger()
|
||||
var clientCAs []tls.FileOrContent
|
||||
|
||||
for _, secretName := range tlsOption.Spec.ClientAuth.SecretNames {
|
||||
secret, exists, err := client.GetSecret(tlsOption.Namespace, secretName)
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to fetch secret %s/%s: %v", tlsOption.Namespace, secretName, err)
|
||||
logger.Error().Err(err).Msgf("Failed to fetch secret %s/%s", tlsOption.Namespace, secretName)
|
||||
continue
|
||||
}
|
||||
|
||||
if !exists {
|
||||
logger.Warnf("Secret %s/%s does not exist", tlsOption.Namespace, secretName)
|
||||
logger.Warn().Msgf("Secret %s/%s does not exist", tlsOption.Namespace, secretName)
|
||||
continue
|
||||
}
|
||||
|
||||
cert, err := getCABlocks(secret, tlsOption.Namespace, secretName)
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to extract CA from secret %s/%s: %v", tlsOption.Namespace, secretName, err)
|
||||
logger.Error().Err(err).Msgf("Failed to extract CA from secret %s/%s", tlsOption.Namespace, secretName)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -890,7 +891,7 @@ func buildTLSOptions(ctx context.Context, client Client) map[string]tls.Options
|
|||
|
||||
if len(nsDefault) > 1 {
|
||||
delete(tlsOptions, tls.DefaultTLSConfigName)
|
||||
log.FromContext(ctx).Errorf("Default TLS Options defined in multiple namespaces: %v", nsDefault)
|
||||
log.Ctx(ctx).Error().Msgf("Default TLS Options defined in multiple namespaces: %v", nsDefault)
|
||||
}
|
||||
|
||||
return tlsOptions
|
||||
|
@ -907,7 +908,7 @@ func buildTLSStores(ctx context.Context, client Client) (map[string]tls.Store, m
|
|||
tlsConfigs := make(map[string]*tls.CertAndStores)
|
||||
|
||||
for _, t := range tlsStoreCRD {
|
||||
logger := log.FromContext(log.With(ctx, log.Str("TLSStore", t.Name), log.Str("namespace", t.Namespace)))
|
||||
logger := log.Ctx(ctx).With().Str("TLSStore", t.Name).Str("namespace", t.Namespace).Logger()
|
||||
|
||||
id := makeID(t.Namespace, t.Name)
|
||||
|
||||
|
@ -924,17 +925,17 @@ func buildTLSStores(ctx context.Context, client Client) (map[string]tls.Store, m
|
|||
|
||||
secret, exists, err := client.GetSecret(t.Namespace, secretName)
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to fetch secret %s/%s: %v", t.Namespace, secretName, err)
|
||||
logger.Error().Err(err).Msgf("Failed to fetch secret %s/%s", t.Namespace, secretName)
|
||||
continue
|
||||
}
|
||||
if !exists {
|
||||
logger.Errorf("Secret %s/%s does not exist", t.Namespace, secretName)
|
||||
logger.Error().Msgf("Secret %s/%s does not exist", t.Namespace, secretName)
|
||||
continue
|
||||
}
|
||||
|
||||
cert, key, err := getCertificateBlocks(secret, t.Namespace, secretName)
|
||||
if err != nil {
|
||||
logger.Errorf("Could not get certificate blocks: %v", err)
|
||||
logger.Error().Err(err).Msg("Could not get certificate blocks")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -952,7 +953,7 @@ func buildTLSStores(ctx context.Context, client Client) (map[string]tls.Store, m
|
|||
}
|
||||
|
||||
if err := buildCertificates(client, id, t.Namespace, t.Spec.Certificates, tlsConfigs); err != nil {
|
||||
logger.Errorf("Failed to load certificates: %v", err)
|
||||
logger.Error().Err(err).Msg("Failed to load certificates")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -961,7 +962,7 @@ func buildTLSStores(ctx context.Context, client Client) (map[string]tls.Store, m
|
|||
|
||||
if len(nsDefault) > 1 {
|
||||
delete(tlsStores, tls.DefaultTLSStoreName)
|
||||
log.FromContext(ctx).Errorf("Default TLS Stores defined in multiple namespaces: %v", nsDefault)
|
||||
log.Ctx(ctx).Error().Msgf("Default TLS Stores defined in multiple namespaces: %v", nsDefault)
|
||||
}
|
||||
|
||||
return tlsStores, tlsConfigs
|
||||
|
@ -1117,7 +1118,7 @@ func throttleEvents(ctx context.Context, throttleDuration time.Duration, pool *s
|
|||
default:
|
||||
// We already have an event in eventsChanBuffered, so we'll do a refresh as soon as our throttle allows us to.
|
||||
// It's fine to drop the event and keep whatever's in the buffer -- we don't do different things for different events
|
||||
log.FromContext(ctx).Debugf("Dropping event kind %T due to throttling", nextEvent)
|
||||
log.Ctx(ctx).Debug().Msgf("Dropping event kind %T due to throttling", nextEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,9 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/logs"
|
||||
"github.com/traefik/traefik/v2/pkg/provider"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/pkg/tls"
|
||||
|
@ -32,8 +33,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
|||
}
|
||||
|
||||
for _, ingressRoute := range client.GetIngressRoutes() {
|
||||
ctxRt := log.With(ctx, log.Str("ingress", ingressRoute.Name), log.Str("namespace", ingressRoute.Namespace))
|
||||
logger := log.FromContext(ctxRt)
|
||||
logger := log.Ctx(ctx).With().Str("ingress", ingressRoute.Name).Str("namespace", ingressRoute.Namespace).Logger()
|
||||
|
||||
// TODO keep the name ingressClass?
|
||||
if !shouldProcessIngress(p.IngressClass, ingressRoute.Annotations[annotationKubernetesIngressClass]) {
|
||||
|
@ -42,7 +42,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
|||
|
||||
err := getTLSHTTP(ctx, ingressRoute, client, tlsConfigs)
|
||||
if err != nil {
|
||||
logger.Errorf("Error configuring TLS: %v", err)
|
||||
logger.Error().Err(err).Msg("Error configuring TLS")
|
||||
}
|
||||
|
||||
ingressName := ingressRoute.Name
|
||||
|
@ -59,24 +59,24 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
|||
|
||||
for _, route := range ingressRoute.Spec.Routes {
|
||||
if route.Kind != "Rule" {
|
||||
logger.Errorf("Unsupported match kind: %s. Only \"Rule\" is supported for now.", route.Kind)
|
||||
logger.Error().Msgf("Unsupported match kind: %s. Only \"Rule\" is supported for now.", route.Kind)
|
||||
continue
|
||||
}
|
||||
|
||||
if len(route.Match) == 0 {
|
||||
logger.Errorf("Empty match rule")
|
||||
logger.Error().Msg("Empty match rule")
|
||||
continue
|
||||
}
|
||||
|
||||
serviceKey, err := makeServiceKey(route.Match, ingressName)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
logger.Error().Err(err).Send()
|
||||
continue
|
||||
}
|
||||
|
||||
mds, err := p.makeMiddlewareKeys(ctx, ingressRoute.Namespace, route.Middlewares)
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to create middleware keys: %v", err)
|
||||
logger.Error().Err(err).Msg("Failed to create middleware keys")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -92,13 +92,13 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
|||
|
||||
errBuild := cb.buildServicesLB(ctx, ingressRoute.Namespace, spec, serviceName, conf.Services)
|
||||
if errBuild != nil {
|
||||
logger.Error(errBuild)
|
||||
logger.Error().Err(errBuild).Send()
|
||||
continue
|
||||
}
|
||||
} else if len(route.Services) == 1 {
|
||||
fullName, serversLB, err := cb.nameAndService(ctx, ingressRoute.Namespace, route.Services[0].LoadBalancerSpec)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
logger.Error().Err(err).Send()
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -134,12 +134,12 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
|||
tlsOptionsName = makeID(ns, tlsOptionsName)
|
||||
} else if len(ns) > 0 {
|
||||
logger.
|
||||
WithField("TLSOption", ingressRoute.Spec.TLS.Options.Name).
|
||||
Warnf("Namespace %q is ignored in cross-provider context", ns)
|
||||
Warn().Str("TLSOption", ingressRoute.Spec.TLS.Options.Name).
|
||||
Msgf("Namespace %q is ignored in cross-provider context", ns)
|
||||
}
|
||||
|
||||
if !isNamespaceAllowed(p.AllowCrossNamespace, ingressRoute.Namespace, ns) {
|
||||
logger.Errorf("TLSOption %s/%s is not in the IngressRoute namespace %s",
|
||||
logger.Error().Msgf("TLSOption %s/%s is not in the IngressRoute namespace %s",
|
||||
ns, ingressRoute.Spec.TLS.Options.Name, ingressRoute.Namespace)
|
||||
continue
|
||||
}
|
||||
|
@ -170,9 +170,9 @@ func (p *Provider) makeMiddlewareKeys(ctx context.Context, ingRouteNamespace str
|
|||
|
||||
if strings.Contains(name, providerNamespaceSeparator) {
|
||||
if len(mi.Namespace) > 0 {
|
||||
log.FromContext(ctx).
|
||||
WithField(log.MiddlewareName, mi.Name).
|
||||
Warnf("namespace %q is ignored in cross-provider context", mi.Namespace)
|
||||
log.Ctx(ctx).
|
||||
Warn().Str(logs.MiddlewareName, mi.Name).
|
||||
Msgf("namespace %q is ignored in cross-provider context", mi.Namespace)
|
||||
}
|
||||
|
||||
mds = append(mds, name)
|
||||
|
@ -439,7 +439,7 @@ func (c configBuilder) loadServers(parentNamespace string, svc v1alpha1.LoadBala
|
|||
// it generates and returns the configuration part for such a service,
|
||||
// so that the caller can add it to the global config map.
|
||||
func (c configBuilder) nameAndService(ctx context.Context, parentNamespace string, service v1alpha1.LoadBalancerSpec) (string, *dynamic.Service, error) {
|
||||
svcCtx := log.With(ctx, log.Str(log.ServiceName, service.Name))
|
||||
svcCtx := log.Ctx(ctx).With().Str(logs.ServiceName, service.Name).Logger().WithContext(ctx)
|
||||
|
||||
namespace := namespaceOrFallback(service, parentNamespace)
|
||||
|
||||
|
@ -488,7 +488,7 @@ func fullServiceName(ctx context.Context, namespace string, service v1alpha1.Loa
|
|||
}
|
||||
|
||||
if service.Namespace != "" {
|
||||
log.FromContext(ctx).Warnf("namespace %q is ignored in cross-provider context", service.Namespace)
|
||||
log.Ctx(ctx).Warn().Msgf("namespace %q is ignored in cross-provider context", service.Namespace)
|
||||
}
|
||||
|
||||
return provider.Normalize(name) + providerNamespaceSeparator + pName
|
||||
|
@ -507,7 +507,7 @@ func getTLSHTTP(ctx context.Context, ingressRoute *v1alpha1.IngressRoute, k8sCli
|
|||
return nil
|
||||
}
|
||||
if ingressRoute.Spec.TLS.SecretName == "" {
|
||||
log.FromContext(ctx).Debugf("No secret name provided")
|
||||
log.Ctx(ctx).Debug().Msg("No secret name provided")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,9 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/logs"
|
||||
"github.com/traefik/traefik/v2/pkg/provider"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/pkg/tls"
|
||||
|
@ -24,7 +25,7 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
|
|||
}
|
||||
|
||||
for _, ingressRouteTCP := range client.GetIngressRouteTCPs() {
|
||||
logger := log.FromContext(log.With(ctx, log.Str("ingress", ingressRouteTCP.Name), log.Str("namespace", ingressRouteTCP.Namespace)))
|
||||
logger := log.Ctx(ctx).With().Str("ingress", ingressRouteTCP.Name).Str("namespace", ingressRouteTCP.Namespace).Logger()
|
||||
|
||||
if !shouldProcessIngress(p.IngressClass, ingressRouteTCP.Annotations[annotationKubernetesIngressClass]) {
|
||||
continue
|
||||
|
@ -33,7 +34,7 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
|
|||
if ingressRouteTCP.Spec.TLS != nil && !ingressRouteTCP.Spec.TLS.Passthrough {
|
||||
err := getTLSTCP(ctx, ingressRouteTCP, client, tlsConfigs)
|
||||
if err != nil {
|
||||
logger.Errorf("Error configuring TLS: %v", err)
|
||||
logger.Error().Err(err).Msg("Error configuring TLS")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,19 +45,19 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
|
|||
|
||||
for _, route := range ingressRouteTCP.Spec.Routes {
|
||||
if len(route.Match) == 0 {
|
||||
logger.Errorf("Empty match rule")
|
||||
logger.Error().Msg("Empty match rule")
|
||||
continue
|
||||
}
|
||||
|
||||
key, err := makeServiceKey(route.Match, ingressName)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
logger.Error().Err(err).Send()
|
||||
continue
|
||||
}
|
||||
|
||||
mds, err := p.makeMiddlewareTCPKeys(ctx, ingressRouteTCP.Namespace, route.Middlewares)
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to create middleware keys: %v", err)
|
||||
logger.Error().Err(err).Msg("Failed to create middleware keys")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -65,10 +66,11 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
|
|||
for _, service := range route.Services {
|
||||
balancerServerTCP, err := p.createLoadBalancerServerTCP(client, ingressRouteTCP.Namespace, service)
|
||||
if err != nil {
|
||||
logger.
|
||||
WithField("serviceName", service.Name).
|
||||
WithField("servicePort", service.Port).
|
||||
Errorf("Cannot create service: %v", err)
|
||||
logger.Error().
|
||||
Str("serviceName", service.Name).
|
||||
Stringer("servicePort", &service.Port).
|
||||
Err(err).
|
||||
Msg("Cannot create service")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -119,13 +121,13 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
|
|||
}
|
||||
tlsOptionsName = makeID(ns, tlsOptionsName)
|
||||
} else if len(ns) > 0 {
|
||||
logger.
|
||||
WithField("TLSOption", ingressRouteTCP.Spec.TLS.Options.Name).
|
||||
Warnf("Namespace %q is ignored in cross-provider context", ns)
|
||||
logger.Warn().
|
||||
Str("TLSOption", ingressRouteTCP.Spec.TLS.Options.Name).
|
||||
Msgf("Namespace %q is ignored in cross-provider context", ns)
|
||||
}
|
||||
|
||||
if !isNamespaceAllowed(p.AllowCrossNamespace, ingressRouteTCP.Namespace, ns) {
|
||||
logger.Errorf("TLSOption %s/%s is not in the IngressRouteTCP namespace %s",
|
||||
logger.Error().Msgf("TLSOption %s/%s is not in the IngressRouteTCP namespace %s",
|
||||
ns, ingressRouteTCP.Spec.TLS.Options.Name, ingressRouteTCP.Namespace)
|
||||
continue
|
||||
}
|
||||
|
@ -147,9 +149,9 @@ func (p *Provider) makeMiddlewareTCPKeys(ctx context.Context, ingRouteTCPNamespa
|
|||
for _, mi := range middlewares {
|
||||
if strings.Contains(mi.Name, providerNamespaceSeparator) {
|
||||
if len(mi.Namespace) > 0 {
|
||||
log.FromContext(ctx).
|
||||
WithField(log.MiddlewareName, mi.Name).
|
||||
Warnf("namespace %q is ignored in cross-provider context", mi.Namespace)
|
||||
log.Ctx(ctx).Warn().
|
||||
Str(logs.MiddlewareName, mi.Name).
|
||||
Msgf("Namespace %q is ignored in cross-provider context", mi.Namespace)
|
||||
}
|
||||
mds = append(mds, mi.Name)
|
||||
continue
|
||||
|
@ -275,7 +277,7 @@ func getTLSTCP(ctx context.Context, ingressRoute *v1alpha1.IngressRouteTCP, k8sC
|
|||
return nil
|
||||
}
|
||||
if ingressRoute.Spec.TLS.SecretName == "" {
|
||||
log.FromContext(ctx).Debugf("No secret name provided")
|
||||
log.Ctx(ctx).Debug().Msg("No secret name provided")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
@ -20,7 +20,7 @@ func (p *Provider) loadIngressRouteUDPConfiguration(ctx context.Context, client
|
|||
}
|
||||
|
||||
for _, ingressRouteUDP := range client.GetIngressRouteUDPs() {
|
||||
logger := log.FromContext(log.With(ctx, log.Str("ingress", ingressRouteUDP.Name), log.Str("namespace", ingressRouteUDP.Namespace)))
|
||||
logger := log.Ctx(ctx).With().Str("ingress", ingressRouteUDP.Name).Str("namespace", ingressRouteUDP.Namespace).Logger()
|
||||
|
||||
if !shouldProcessIngress(p.IngressClass, ingressRouteUDP.Annotations[annotationKubernetesIngressClass]) {
|
||||
continue
|
||||
|
@ -38,10 +38,11 @@ func (p *Provider) loadIngressRouteUDPConfiguration(ctx context.Context, client
|
|||
for _, service := range route.Services {
|
||||
balancerServerUDP, err := p.createLoadBalancerServerUDP(client, ingressRouteUDP.Namespace, service)
|
||||
if err != nil {
|
||||
logger.
|
||||
WithField("serviceName", service.Name).
|
||||
WithField("servicePort", service.Port).
|
||||
Errorf("Cannot create service: %v", err)
|
||||
logger.Error().
|
||||
Str("serviceName", service.Name).
|
||||
Stringer("servicePort", &service.Port).
|
||||
Err(err).
|
||||
Msg("Cannot create service")
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue