1
0
Fork 0

rework loadbalancer support

This commit is contained in:
Julien Salleyron 2019-06-05 22:18:06 +02:00 committed by Traefiker Bot
parent b143101f82
commit 518a37e776
86 changed files with 339 additions and 1055 deletions

View file

@ -41,7 +41,6 @@ type RouterTCPTLSConfig struct {
type LoadBalancerService struct {
Stickiness *Stickiness `json:"stickiness,omitempty" toml:",omitempty" label:"allowEmpty"`
Servers []Server `json:"servers,omitempty" toml:",omitempty" label-slice-as-struct:"server"`
Method string `json:"method,omitempty" toml:",omitempty"`
HealthCheck *HealthCheck `json:"healthCheck,omitempty" toml:",omitempty"`
PassHostHeader bool `json:"passHostHeader" toml:",omitempty"`
ResponseForwarding *ResponseForwarding `json:"forwardingResponse,omitempty" toml:",omitempty"`
@ -50,7 +49,6 @@ type LoadBalancerService struct {
// TCPLoadBalancerService holds the LoadBalancerService configuration.
type TCPLoadBalancerService struct {
Servers []TCPServer `json:"servers,omitempty" toml:",omitempty" label-slice-as-struct:"server"`
Method string `json:"method,omitempty" toml:",omitempty"`
}
// Mergeable tells if the given service is mergeable.
@ -87,15 +85,9 @@ func (l *LoadBalancerService) Mergeable(loadBalancer *LoadBalancerService) bool
return reflect.DeepEqual(l, loadBalancer)
}
// SetDefaults Default values for a TCPLoadBalancerService.
func (l *TCPLoadBalancerService) SetDefaults() {
l.Method = "wrr"
}
// SetDefaults Default values for a LoadBalancerService.
func (l *LoadBalancerService) SetDefaults() {
l.PassHostHeader = true
l.Method = "wrr"
}
// ResponseForwarding holds configuration for the forward of the response.
@ -113,24 +105,16 @@ type Server struct {
URL string `json:"url" label:"-"`
Scheme string `toml:"-" json:"-"`
Port string `toml:"-" json:"-"`
Weight int `json:"weight"`
}
// TCPServer holds a TCP Server configuration
type TCPServer struct {
Address string `json:"address" label:"-"`
Port string `toml:"-" json:"-"`
Weight int `json:"weight"`
}
// SetDefaults Default values for a Server.
func (s *TCPServer) SetDefaults() {
s.Weight = 1
}
// SetDefaults Default values for a Server.
func (s *Server) SetDefaults() {
s.Weight = 1
s.Scheme = "http"
}

View file

@ -44,16 +44,9 @@ func TestPopulateUsedby(t *testing.T) {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:8085",
Weight: 1,
},
{
URL: "http://127.0.0.1:8086",
Weight: 1,
},
{URL: "http://127.0.0.1:8085"},
{URL: "http://127.0.0.1:8086"},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -83,12 +76,8 @@ func TestPopulateUsedby(t *testing.T) {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
{URL: "http://127.0.0.1"},
},
Method: "wrr",
},
},
},
@ -162,15 +151,12 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:8085",
Weight: 1,
URL: "http://127.0.0.1:8085",
},
{
URL: "http://127.0.0.1:8086",
Weight: 1,
URL: "http://127.0.0.1:8086",
},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -183,15 +169,12 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:8087",
Weight: 1,
URL: "http://127.0.0.1:8087",
},
{
URL: "http://127.0.0.1:8088",
Weight: 1,
URL: "http://127.0.0.1:8088",
},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -241,11 +224,9 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -314,11 +295,9 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -360,11 +339,9 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -414,11 +391,9 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -517,15 +492,12 @@ func TestPopulateUsedby(t *testing.T) {
{
Address: "127.0.0.1",
Port: "8085",
Weight: 1,
},
{
Address: "127.0.0.1",
Port: "8086",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -553,10 +525,8 @@ func TestPopulateUsedby(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -632,15 +602,12 @@ func TestPopulateUsedby(t *testing.T) {
{
Address: "127.0.0.1",
Port: "8085",
Weight: 1,
},
{
Address: "127.0.0.1",
Port: "8086",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -651,15 +618,12 @@ func TestPopulateUsedby(t *testing.T) {
{
Address: "127.0.0.1",
Port: "8087",
Weight: 1,
},
{
Address: "127.0.0.1",
Port: "8088",
Weight: 1,
},
},
Method: "wrr",
},
},
},