fix: invalid service definition.
This commit is contained in:
parent
6c4d7fd377
commit
9544dece07
2 changed files with 79 additions and 3 deletions
|
@ -89,7 +89,7 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, container d
|
||||||
ctxSvc := log.With(ctx, log.Str(log.ServiceName, name))
|
ctxSvc := log.With(ctx, log.Str(log.ServiceName, name))
|
||||||
err := p.addServerTCP(ctxSvc, container, service.LoadBalancer)
|
err := p.addServerTCP(ctxSvc, container, service.LoadBalancer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("service %q error: %w", name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ func (p *Provider) buildServiceConfiguration(ctx context.Context, container dock
|
||||||
ctxSvc := log.With(ctx, log.Str(log.ServiceName, name))
|
ctxSvc := log.With(ctx, log.Str(log.ServiceName, name))
|
||||||
err := p.addServer(ctxSvc, container, service.LoadBalancer)
|
err := p.addServer(ctxSvc, container, service.LoadBalancer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("service %q error: %w", name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,8 +146,12 @@ func (p *Provider) keepContainer(ctx context.Context, container dockerData) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) addServerTCP(ctx context.Context, container dockerData, loadBalancer *dynamic.TCPServersLoadBalancer) error {
|
func (p *Provider) addServerTCP(ctx context.Context, container dockerData, loadBalancer *dynamic.TCPServersLoadBalancer) error {
|
||||||
|
if loadBalancer == nil {
|
||||||
|
return errors.New("load-balancer is not defined")
|
||||||
|
}
|
||||||
|
|
||||||
serverPort := ""
|
serverPort := ""
|
||||||
if loadBalancer != nil && len(loadBalancer.Servers) > 0 {
|
if len(loadBalancer.Servers) > 0 {
|
||||||
serverPort = loadBalancer.Servers[0].Port
|
serverPort = loadBalancer.Servers[0].Port
|
||||||
}
|
}
|
||||||
ip, port, err := p.getIPPort(ctx, container, serverPort)
|
ip, port, err := p.getIPPort(ctx, container, serverPort)
|
||||||
|
@ -175,6 +179,10 @@ func (p *Provider) addServerTCP(ctx context.Context, container dockerData, loadB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) addServer(ctx context.Context, container dockerData, loadBalancer *dynamic.ServersLoadBalancer) error {
|
func (p *Provider) addServer(ctx context.Context, container dockerData, loadBalancer *dynamic.ServersLoadBalancer) error {
|
||||||
|
if loadBalancer == nil {
|
||||||
|
return errors.New("load-balancer is not defined")
|
||||||
|
}
|
||||||
|
|
||||||
serverPort := getLBServerPort(loadBalancer)
|
serverPort := getLBServerPort(loadBalancer)
|
||||||
ip, port, err := p.getIPPort(ctx, container, serverPort)
|
ip, port, err := p.getIPPort(ctx, container, serverPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -344,6 +344,74 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
constraints string
|
constraints string
|
||||||
expected *dynamic.Configuration
|
expected *dynamic.Configuration
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
desc: "invalid HTTP service definition",
|
||||||
|
containers: []dockerData{
|
||||||
|
{
|
||||||
|
ServiceName: "Test",
|
||||||
|
Name: "Test",
|
||||||
|
Labels: map[string]string{
|
||||||
|
"traefik.http.services.test": "",
|
||||||
|
},
|
||||||
|
NetworkSettings: networkSettings{
|
||||||
|
Ports: nat.PortMap{
|
||||||
|
nat.Port("80/tcp"): []nat.PortBinding{},
|
||||||
|
},
|
||||||
|
Networks: map[string]*networkData{
|
||||||
|
"bridge": {
|
||||||
|
Name: "bridge",
|
||||||
|
Addr: "127.0.0.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &dynamic.Configuration{
|
||||||
|
TCP: &dynamic.TCPConfiguration{
|
||||||
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
|
Services: map[string]*dynamic.TCPService{},
|
||||||
|
},
|
||||||
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
|
Routers: map[string]*dynamic.Router{},
|
||||||
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
|
Services: map[string]*dynamic.Service{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "invalid TCP service definition",
|
||||||
|
containers: []dockerData{
|
||||||
|
{
|
||||||
|
ServiceName: "Test",
|
||||||
|
Name: "Test",
|
||||||
|
Labels: map[string]string{
|
||||||
|
"traefik.tcp.services.test": "",
|
||||||
|
},
|
||||||
|
NetworkSettings: networkSettings{
|
||||||
|
Ports: nat.PortMap{
|
||||||
|
nat.Port("80/tcp"): []nat.PortBinding{},
|
||||||
|
},
|
||||||
|
Networks: map[string]*networkData{
|
||||||
|
"bridge": {
|
||||||
|
Name: "bridge",
|
||||||
|
Addr: "127.0.0.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &dynamic.Configuration{
|
||||||
|
TCP: &dynamic.TCPConfiguration{
|
||||||
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
|
Services: map[string]*dynamic.TCPService{},
|
||||||
|
},
|
||||||
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
|
Routers: map[string]*dynamic.Router{},
|
||||||
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
|
Services: map[string]*dynamic.Service{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "one container no label",
|
desc: "one container no label",
|
||||||
containers: []dockerData{
|
containers: []dockerData{
|
||||||
|
|
Loading…
Reference in a new issue