Handle TCP in the marathon provider
Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
This commit is contained in:
parent
8389b46b5c
commit
d1d2611665
33 changed files with 1983 additions and 827 deletions
|
@ -160,361 +160,477 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
"traefik.http.services.Service1.loadbalancer.server.port": "8080",
|
||||
"traefik.http.services.Service1.loadbalancer.stickiness": "false",
|
||||
"traefik.http.services.Service1.loadbalancer.stickiness.cookiename": "fui",
|
||||
"traefik.tcp.routers.Router0.rule": "foobar",
|
||||
"traefik.tcp.routers.Router0.entrypoints": "foobar, fiibar",
|
||||
"traefik.tcp.routers.Router0.service": "foobar",
|
||||
"traefik.tcp.routers.Router0.tls.passthrough": "false",
|
||||
"traefik.tcp.routers.Router1.rule": "foobar",
|
||||
"traefik.tcp.routers.Router1.entrypoints": "foobar, fiibar",
|
||||
"traefik.tcp.routers.Router1.service": "foobar",
|
||||
"traefik.tcp.routers.Router1.tls.passthrough": "false",
|
||||
"traefik.tcp.services.Service0.loadbalancer.method": "foobar",
|
||||
"traefik.tcp.services.Service0.loadbalancer.server.Port": "42",
|
||||
"traefik.tcp.services.Service0.loadbalancer.server.Weight": "42",
|
||||
"traefik.tcp.services.Service1.loadbalancer.method": "foobar",
|
||||
"traefik.tcp.services.Service1.loadbalancer.server.Port": "42",
|
||||
"traefik.tcp.services.Service1.loadbalancer.server.Weight": "42",
|
||||
}
|
||||
|
||||
configuration, err := DecodeConfiguration(labels)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := &config.HTTPConfiguration{
|
||||
Routers: map[string]*config.Router{
|
||||
"Router0": {
|
||||
EntryPoints: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Middlewares: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Service: "foobar",
|
||||
Rule: "foobar",
|
||||
Priority: 42,
|
||||
TLS: &config.RouterTLSConfig{},
|
||||
},
|
||||
"Router1": {
|
||||
EntryPoints: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Middlewares: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Service: "foobar",
|
||||
Rule: "foobar",
|
||||
Priority: 42,
|
||||
},
|
||||
},
|
||||
Middlewares: map[string]*config.Middleware{
|
||||
"Middleware0": {
|
||||
AddPrefix: &config.AddPrefix{
|
||||
Prefix: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware1": {
|
||||
BasicAuth: &config.BasicAuth{
|
||||
Users: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
UsersFile: "foobar",
|
||||
Realm: "foobar",
|
||||
RemoveHeader: true,
|
||||
HeaderField: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware10": {
|
||||
MaxConn: &config.MaxConn{
|
||||
Amount: 42,
|
||||
ExtractorFunc: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware11": {
|
||||
PassTLSClientCert: &config.PassTLSClientCert{
|
||||
PEM: true,
|
||||
Info: &config.TLSClientCertificateInfo{
|
||||
NotAfter: true,
|
||||
NotBefore: true,
|
||||
Subject: &config.TLSCLientCertificateDNInfo{
|
||||
Country: true,
|
||||
Province: true,
|
||||
Locality: true,
|
||||
Organization: true,
|
||||
CommonName: true,
|
||||
SerialNumber: true,
|
||||
DomainComponent: true,
|
||||
},
|
||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
||||
Country: true,
|
||||
Province: true,
|
||||
Locality: true,
|
||||
Organization: true,
|
||||
CommonName: true,
|
||||
SerialNumber: true,
|
||||
DomainComponent: true,
|
||||
},
|
||||
Sans: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"Middleware12": {
|
||||
RateLimit: &config.RateLimit{
|
||||
RateSet: map[string]*config.Rate{
|
||||
"Rate0": {
|
||||
Period: parse.Duration(42 * time.Second),
|
||||
Average: 42,
|
||||
Burst: 42,
|
||||
},
|
||||
"Rate1": {
|
||||
Period: parse.Duration(42 * time.Second),
|
||||
Average: 42,
|
||||
Burst: 42,
|
||||
},
|
||||
},
|
||||
ExtractorFunc: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware13": {
|
||||
RedirectRegex: &config.RedirectRegex{
|
||||
Regex: "foobar",
|
||||
Replacement: "foobar",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
"Middleware13b": {
|
||||
RedirectScheme: &config.RedirectScheme{
|
||||
Scheme: "https",
|
||||
Port: "80",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
"Middleware14": {
|
||||
ReplacePath: &config.ReplacePath{
|
||||
Path: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware15": {
|
||||
ReplacePathRegex: &config.ReplacePathRegex{
|
||||
Regex: "foobar",
|
||||
Replacement: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware16": {
|
||||
Retry: &config.Retry{
|
||||
Attempts: 42,
|
||||
},
|
||||
},
|
||||
"Middleware17": {
|
||||
StripPrefix: &config.StripPrefix{
|
||||
Prefixes: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
},
|
||||
},
|
||||
"Middleware18": {
|
||||
StripPrefixRegex: &config.StripPrefixRegex{
|
||||
Regex: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
},
|
||||
},
|
||||
"Middleware19": {
|
||||
Compress: &config.Compress{},
|
||||
},
|
||||
"Middleware2": {
|
||||
Buffering: &config.Buffering{
|
||||
MaxRequestBodyBytes: 42,
|
||||
MemRequestBodyBytes: 42,
|
||||
MaxResponseBodyBytes: 42,
|
||||
MemResponseBodyBytes: 42,
|
||||
RetryExpression: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware3": {
|
||||
Chain: &config.Chain{
|
||||
Middlewares: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
},
|
||||
},
|
||||
"Middleware4": {
|
||||
CircuitBreaker: &config.CircuitBreaker{
|
||||
Expression: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware5": {
|
||||
DigestAuth: &config.DigestAuth{
|
||||
Users: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
UsersFile: "foobar",
|
||||
RemoveHeader: true,
|
||||
Realm: "foobar",
|
||||
HeaderField: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware6": {
|
||||
Errors: &config.ErrorPage{
|
||||
Status: []string{
|
||||
expected := &config.Configuration{
|
||||
TCP: &config.TCPConfiguration{
|
||||
Routers: map[string]*config.TCPRouter{
|
||||
"Router0": {
|
||||
EntryPoints: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Service: "foobar",
|
||||
Query: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware7": {
|
||||
ForwardAuth: &config.ForwardAuth{
|
||||
Address: "foobar",
|
||||
TLS: &config.ClientTLS{
|
||||
CA: "foobar",
|
||||
CAOptional: true,
|
||||
Cert: "foobar",
|
||||
Key: "foobar",
|
||||
InsecureSkipVerify: true,
|
||||
Rule: "foobar",
|
||||
TLS: &config.RouterTCPTLSConfig{
|
||||
Passthrough: false,
|
||||
},
|
||||
TrustForwardHeader: true,
|
||||
AuthResponseHeaders: []string{
|
||||
},
|
||||
"Router1": {
|
||||
EntryPoints: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Service: "foobar",
|
||||
Rule: "foobar",
|
||||
TLS: &config.RouterTCPTLSConfig{
|
||||
Passthrough: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
"Middleware8": {
|
||||
Headers: &config.Headers{
|
||||
CustomRequestHeaders: map[string]string{
|
||||
"name0": "foobar",
|
||||
"name1": "foobar",
|
||||
Services: map[string]*config.TCPService{
|
||||
"Service0": {
|
||||
LoadBalancer: &config.TCPLoadBalancerService{
|
||||
Servers: []config.TCPServer{
|
||||
{
|
||||
Port: "42",
|
||||
Weight: 42,
|
||||
},
|
||||
},
|
||||
Method: "foobar",
|
||||
},
|
||||
CustomResponseHeaders: map[string]string{
|
||||
"name0": "foobar",
|
||||
"name1": "foobar",
|
||||
},
|
||||
"Service1": {
|
||||
LoadBalancer: &config.TCPLoadBalancerService{
|
||||
Servers: []config.TCPServer{
|
||||
{
|
||||
Port: "42",
|
||||
Weight: 42,
|
||||
},
|
||||
},
|
||||
Method: "foobar",
|
||||
},
|
||||
AccessControlAllowCredentials: true,
|
||||
AccessControlAllowHeaders: []string{
|
||||
"X-foobar",
|
||||
"X-fiibar",
|
||||
},
|
||||
AccessControlAllowMethods: []string{
|
||||
"GET",
|
||||
"PUT",
|
||||
},
|
||||
AccessControlAllowOrigin: "foobar",
|
||||
AccessControlExposeHeaders: []string{
|
||||
"X-foobar",
|
||||
"X-fiibar",
|
||||
},
|
||||
AccessControlMaxAge: 200,
|
||||
AddVaryHeader: true,
|
||||
AllowedHosts: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
HostsProxyHeaders: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
SSLRedirect: true,
|
||||
SSLTemporaryRedirect: true,
|
||||
SSLHost: "foobar",
|
||||
SSLProxyHeaders: map[string]string{
|
||||
"name0": "foobar",
|
||||
"name1": "foobar",
|
||||
},
|
||||
SSLForceHost: true,
|
||||
STSSeconds: 42,
|
||||
STSIncludeSubdomains: true,
|
||||
STSPreload: true,
|
||||
ForceSTSHeader: true,
|
||||
FrameDeny: true,
|
||||
CustomFrameOptionsValue: "foobar",
|
||||
ContentTypeNosniff: true,
|
||||
BrowserXSSFilter: true,
|
||||
CustomBrowserXSSValue: "foobar",
|
||||
ContentSecurityPolicy: "foobar",
|
||||
PublicKey: "foobar",
|
||||
ReferrerPolicy: "foobar",
|
||||
IsDevelopment: true,
|
||||
},
|
||||
},
|
||||
"Middleware9": {
|
||||
IPWhiteList: &config.IPWhiteList{
|
||||
SourceRange: []string{
|
||||
},
|
||||
HTTP: &config.HTTPConfiguration{
|
||||
Routers: map[string]*config.Router{
|
||||
"Router0": {
|
||||
EntryPoints: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
IPStrategy: &config.IPStrategy{
|
||||
Depth: 42,
|
||||
ExcludedIPs: []string{
|
||||
Middlewares: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Service: "foobar",
|
||||
Rule: "foobar",
|
||||
Priority: 42,
|
||||
TLS: &config.RouterTLSConfig{},
|
||||
},
|
||||
"Router1": {
|
||||
EntryPoints: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Middlewares: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Service: "foobar",
|
||||
Rule: "foobar",
|
||||
Priority: 42,
|
||||
},
|
||||
},
|
||||
Middlewares: map[string]*config.Middleware{
|
||||
"Middleware0": {
|
||||
AddPrefix: &config.AddPrefix{
|
||||
Prefix: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware1": {
|
||||
BasicAuth: &config.BasicAuth{
|
||||
Users: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
UsersFile: "foobar",
|
||||
Realm: "foobar",
|
||||
RemoveHeader: true,
|
||||
HeaderField: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware10": {
|
||||
MaxConn: &config.MaxConn{
|
||||
Amount: 42,
|
||||
ExtractorFunc: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware11": {
|
||||
PassTLSClientCert: &config.PassTLSClientCert{
|
||||
PEM: true,
|
||||
Info: &config.TLSClientCertificateInfo{
|
||||
NotAfter: true,
|
||||
NotBefore: true,
|
||||
Subject: &config.TLSCLientCertificateDNInfo{
|
||||
Country: true,
|
||||
Province: true,
|
||||
Locality: true,
|
||||
Organization: true,
|
||||
CommonName: true,
|
||||
SerialNumber: true,
|
||||
DomainComponent: true,
|
||||
},
|
||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
||||
Country: true,
|
||||
Province: true,
|
||||
Locality: true,
|
||||
Organization: true,
|
||||
CommonName: true,
|
||||
SerialNumber: true,
|
||||
DomainComponent: true,
|
||||
},
|
||||
Sans: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
"Middleware12": {
|
||||
RateLimit: &config.RateLimit{
|
||||
RateSet: map[string]*config.Rate{
|
||||
"Rate0": {
|
||||
Period: parse.Duration(42 * time.Second),
|
||||
Average: 42,
|
||||
Burst: 42,
|
||||
},
|
||||
"Rate1": {
|
||||
Period: parse.Duration(42 * time.Second),
|
||||
Average: 42,
|
||||
Burst: 42,
|
||||
},
|
||||
},
|
||||
ExtractorFunc: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware13": {
|
||||
RedirectRegex: &config.RedirectRegex{
|
||||
Regex: "foobar",
|
||||
Replacement: "foobar",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
"Middleware13b": {
|
||||
RedirectScheme: &config.RedirectScheme{
|
||||
Scheme: "https",
|
||||
Port: "80",
|
||||
Permanent: true,
|
||||
},
|
||||
},
|
||||
"Middleware14": {
|
||||
ReplacePath: &config.ReplacePath{
|
||||
Path: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware15": {
|
||||
ReplacePathRegex: &config.ReplacePathRegex{
|
||||
Regex: "foobar",
|
||||
Replacement: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware16": {
|
||||
Retry: &config.Retry{
|
||||
Attempts: 42,
|
||||
},
|
||||
},
|
||||
"Middleware17": {
|
||||
StripPrefix: &config.StripPrefix{
|
||||
Prefixes: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Services: map[string]*config.Service{
|
||||
"Service0": {
|
||||
LoadBalancer: &config.LoadBalancerService{
|
||||
Stickiness: &config.Stickiness{
|
||||
CookieName: "foobar",
|
||||
},
|
||||
Servers: []config.Server{
|
||||
{
|
||||
Scheme: "foobar",
|
||||
Port: "8080",
|
||||
Weight: 42,
|
||||
"Middleware18": {
|
||||
StripPrefixRegex: &config.StripPrefixRegex{
|
||||
Regex: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
},
|
||||
Method: "foobar",
|
||||
HealthCheck: &config.HealthCheck{
|
||||
Scheme: "foobar",
|
||||
Path: "foobar",
|
||||
Port: 42,
|
||||
Interval: "foobar",
|
||||
Timeout: "foobar",
|
||||
Hostname: "foobar",
|
||||
Headers: map[string]string{
|
||||
},
|
||||
"Middleware19": {
|
||||
Compress: &config.Compress{},
|
||||
},
|
||||
"Middleware2": {
|
||||
Buffering: &config.Buffering{
|
||||
MaxRequestBodyBytes: 42,
|
||||
MemRequestBodyBytes: 42,
|
||||
MaxResponseBodyBytes: 42,
|
||||
MemResponseBodyBytes: 42,
|
||||
RetryExpression: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware3": {
|
||||
Chain: &config.Chain{
|
||||
Middlewares: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
},
|
||||
},
|
||||
"Middleware4": {
|
||||
CircuitBreaker: &config.CircuitBreaker{
|
||||
Expression: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware5": {
|
||||
DigestAuth: &config.DigestAuth{
|
||||
Users: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
UsersFile: "foobar",
|
||||
RemoveHeader: true,
|
||||
Realm: "foobar",
|
||||
HeaderField: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware6": {
|
||||
Errors: &config.ErrorPage{
|
||||
Status: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Service: "foobar",
|
||||
Query: "foobar",
|
||||
},
|
||||
},
|
||||
"Middleware7": {
|
||||
ForwardAuth: &config.ForwardAuth{
|
||||
Address: "foobar",
|
||||
TLS: &config.ClientTLS{
|
||||
CA: "foobar",
|
||||
CAOptional: true,
|
||||
Cert: "foobar",
|
||||
Key: "foobar",
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
TrustForwardHeader: true,
|
||||
AuthResponseHeaders: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
},
|
||||
},
|
||||
"Middleware8": {
|
||||
Headers: &config.Headers{
|
||||
CustomRequestHeaders: map[string]string{
|
||||
"name0": "foobar",
|
||||
"name1": "foobar",
|
||||
},
|
||||
CustomResponseHeaders: map[string]string{
|
||||
"name0": "foobar",
|
||||
"name1": "foobar",
|
||||
},
|
||||
AccessControlAllowCredentials: true,
|
||||
AccessControlAllowHeaders: []string{
|
||||
"X-foobar",
|
||||
"X-fiibar",
|
||||
},
|
||||
AccessControlAllowMethods: []string{
|
||||
"GET",
|
||||
"PUT",
|
||||
},
|
||||
AccessControlAllowOrigin: "foobar",
|
||||
AccessControlExposeHeaders: []string{
|
||||
"X-foobar",
|
||||
"X-fiibar",
|
||||
},
|
||||
AccessControlMaxAge: 200,
|
||||
AddVaryHeader: true,
|
||||
AllowedHosts: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
HostsProxyHeaders: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
SSLRedirect: true,
|
||||
SSLTemporaryRedirect: true,
|
||||
SSLHost: "foobar",
|
||||
SSLProxyHeaders: map[string]string{
|
||||
"name0": "foobar",
|
||||
"name1": "foobar",
|
||||
},
|
||||
SSLForceHost: true,
|
||||
STSSeconds: 42,
|
||||
STSIncludeSubdomains: true,
|
||||
STSPreload: true,
|
||||
ForceSTSHeader: true,
|
||||
FrameDeny: true,
|
||||
CustomFrameOptionsValue: "foobar",
|
||||
ContentTypeNosniff: true,
|
||||
BrowserXSSFilter: true,
|
||||
CustomBrowserXSSValue: "foobar",
|
||||
ContentSecurityPolicy: "foobar",
|
||||
PublicKey: "foobar",
|
||||
ReferrerPolicy: "foobar",
|
||||
IsDevelopment: true,
|
||||
},
|
||||
PassHostHeader: true,
|
||||
ResponseForwarding: &config.ResponseForwarding{
|
||||
FlushInterval: "foobar",
|
||||
},
|
||||
"Middleware9": {
|
||||
IPWhiteList: &config.IPWhiteList{
|
||||
SourceRange: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
IPStrategy: &config.IPStrategy{
|
||||
Depth: 42,
|
||||
ExcludedIPs: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"Service1": {
|
||||
LoadBalancer: &config.LoadBalancerService{
|
||||
Servers: []config.Server{
|
||||
{
|
||||
Scheme: "foobar",
|
||||
Port: "8080",
|
||||
Weight: 1,
|
||||
Services: map[string]*config.Service{
|
||||
"Service0": {
|
||||
LoadBalancer: &config.LoadBalancerService{
|
||||
Stickiness: &config.Stickiness{
|
||||
CookieName: "foobar",
|
||||
},
|
||||
Servers: []config.Server{
|
||||
{
|
||||
Scheme: "foobar",
|
||||
Port: "8080",
|
||||
Weight: 42,
|
||||
},
|
||||
},
|
||||
Method: "foobar",
|
||||
HealthCheck: &config.HealthCheck{
|
||||
Scheme: "foobar",
|
||||
Path: "foobar",
|
||||
Port: 42,
|
||||
Interval: "foobar",
|
||||
Timeout: "foobar",
|
||||
Hostname: "foobar",
|
||||
Headers: map[string]string{
|
||||
"name0": "foobar",
|
||||
"name1": "foobar",
|
||||
},
|
||||
},
|
||||
PassHostHeader: true,
|
||||
ResponseForwarding: &config.ResponseForwarding{
|
||||
FlushInterval: "foobar",
|
||||
},
|
||||
},
|
||||
Method: "foobar",
|
||||
HealthCheck: &config.HealthCheck{
|
||||
Scheme: "foobar",
|
||||
Path: "foobar",
|
||||
Port: 42,
|
||||
Interval: "foobar",
|
||||
Timeout: "foobar",
|
||||
Hostname: "foobar",
|
||||
Headers: map[string]string{
|
||||
"name0": "foobar",
|
||||
"name1": "foobar",
|
||||
},
|
||||
"Service1": {
|
||||
LoadBalancer: &config.LoadBalancerService{
|
||||
Servers: []config.Server{
|
||||
{
|
||||
Scheme: "foobar",
|
||||
Port: "8080",
|
||||
Weight: 1,
|
||||
},
|
||||
},
|
||||
Method: "foobar",
|
||||
HealthCheck: &config.HealthCheck{
|
||||
Scheme: "foobar",
|
||||
Path: "foobar",
|
||||
Port: 42,
|
||||
Interval: "foobar",
|
||||
Timeout: "foobar",
|
||||
Hostname: "foobar",
|
||||
Headers: map[string]string{
|
||||
"name0": "foobar",
|
||||
"name1": "foobar",
|
||||
},
|
||||
},
|
||||
PassHostHeader: true,
|
||||
ResponseForwarding: &config.ResponseForwarding{
|
||||
FlushInterval: "foobar",
|
||||
},
|
||||
},
|
||||
PassHostHeader: true,
|
||||
ResponseForwarding: &config.ResponseForwarding{
|
||||
FlushInterval: "foobar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, expected, configuration.HTTP)
|
||||
assert.Equal(t, expected, configuration)
|
||||
}
|
||||
|
||||
func TestEncodeConfiguration(t *testing.T) {
|
||||
configuration := &config.Configuration{
|
||||
TCP: &config.TCPConfiguration{
|
||||
Routers: map[string]*config.TCPRouter{
|
||||
"Router0": {
|
||||
EntryPoints: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Service: "foobar",
|
||||
Rule: "foobar",
|
||||
TLS: &config.RouterTCPTLSConfig{
|
||||
Passthrough: false,
|
||||
},
|
||||
},
|
||||
"Router1": {
|
||||
EntryPoints: []string{
|
||||
"foobar",
|
||||
"fiibar",
|
||||
},
|
||||
Service: "foobar",
|
||||
Rule: "foobar",
|
||||
TLS: &config.RouterTCPTLSConfig{
|
||||
Passthrough: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
Services: map[string]*config.TCPService{
|
||||
"Service0": {
|
||||
LoadBalancer: &config.TCPLoadBalancerService{
|
||||
Servers: []config.TCPServer{
|
||||
{
|
||||
Port: "42",
|
||||
Weight: 42,
|
||||
},
|
||||
},
|
||||
Method: "foobar",
|
||||
},
|
||||
},
|
||||
"Service1": {
|
||||
LoadBalancer: &config.TCPLoadBalancerService{
|
||||
Servers: []config.TCPServer{
|
||||
{
|
||||
Port: "42",
|
||||
Weight: 42,
|
||||
},
|
||||
},
|
||||
Method: "foobar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
HTTP: &config.HTTPConfiguration{
|
||||
Routers: map[string]*config.Router{
|
||||
"Router0": {
|
||||
|
@ -1010,6 +1126,21 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
"traefik.HTTP.Services.Service1.LoadBalancer.server.Scheme": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Headers.name0": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.server.Weight": "42",
|
||||
|
||||
"traefik.TCP.Routers.Router0.Rule": "foobar",
|
||||
"traefik.TCP.Routers.Router0.EntryPoints": "foobar, fiibar",
|
||||
"traefik.TCP.Routers.Router0.Service": "foobar",
|
||||
"traefik.TCP.Routers.Router0.TLS.Passthrough": "false",
|
||||
"traefik.TCP.Routers.Router1.Rule": "foobar",
|
||||
"traefik.TCP.Routers.Router1.EntryPoints": "foobar, fiibar",
|
||||
"traefik.TCP.Routers.Router1.Service": "foobar",
|
||||
"traefik.TCP.Routers.Router1.TLS.Passthrough": "false",
|
||||
"traefik.TCP.Services.Service0.LoadBalancer.Method": "foobar",
|
||||
"traefik.TCP.Services.Service0.LoadBalancer.server.Port": "42",
|
||||
"traefik.TCP.Services.Service0.LoadBalancer.server.Weight": "42",
|
||||
"traefik.TCP.Services.Service1.LoadBalancer.Method": "foobar",
|
||||
"traefik.TCP.Services.Service1.LoadBalancer.server.Port": "42",
|
||||
"traefik.TCP.Services.Service1.LoadBalancer.server.Weight": "42",
|
||||
}
|
||||
|
||||
for key, val := range expected {
|
||||
|
|
|
@ -39,6 +39,21 @@ func (p *Provider) buildConfiguration(ctx context.Context, applications *maratho
|
|||
continue
|
||||
}
|
||||
|
||||
if len(confFromLabel.TCP.Routers) > 0 || len(confFromLabel.TCP.Services) > 0 {
|
||||
err := p.buildTCPServiceConfiguration(ctxApp, app, extraConf, confFromLabel.TCP)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
continue
|
||||
}
|
||||
provider.BuildTCPRouterConfiguration(ctxApp, confFromLabel.TCP)
|
||||
if len(confFromLabel.HTTP.Routers) == 0 &&
|
||||
len(confFromLabel.HTTP.Middlewares) == 0 &&
|
||||
len(confFromLabel.HTTP.Services) == 0 {
|
||||
configurations[app.ID] = confFromLabel
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
err = p.buildServiceConfiguration(ctxApp, app, extraConf, confFromLabel.HTTP)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
|
@ -109,6 +124,48 @@ func (p *Provider) buildServiceConfiguration(ctx context.Context, app marathon.A
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, app marathon.Application, extraConf configuration, conf *config.TCPConfiguration) error {
|
||||
appName := getServiceName(app)
|
||||
appCtx := log.With(ctx, log.Str("ApplicationID", appName))
|
||||
|
||||
if len(conf.Services) == 0 {
|
||||
conf.Services = make(map[string]*config.TCPService)
|
||||
lb := &config.TCPLoadBalancerService{}
|
||||
lb.SetDefaults()
|
||||
conf.Services[appName] = &config.TCPService{
|
||||
LoadBalancer: lb,
|
||||
}
|
||||
}
|
||||
|
||||
for serviceName, service := range conf.Services {
|
||||
var servers []config.TCPServer
|
||||
|
||||
defaultServer := config.TCPServer{}
|
||||
defaultServer.SetDefaults()
|
||||
|
||||
if len(service.LoadBalancer.Servers) > 0 {
|
||||
defaultServer = service.LoadBalancer.Servers[0]
|
||||
}
|
||||
|
||||
for _, task := range app.Tasks {
|
||||
if p.taskFilter(ctx, *task, app) {
|
||||
server, err := p.getTCPServer(app, *task, extraConf, defaultServer)
|
||||
if err != nil {
|
||||
log.FromContext(appCtx).Errorf("Skip task: %v", err)
|
||||
continue
|
||||
}
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
if len(servers) == 0 {
|
||||
return fmt.Errorf("no server for the service %s", serviceName)
|
||||
}
|
||||
service.LoadBalancer.Servers = servers
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Provider) keepApplication(ctx context.Context, extraConf configuration) bool {
|
||||
logger := log.FromContext(ctx)
|
||||
|
||||
|
@ -142,6 +199,25 @@ func (p *Provider) taskFilter(ctx context.Context, task marathon.Task, applicati
|
|||
return true
|
||||
}
|
||||
|
||||
func (p *Provider) getTCPServer(app marathon.Application, task marathon.Task, extraConf configuration, defaultServer config.TCPServer) (config.TCPServer, error) {
|
||||
host, err := p.getServerHost(task, app, extraConf)
|
||||
if len(host) == 0 {
|
||||
return config.TCPServer{}, err
|
||||
}
|
||||
|
||||
port, err := getPort(task, app, defaultServer.Port)
|
||||
if err != nil {
|
||||
return config.TCPServer{}, err
|
||||
}
|
||||
|
||||
server := config.TCPServer{
|
||||
Address: net.JoinHostPort(host, port),
|
||||
Weight: 1,
|
||||
}
|
||||
|
||||
return server, nil
|
||||
}
|
||||
|
||||
func (p *Provider) getServer(app marathon.Application, task marathon.Task, extraConf configuration, defaultServer config.Server) (config.Server, error) {
|
||||
host, err := p.getServerHost(task, app, extraConf)
|
||||
if len(host) == 0 {
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue