2019-07-10 07:26:04 +00:00
|
|
|
package dynamic
|
|
|
|
|
2019-07-19 09:52:04 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
2020-09-16 13:46:04 +00:00
|
|
|
"github.com/traefik/traefik/v2/pkg/types"
|
2019-07-19 09:52:04 +00:00
|
|
|
)
|
2019-07-10 07:26:04 +00:00
|
|
|
|
|
|
|
// +k8s:deepcopy-gen=true
|
|
|
|
|
|
|
|
// TCPConfiguration contains all the TCP configuration parameters.
|
|
|
|
type TCPConfiguration struct {
|
2021-06-11 13:30:05 +00:00
|
|
|
Routers map[string]*TCPRouter `json:"routers,omitempty" toml:"routers,omitempty" yaml:"routers,omitempty" export:"true"`
|
|
|
|
Services map[string]*TCPService `json:"services,omitempty" toml:"services,omitempty" yaml:"services,omitempty" export:"true"`
|
|
|
|
Middlewares map[string]*TCPMiddleware `json:"middlewares,omitempty" toml:"middlewares,omitempty" yaml:"middlewares,omitempty" export:"true"`
|
2019-07-10 07:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// +k8s:deepcopy-gen=true
|
|
|
|
|
|
|
|
// TCPService holds a tcp service configuration (can only be of one type at the same time).
|
|
|
|
type TCPService struct {
|
2020-12-03 14:52:05 +00:00
|
|
|
LoadBalancer *TCPServersLoadBalancer `json:"loadBalancer,omitempty" toml:"loadBalancer,omitempty" yaml:"loadBalancer,omitempty" export:"true"`
|
|
|
|
Weighted *TCPWeightedRoundRobin `json:"weighted,omitempty" toml:"weighted,omitempty" yaml:"weighted,omitempty" label:"-" export:"true"`
|
2019-09-13 18:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// +k8s:deepcopy-gen=true
|
|
|
|
|
|
|
|
// TCPWeightedRoundRobin is a weighted round robin tcp load-balancer of services.
|
|
|
|
type TCPWeightedRoundRobin struct {
|
2020-12-03 14:52:05 +00:00
|
|
|
Services []TCPWRRService `json:"services,omitempty" toml:"services,omitempty" yaml:"services,omitempty" export:"true"`
|
2019-09-13 18:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// +k8s:deepcopy-gen=true
|
|
|
|
|
|
|
|
// TCPWRRService is a reference to a tcp service load-balanced with weighted round robin.
|
|
|
|
type TCPWRRService struct {
|
2020-12-03 14:52:05 +00:00
|
|
|
Name string `json:"name,omitempty" toml:"name,omitempty" yaml:"name,omitempty" export:"true"`
|
|
|
|
Weight *int `json:"weight,omitempty" toml:"weight,omitempty" yaml:"weight,omitempty" export:"true"`
|
2019-09-13 18:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetDefaults Default values for a TCPWRRService.
|
|
|
|
func (w *TCPWRRService) SetDefaults() {
|
|
|
|
defaultWeight := 1
|
|
|
|
w.Weight = &defaultWeight
|
2019-07-10 07:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// +k8s:deepcopy-gen=true
|
|
|
|
|
|
|
|
// TCPRouter holds the router configuration.
|
|
|
|
type TCPRouter struct {
|
2020-12-03 14:52:05 +00:00
|
|
|
EntryPoints []string `json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty" export:"true"`
|
2021-06-11 13:30:05 +00:00
|
|
|
Middlewares []string `json:"middlewares,omitempty" toml:"middlewares,omitempty" yaml:"middlewares,omitempty" export:"true"`
|
2020-12-03 14:52:05 +00:00
|
|
|
Service string `json:"service,omitempty" toml:"service,omitempty" yaml:"service,omitempty" export:"true"`
|
2019-07-10 07:26:04 +00:00
|
|
|
Rule string `json:"rule,omitempty" toml:"rule,omitempty" yaml:"rule,omitempty"`
|
2022-03-17 17:02:08 +00:00
|
|
|
Priority int `json:"priority,omitempty" toml:"priority,omitempty,omitzero" yaml:"priority,omitempty" export:"true"`
|
2022-03-22 10:04:08 +00:00
|
|
|
TLS *RouterTCPTLSConfig `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"allowEmpty" file:"allowEmpty" kv:"allowEmpty" export:"true"`
|
2019-07-10 07:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// +k8s:deepcopy-gen=true
|
|
|
|
|
2020-05-11 10:06:07 +00:00
|
|
|
// RouterTCPTLSConfig holds the TLS configuration for a router.
|
2019-07-10 07:26:04 +00:00
|
|
|
type RouterTCPTLSConfig struct {
|
2020-12-03 14:52:05 +00:00
|
|
|
Passthrough bool `json:"passthrough" toml:"passthrough" yaml:"passthrough" export:"true"`
|
|
|
|
Options string `json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty" export:"true"`
|
|
|
|
CertResolver string `json:"certResolver,omitempty" toml:"certResolver,omitempty" yaml:"certResolver,omitempty" export:"true"`
|
|
|
|
Domains []types.Domain `json:"domains,omitempty" toml:"domains,omitempty" yaml:"domains,omitempty" export:"true"`
|
2019-07-10 07:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// +k8s:deepcopy-gen=true
|
|
|
|
|
2019-09-13 18:00:06 +00:00
|
|
|
// TCPServersLoadBalancer holds the LoadBalancerService configuration.
|
|
|
|
type TCPServersLoadBalancer struct {
|
2019-09-13 15:46:04 +00:00
|
|
|
// TerminationDelay, corresponds to the deadline that the proxy sets, after one
|
|
|
|
// of its connected peers indicates it has closed the writing capability of its
|
|
|
|
// connection, to close the reading capability as well, hence fully terminating the
|
|
|
|
// connection. It is a duration in milliseconds, defaulting to 100. A negative value
|
|
|
|
// means an infinite deadline (i.e. the reading capability is never closed).
|
2020-12-03 14:52:05 +00:00
|
|
|
TerminationDelay *int `json:"terminationDelay,omitempty" toml:"terminationDelay,omitempty" yaml:"terminationDelay,omitempty" export:"true"`
|
2022-03-22 10:04:08 +00:00
|
|
|
ProxyProtocol *ProxyProtocol `json:"proxyProtocol,omitempty" toml:"proxyProtocol,omitempty" yaml:"proxyProtocol,omitempty" label:"allowEmpty" file:"allowEmpty" kv:"allowEmpty" export:"true"`
|
2020-12-03 14:52:05 +00:00
|
|
|
Servers []TCPServer `json:"servers,omitempty" toml:"servers,omitempty" yaml:"servers,omitempty" label-slice-as-struct:"server" export:"true"`
|
2019-09-13 15:46:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 10:06:07 +00:00
|
|
|
// SetDefaults Default values for a TCPServersLoadBalancer.
|
2019-09-13 18:00:06 +00:00
|
|
|
func (l *TCPServersLoadBalancer) SetDefaults() {
|
2019-09-13 15:46:04 +00:00
|
|
|
defaultTerminationDelay := 100 // in milliseconds
|
|
|
|
l.TerminationDelay = &defaultTerminationDelay
|
2019-07-10 07:26:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mergeable tells if the given service is mergeable.
|
2019-09-13 18:00:06 +00:00
|
|
|
func (l *TCPServersLoadBalancer) Mergeable(loadBalancer *TCPServersLoadBalancer) bool {
|
2019-07-10 07:26: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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// +k8s:deepcopy-gen=true
|
|
|
|
|
2020-05-11 10:06:07 +00:00
|
|
|
// TCPServer holds a TCP Server configuration.
|
2019-07-10 07:26:04 +00:00
|
|
|
type TCPServer struct {
|
|
|
|
Address string `json:"address,omitempty" toml:"address,omitempty" yaml:"address,omitempty" label:"-"`
|
|
|
|
Port string `toml:"-" json:"-" yaml:"-"`
|
|
|
|
}
|
2020-11-17 12:04:04 +00:00
|
|
|
|
|
|
|
// +k8s:deepcopy-gen=true
|
|
|
|
|
2022-06-24 10:40:08 +00:00
|
|
|
// ProxyProtocol holds the PROXY Protocol configuration.
|
|
|
|
// More info: https://doc.traefik.io/traefik/v2.7/routing/services/#proxy-protocol
|
2020-11-17 12:04:04 +00:00
|
|
|
type ProxyProtocol struct {
|
2022-06-24 10:40:08 +00:00
|
|
|
// Version defines the PROXY Protocol version to use.
|
2020-12-03 14:52:05 +00:00
|
|
|
Version int `json:"version,omitempty" toml:"version,omitempty" yaml:"version,omitempty" export:"true"`
|
2020-11-17 12:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetDefaults Default values for a ProxyProtocol.
|
|
|
|
func (p *ProxyProtocol) SetDefaults() {
|
|
|
|
p.Version = 2
|
|
|
|
}
|