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
|
@ -21,9 +21,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
roundRobinStrategy = "RoundRobin"
|
||||
httpsProtocol = "https"
|
||||
httpProtocol = "http"
|
||||
httpsProtocol = "https"
|
||||
httpProtocol = "http"
|
||||
)
|
||||
|
||||
func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *dynamic.HTTPConfiguration {
|
||||
|
@ -322,13 +321,33 @@ func (c configBuilder) buildMirroring(ctx context.Context, tService *traefikv1al
|
|||
|
||||
// buildServersLB creates the configuration for the load-balancer of servers defined by svc.
|
||||
func (c configBuilder) buildServersLB(namespace string, svc traefikv1alpha1.LoadBalancerSpec) (*dynamic.Service, error) {
|
||||
lb := &dynamic.ServersLoadBalancer{}
|
||||
lb.SetDefaults()
|
||||
|
||||
// This is required by the tests as the fake client does not apply default values.
|
||||
// TODO: remove this when the fake client apply default values.
|
||||
if svc.Strategy != "" {
|
||||
switch svc.Strategy {
|
||||
case dynamic.BalancerStrategyWRR, dynamic.BalancerStrategyP2C:
|
||||
lb.Strategy = svc.Strategy
|
||||
|
||||
// Here we are just logging a warning as the default value is already applied.
|
||||
case "RoundRobin":
|
||||
log.Warn().
|
||||
Str("namespace", namespace).
|
||||
Str("service", svc.Name).
|
||||
Msgf("RoundRobin strategy value is deprecated, please use %s value instead", dynamic.BalancerStrategyWRR)
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("load-balancer strategy %s is not supported", svc.Strategy)
|
||||
}
|
||||
}
|
||||
|
||||
servers, err := c.loadServers(namespace, svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lb := &dynamic.ServersLoadBalancer{}
|
||||
lb.SetDefaults()
|
||||
lb.Servers = servers
|
||||
|
||||
if svc.HealthCheck != nil {
|
||||
|
@ -421,14 +440,6 @@ func (c configBuilder) makeServersTransportKey(parentNamespace string, serversTr
|
|||
}
|
||||
|
||||
func (c configBuilder) loadServers(parentNamespace string, svc traefikv1alpha1.LoadBalancerSpec) ([]dynamic.Server, error) {
|
||||
strategy := svc.Strategy
|
||||
if strategy == "" {
|
||||
strategy = roundRobinStrategy
|
||||
}
|
||||
if strategy != roundRobinStrategy {
|
||||
return nil, fmt.Errorf("load balancing strategy %s is not supported", strategy)
|
||||
}
|
||||
|
||||
namespace := namespaceOrFallback(svc, parentNamespace)
|
||||
|
||||
if !isNamespaceAllowed(c.allowCrossNamespace, parentNamespace, namespace) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue