1
0
Fork 0

Add TCP Servers Transports support

Co-authored-by: Romain <rtribotte@users.noreply.github.com>
This commit is contained in:
Simon Delicata 2022-12-09 09:58:05 +01:00 committed by GitHub
parent c2dac39da1
commit 3eeea2bb2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
101 changed files with 5956 additions and 1669 deletions

View file

@ -41,6 +41,17 @@ func (p *Provider) buildConfiguration(ctx context.Context, items []itemData, cer
if len(confFromLabel.TCP.Routers) > 0 || len(confFromLabel.TCP.Services) > 0 {
tcpOrUDP = true
if item.ExtraConf.ConsulCatalog.Connect {
if confFromLabel.TCP.ServersTransports == nil {
confFromLabel.TCP.ServersTransports = make(map[string]*dynamic.TCPServersTransport)
}
serversTransportKey := itemServersTransportKey(item)
if confFromLabel.TCP.ServersTransports[serversTransportKey] == nil {
confFromLabel.TCP.ServersTransports[serversTransportKey] = certInfo.tcpServersTransport(item)
}
}
if err := p.buildTCPServiceConfiguration(item, confFromLabel.TCP); err != nil {
logger.Error().Err(err).Send()
continue
@ -131,13 +142,10 @@ func (p *Provider) keepContainer(ctx context.Context, item itemData) bool {
func (p *Provider) buildTCPServiceConfiguration(item itemData, configuration *dynamic.TCPConfiguration) error {
if len(configuration.Services) == 0 {
configuration.Services = make(map[string]*dynamic.TCPService)
lb := &dynamic.TCPServersLoadBalancer{}
lb.SetDefaults()
configuration.Services[getName(item)] = &dynamic.TCPService{
LoadBalancer: lb,
configuration.Services = map[string]*dynamic.TCPService{
getName(item): {
LoadBalancer: new(dynamic.TCPServersLoadBalancer),
},
}
}
@ -215,6 +223,14 @@ func (p *Provider) addServerTCP(item itemData, loadBalancer *dynamic.TCPServersL
return errors.New("port is missing")
}
if item.Address == "" {
return errors.New("address is missing")
}
if item.ExtraConf.ConsulCatalog.Connect {
loadBalancer.ServersTransport = itemServersTransportKey(item)
}
loadBalancer.Servers[0].Address = net.JoinHostPort(item.Address, port)
return nil