Add p2c load-balancing strategy for servers load-balancer
Co-authored-by: Ian Ross <ifross@gmail.com> Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
parent
550d96ea67
commit
9e029a84c4
50 changed files with 1621 additions and 382 deletions
|
@ -211,12 +211,22 @@ func (c *Cookie) SetDefaults() {
|
|||
c.Path = &defaultPath
|
||||
}
|
||||
|
||||
type BalancerStrategy string
|
||||
|
||||
const (
|
||||
// BalancerStrategyWRR is the weighted round-robin strategy.
|
||||
BalancerStrategyWRR BalancerStrategy = "wrr"
|
||||
// BalancerStrategyP2C is the power of two choices strategy.
|
||||
BalancerStrategyP2C BalancerStrategy = "p2c"
|
||||
)
|
||||
|
||||
// +k8s:deepcopy-gen=true
|
||||
|
||||
// ServersLoadBalancer holds the ServersLoadBalancer configuration.
|
||||
type ServersLoadBalancer struct {
|
||||
Sticky *Sticky `json:"sticky,omitempty" toml:"sticky,omitempty" yaml:"sticky,omitempty" label:"allowEmpty" file:"allowEmpty" kv:"allowEmpty" export:"true"`
|
||||
Servers []Server `json:"servers,omitempty" toml:"servers,omitempty" yaml:"servers,omitempty" label-slice-as-struct:"server" export:"true"`
|
||||
Sticky *Sticky `json:"sticky,omitempty" toml:"sticky,omitempty" yaml:"sticky,omitempty" label:"allowEmpty" file:"allowEmpty" kv:"allowEmpty" export:"true"`
|
||||
Servers []Server `json:"servers,omitempty" toml:"servers,omitempty" yaml:"servers,omitempty" label-slice-as-struct:"server" export:"true"`
|
||||
Strategy BalancerStrategy `json:"strategy,omitempty" toml:"strategy,omitempty" yaml:"strategy,omitempty" export:"true"`
|
||||
// HealthCheck enables regular active checks of the responsiveness of the
|
||||
// children servers of this load-balancer. To propagate status changes (e.g. all
|
||||
// servers of this service are down) upwards, HealthCheck must also be enabled on
|
||||
|
@ -249,6 +259,7 @@ func (l *ServersLoadBalancer) SetDefaults() {
|
|||
defaultPassHostHeader := DefaultPassHostHeader
|
||||
l.PassHostHeader = &defaultPassHostHeader
|
||||
|
||||
l.Strategy = BalancerStrategyWRR
|
||||
l.ResponseForwarding = &ResponseForwarding{}
|
||||
l.ResponseForwarding.SetDefaults()
|
||||
}
|
||||
|
|
|
@ -172,6 +172,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
"traefik.http.services.Service0.loadbalancer.healthcheck.followredirects": "true",
|
||||
"traefik.http.services.Service0.loadbalancer.passhostheader": "true",
|
||||
"traefik.http.services.Service0.loadbalancer.responseforwarding.flushinterval": "1s",
|
||||
"traefik.http.services.Service0.loadbalancer.strategy": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.server.url": "foobar",
|
||||
"traefik.http.services.Service0.loadbalancer.server.preservepath": "true",
|
||||
"traefik.http.services.Service0.loadbalancer.server.scheme": "foobar",
|
||||
|
@ -195,6 +196,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
"traefik.http.services.Service1.loadbalancer.healthcheck.followredirects": "true",
|
||||
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
|
||||
"traefik.http.services.Service1.loadbalancer.responseforwarding.flushinterval": "1s",
|
||||
"traefik.http.services.Service1.loadbalancer.strategy": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.server.url": "foobar",
|
||||
"traefik.http.services.Service1.loadbalancer.server.preservepath": "true",
|
||||
"traefik.http.services.Service1.loadbalancer.server.scheme": "foobar",
|
||||
|
@ -680,6 +682,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
Services: map[string]*dynamic.Service{
|
||||
"Service0": {
|
||||
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||
Strategy: "foobar",
|
||||
Sticky: &dynamic.Sticky{
|
||||
Cookie: &dynamic.Cookie{
|
||||
Name: "foobar",
|
||||
|
@ -722,6 +725,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
|||
},
|
||||
"Service1": {
|
||||
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||
Strategy: "foobar",
|
||||
Servers: []dynamic.Server{
|
||||
{
|
||||
URL: "foobar",
|
||||
|
@ -1222,6 +1226,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
Services: map[string]*dynamic.Service{
|
||||
"Service0": {
|
||||
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||
Strategy: "foobar",
|
||||
Sticky: &dynamic.Sticky{
|
||||
Cookie: &dynamic.Cookie{
|
||||
Name: "foobar",
|
||||
|
@ -1261,6 +1266,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
},
|
||||
"Service1": {
|
||||
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||
Strategy: "foobar",
|
||||
Servers: []dynamic.Server{
|
||||
{
|
||||
URL: "foobar",
|
||||
|
@ -1473,6 +1479,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Timeout": "1000000000",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.PassHostHeader": "true",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.ResponseForwarding.FlushInterval": "1000000000",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.Strategy": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.server.URL": "foobar",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.server.PreservePath": "true",
|
||||
"traefik.HTTP.Services.Service0.LoadBalancer.server.Port": "8080",
|
||||
|
@ -1496,6 +1503,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
|||
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Timeout": "1000000000",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.PassHostHeader": "true",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.ResponseForwarding.FlushInterval": "1000000000",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.Strategy": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.server.URL": "foobar",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.server.PreservePath": "true",
|
||||
"traefik.HTTP.Services.Service1.LoadBalancer.server.Port": "8080",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue