2019-07-10 07:26:04 +00:00
package dynamic
2018-11-14 09:18:03 +00:00
2019-07-19 09:52:04 +00:00
import (
"reflect"
2020-09-11 13:40:03 +00:00
"time"
2019-07-19 09:52:04 +00:00
2020-09-11 13:40:03 +00:00
"github.com/containous/traefik/v2/pkg/tls"
2019-08-03 01:58:23 +00:00
"github.com/containous/traefik/v2/pkg/types"
2020-09-11 13:40:03 +00:00
ptypes "github.com/traefik/paerser/types"
2019-07-19 09:52:04 +00:00
)
2019-07-01 09:30:05 +00:00
2019-07-09 13:18:04 +00:00
// +k8s:deepcopy-gen=true
2019-07-01 09:30:05 +00:00
// HTTPConfiguration contains all the HTTP configuration parameters.
type HTTPConfiguration struct {
2020-09-11 13:40:03 +00:00
Routers map [ string ] * Router ` json:"routers,omitempty" toml:"routers,omitempty" yaml:"routers,omitempty" `
Services map [ string ] * Service ` json:"services,omitempty" toml:"services,omitempty" yaml:"services,omitempty" `
Middlewares map [ string ] * Middleware ` json:"middlewares,omitempty" toml:"middlewares,omitempty" yaml:"middlewares,omitempty" `
Models map [ string ] * Model ` json:"models,omitempty" toml:"models,omitempty" yaml:"models,omitempty" `
ServersTransports map [ string ] * ServersTransport ` json:"serversTransports,omitempty" toml:"serversTransports,omitempty" yaml:"serversTransports,omitempty" label:"-" `
2020-03-05 11:46:05 +00:00
}
// +k8s:deepcopy-gen=true
// Model is a set of default router's values.
type Model struct {
Middlewares [ ] string ` json:"middlewares,omitempty" toml:"middlewares,omitempty" yaml:"middlewares,omitempty" `
2020-06-17 14:48:04 +00:00
TLS * RouterTLSConfig ` json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"allowEmpty" file:"allowEmpty" `
2019-07-01 09:30:05 +00:00
}
2019-07-09 13:18:04 +00:00
// +k8s:deepcopy-gen=true
2019-07-01 09:30:05 +00:00
// Service holds a service configuration (can only be of one type at the same time).
type Service struct {
2019-08-26 08:30:05 +00:00
LoadBalancer * ServersLoadBalancer ` json:"loadBalancer,omitempty" toml:"loadBalancer,omitempty" yaml:"loadBalancer,omitempty" `
Weighted * WeightedRoundRobin ` json:"weighted,omitempty" toml:"weighted,omitempty" yaml:"weighted,omitempty" label:"-" `
2019-08-26 17:00:04 +00:00
Mirroring * Mirroring ` json:"mirroring,omitempty" toml:"mirroring,omitempty" yaml:"mirroring,omitempty" label:"-" `
2019-07-01 09:30:05 +00:00
}
2019-07-09 13:18:04 +00:00
// +k8s:deepcopy-gen=true
2018-11-14 09:18:03 +00:00
// Router holds the router configuration.
type Router struct {
2019-07-01 09:30:05 +00:00
EntryPoints [ ] string ` json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty" `
Middlewares [ ] string ` json:"middlewares,omitempty" toml:"middlewares,omitempty" yaml:"middlewares,omitempty" `
Service string ` json:"service,omitempty" toml:"service,omitempty" yaml:"service,omitempty" `
Rule string ` json:"rule,omitempty" toml:"rule,omitempty" yaml:"rule,omitempty" `
Priority int ` json:"priority,omitempty" toml:"priority,omitempty,omitzero" yaml:"priority,omitempty" `
2020-06-17 14:48:04 +00:00
TLS * RouterTLSConfig ` json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"allowEmpty" file:"allowEmpty" `
2019-03-14 08:30:04 +00:00
}
2019-07-09 13:18:04 +00:00
// +k8s:deepcopy-gen=true
2020-05-11 10:06:07 +00:00
// RouterTLSConfig holds the TLS configuration for a router.
2019-06-17 16:14:08 +00:00
type RouterTLSConfig struct {
2019-07-19 09:52:04 +00:00
Options string ` json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty" `
CertResolver string ` json:"certResolver,omitempty" toml:"certResolver,omitempty" yaml:"certResolver,omitempty" `
Domains [ ] types . Domain ` json:"domains,omitempty" toml:"domains,omitempty" yaml:"domains,omitempty" `
2019-06-17 16:14:08 +00:00
}
2019-03-14 08:30:04 +00:00
2019-07-09 13:18:04 +00:00
// +k8s:deepcopy-gen=true
2019-08-26 17:00:04 +00:00
// Mirroring holds the Mirroring configuration.
type Mirroring struct {
2020-03-05 17:03:08 +00:00
Service string ` json:"service,omitempty" toml:"service,omitempty" yaml:"service,omitempty" `
MaxBodySize * int64 ` json:"maxBodySize,omitempty" toml:"maxBodySize,omitempty" yaml:"maxBodySize,omitempty" `
Mirrors [ ] MirrorService ` json:"mirrors,omitempty" toml:"mirrors,omitempty" yaml:"mirrors,omitempty" `
}
// SetDefaults Default values for a WRRService.
func ( m * Mirroring ) SetDefaults ( ) {
var defaultMaxBodySize int64 = - 1
m . MaxBodySize = & defaultMaxBodySize
2019-08-26 17:00:04 +00:00
}
// +k8s:deepcopy-gen=true
// MirrorService holds the MirrorService configuration.
type MirrorService struct {
Name string ` json:"name,omitempty" toml:"name,omitempty" yaml:"name,omitempty" `
Percent int ` json:"percent,omitempty" toml:"percent,omitempty" yaml:"percent,omitempty" `
}
// +k8s:deepcopy-gen=true
2019-08-26 08:30:05 +00:00
// WeightedRoundRobin is a weighted round robin load-balancer of services.
type WeightedRoundRobin struct {
Services [ ] WRRService ` json:"services,omitempty" toml:"services,omitempty" yaml:"services,omitempty" `
Sticky * Sticky ` json:"sticky,omitempty" toml:"sticky,omitempty" yaml:"sticky,omitempty" `
}
// +k8s:deepcopy-gen=true
// WRRService is a reference to a service load-balanced with weighted round robin.
type WRRService struct {
Name string ` json:"name,omitempty" toml:"name,omitempty" yaml:"name,omitempty" `
Weight * int ` json:"weight,omitempty" toml:"weight,omitempty" yaml:"weight,omitempty" `
}
2019-09-13 18:00:06 +00:00
// SetDefaults Default values for a WRRService.
2019-08-26 08:30:05 +00:00
func ( w * WRRService ) SetDefaults ( ) {
defaultWeight := 1
w . Weight = & defaultWeight
}
// +k8s:deepcopy-gen=true
// Sticky holds the sticky configuration.
type Sticky struct {
2020-06-17 14:48:04 +00:00
Cookie * Cookie ` json:"cookie,omitempty" toml:"cookie,omitempty" yaml:"cookie,omitempty" label:"allowEmpty" file:"allowEmpty" `
2019-08-26 08:30:05 +00:00
}
// +k8s:deepcopy-gen=true
// Cookie holds the sticky configuration based on cookie.
type Cookie struct {
Name string ` json:"name,omitempty" toml:"name,omitempty" yaml:"name,omitempty" `
Secure bool ` json:"secure,omitempty" toml:"secure,omitempty" yaml:"secure,omitempty" `
HTTPOnly bool ` json:"httpOnly,omitempty" toml:"httpOnly,omitempty" yaml:"httpOnly,omitempty" `
2020-03-23 10:24:05 +00:00
SameSite string ` json:"sameSite,omitempty" toml:"sameSite,omitempty" yaml:"sameSite,omitempty" `
2019-08-26 08:30:05 +00:00
}
// +k8s:deepcopy-gen=true
// ServersLoadBalancer holds the ServersLoadBalancer configuration.
type ServersLoadBalancer struct {
2020-06-17 14:48:04 +00:00
Sticky * Sticky ` json:"sticky,omitempty" toml:"sticky,omitempty" yaml:"sticky,omitempty" label:"allowEmpty" file:"allowEmpty" `
2019-07-01 09:30:05 +00:00
Servers [ ] Server ` json:"servers,omitempty" toml:"servers,omitempty" yaml:"servers,omitempty" label-slice-as-struct:"server" `
HealthCheck * HealthCheck ` json:"healthCheck,omitempty" toml:"healthCheck,omitempty" yaml:"healthCheck,omitempty" `
2019-09-30 16:12:04 +00:00
PassHostHeader * bool ` json:"passHostHeader" toml:"passHostHeader" yaml:"passHostHeader" `
2019-07-01 09:30:05 +00:00
ResponseForwarding * ResponseForwarding ` json:"responseForwarding,omitempty" toml:"responseForwarding,omitempty" yaml:"responseForwarding,omitempty" `
2020-09-11 13:40:03 +00:00
ServersTransport string ` json:"serversTransport,omitempty" toml:"serversTransport,omitempty" yaml:"serversTransport,omitempty" `
2018-11-14 09:18:03 +00:00
}
2019-01-18 14:18:04 +00:00
// Mergeable tells if the given service is mergeable.
2019-08-26 08:30:05 +00:00
func ( l * ServersLoadBalancer ) Mergeable ( loadBalancer * ServersLoadBalancer ) bool {
2019-01-18 14:18:04 +00:00
savedServers := l . Servers
defer func ( ) {
l . Servers = savedServers
} ( )
l . Servers = nil
savedServersLB := loadBalancer . Servers
defer func ( ) {
loadBalancer . Servers = savedServersLB
} ( )
loadBalancer . Servers = nil
return reflect . DeepEqual ( l , loadBalancer )
}
2019-08-26 08:30:05 +00:00
// SetDefaults Default values for a ServersLoadBalancer.
func ( l * ServersLoadBalancer ) SetDefaults ( ) {
2019-09-30 16:12:04 +00:00
defaultPassHostHeader := true
l . PassHostHeader = & defaultPassHostHeader
2019-01-18 14:18:04 +00:00
}
2019-07-09 13:18:04 +00:00
// +k8s:deepcopy-gen=true
2018-11-14 09:18:03 +00:00
// ResponseForwarding holds configuration for the forward of the response.
type ResponseForwarding struct {
2019-07-01 09:30:05 +00:00
FlushInterval string ` json:"flushInterval,omitempty" toml:"flushInterval,omitempty" yaml:"flushInterval,omitempty" `
2018-11-14 09:18:03 +00:00
}
2019-07-09 13:18:04 +00:00
// +k8s:deepcopy-gen=true
2018-11-14 09:18:03 +00:00
// Server holds the server configuration.
type Server struct {
2019-07-01 09:30:05 +00:00
URL string ` json:"url,omitempty" toml:"url,omitempty" yaml:"url,omitempty" label:"-" `
2020-06-17 14:48:04 +00:00
Scheme string ` toml:"-" json:"-" yaml:"-" file:"-" `
Port string ` toml:"-" json:"-" yaml:"-" file:"-" `
2018-11-14 09:18:03 +00:00
}
2019-01-18 14:18:04 +00:00
// SetDefaults Default values for a Server.
func ( s * Server ) SetDefaults ( ) {
s . Scheme = "http"
}
2019-07-09 13:18:04 +00:00
// +k8s:deepcopy-gen=true
2018-11-14 09:18:03 +00:00
// HealthCheck holds the HealthCheck configuration.
type HealthCheck struct {
2019-07-01 09:30:05 +00:00
Scheme string ` json:"scheme,omitempty" toml:"scheme,omitempty" yaml:"scheme,omitempty" `
Path string ` json:"path,omitempty" toml:"path,omitempty" yaml:"path,omitempty" `
Port int ` json:"port,omitempty" toml:"port,omitempty,omitzero" yaml:"port,omitempty" `
2020-08-17 16:04:03 +00:00
// FIXME change string to ptypes.Duration
2019-07-01 09:30:05 +00:00
Interval string ` json:"interval,omitempty" toml:"interval,omitempty" yaml:"interval,omitempty" `
2020-08-17 16:04:03 +00:00
// FIXME change string to ptypes.Duration
2020-02-26 16:28:04 +00:00
Timeout string ` json:"timeout,omitempty" toml:"timeout,omitempty" yaml:"timeout,omitempty" `
Hostname string ` json:"hostname,omitempty" toml:"hostname,omitempty" yaml:"hostname,omitempty" `
FollowRedirects * bool ` json:"followRedirects" toml:"followRedirects" yaml:"followRedirects" `
Headers map [ string ] string ` json:"headers,omitempty" toml:"headers,omitempty" yaml:"headers,omitempty" `
}
// SetDefaults Default values for a HealthCheck.
func ( h * HealthCheck ) SetDefaults ( ) {
fr := true
h . FollowRedirects = & fr
2019-03-14 08:30:04 +00:00
}
2020-09-11 13:40:03 +00:00
// +k8s:deepcopy-gen=true
// ServersTransport options to configure communication between Traefik and the servers.
type ServersTransport struct {
ServerName string ` description:"ServerName used to contact the server" json:"serverName,omitempty" toml:"serverName,omitempty" yaml:"serverName,omitempty" export:"true" `
InsecureSkipVerify bool ` description:"Disable SSL certificate verification." json:"insecureSkipVerify,omitempty" toml:"insecureSkipVerify,omitempty" yaml:"insecureSkipVerify,omitempty" export:"true" `
RootCAs [ ] tls . FileOrContent ` description:"Add cert file for self-signed certificate." json:"rootCAs,omitempty" toml:"rootCAs,omitempty" yaml:"rootCAs,omitempty" `
Certificates tls . Certificates ` description:"Certificates for mTLS." json:"certificates,omitempty" toml:"certificates,omitempty" yaml:"certificates,omitempty" `
MaxIdleConnsPerHost int ` description:"If non-zero, controls the maximum idle (keep-alive) to keep per-host. If zero, DefaultMaxIdleConnsPerHost is used" json:"maxIdleConnsPerHost,omitempty" toml:"maxIdleConnsPerHost,omitempty" yaml:"maxIdleConnsPerHost,omitempty" export:"true" `
ForwardingTimeouts * ForwardingTimeouts ` description:"Timeouts for requests forwarded to the backend servers." json:"forwardingTimeouts,omitempty" toml:"forwardingTimeouts,omitempty" yaml:"forwardingTimeouts,omitempty" export:"true" `
}
// +k8s:deepcopy-gen=true
// ForwardingTimeouts contains timeout configurations for forwarding requests to the backend servers.
type ForwardingTimeouts struct {
DialTimeout ptypes . Duration ` description:"The amount of time to wait until a connection to a backend server can be established. If zero, no timeout exists." json:"dialTimeout,omitempty" toml:"dialTimeout,omitempty" yaml:"dialTimeout,omitempty" export:"true" `
ResponseHeaderTimeout ptypes . Duration ` description:"The amount of time to wait for a server's response headers after fully writing the request (including its body, if any). If zero, no timeout exists." json:"responseHeaderTimeout,omitempty" toml:"responseHeaderTimeout,omitempty" yaml:"responseHeaderTimeout,omitempty" export:"true" `
IdleConnTimeout ptypes . Duration ` description:"The maximum period for which an idle HTTP keep-alive connection will remain open before closing itself" json:"idleConnTimeout,omitempty" toml:"idleConnTimeout,omitempty" yaml:"idleConnTimeout,omitempty" export:"true" `
}
// SetDefaults sets the default values.
func ( f * ForwardingTimeouts ) SetDefaults ( ) {
f . DialTimeout = ptypes . Duration ( 30 * time . Second )
f . IdleConnTimeout = ptypes . Duration ( 90 * time . Second )
}