mirror of
https://github.com/sablierapp/sablier.git
synced 2026-01-04 12:05:05 +01:00
fix(swarm): remove suffix match on name
This could bring too much complexity. If a new service was created with exact match, it would take pecedence over the previously suffix matched service. Closes #85
This commit is contained in:
@@ -307,10 +307,6 @@ http:
|
||||
|
||||
#### Traefik with Docker Swarm
|
||||
|
||||
- The value from the `names` section will do a strict match if possible, if it is not found it will match by suffix only if there's one match.
|
||||
- `names=nginx` matches `nginx` from `MYSTACK_nginx` and `nginx` services
|
||||
- `names=nginx` matches `MYSTACK_nginx` from `MYSTACK_nginx` and `nginx-2` services
|
||||
|
||||
⚠️ Limitations
|
||||
|
||||
- Traefik will evict the service from its pool as soon as the service is 0/0. You must add the [`traefik.docker.lbswarm`](https://doc.traefik.io/traefik/routing/providers/docker/#traefikdockerlbswarm) label.
|
||||
|
||||
@@ -106,29 +106,13 @@ func (provider *DockerSwarmProvider) getServiceByName(name string, ctx context.C
|
||||
return nil, fmt.Errorf(fmt.Sprintf("service with name %s was not found", name))
|
||||
}
|
||||
|
||||
suffixMatches := make([]swarm.Service, 0)
|
||||
suffixMatchNames := make([]string, 0)
|
||||
|
||||
for _, service := range services {
|
||||
// Exact match
|
||||
if service.Spec.Name == name {
|
||||
return &service, nil
|
||||
} else if strings.HasSuffix(service.Spec.Name, name) {
|
||||
suffixMatches = append(suffixMatches, service)
|
||||
suffixMatchNames = append(suffixMatchNames, service.Spec.Name)
|
||||
} else {
|
||||
log.Warnf("service %s was ignored because it did not match %s exactly or on suffix", service.Spec.Name, name)
|
||||
}
|
||||
}
|
||||
|
||||
if len(suffixMatches) > 1 {
|
||||
return nil, fmt.Errorf("ambiguous service names found for \"%s\" (%s)", name, strings.Join(suffixMatchNames, ", "))
|
||||
}
|
||||
|
||||
if len(suffixMatches) == 1 {
|
||||
return &suffixMatches[0], nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf(fmt.Sprintf("service %s was not found because it did not match exactly or on suffix", name))
|
||||
}
|
||||
|
||||
|
||||
@@ -46,28 +46,6 @@ func TestDockerSwarmProvider_Start(t *testing.T) {
|
||||
wantService: mocks.ServiceReplicated("nginx", 1),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ambiguous service name",
|
||||
args: args{
|
||||
name: "nginx",
|
||||
},
|
||||
serviceList: []swarm.Service{
|
||||
mocks.ServiceReplicated("STACK1_nginx", 0),
|
||||
mocks.ServiceReplicated("STACK2_nginx", 0),
|
||||
},
|
||||
response: types.ServiceUpdateResponse{
|
||||
Warnings: []string{},
|
||||
},
|
||||
want: instance.State{
|
||||
Name: "nginx",
|
||||
CurrentReplicas: 0,
|
||||
DesiredReplicas: 1,
|
||||
Status: instance.Unrecoverable,
|
||||
Message: "ambiguous service names found for \"nginx\" (STACK1_nginx, STACK2_nginx)",
|
||||
},
|
||||
wantService: mocks.ServiceReplicated("nginx", 1),
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "exact match service name",
|
||||
args: args{
|
||||
@@ -90,27 +68,6 @@ func TestDockerSwarmProvider_Start(t *testing.T) {
|
||||
wantService: mocks.ServiceReplicated("nginx", 1),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "service match on suffix",
|
||||
args: args{
|
||||
name: "nginx",
|
||||
},
|
||||
serviceList: []swarm.Service{
|
||||
mocks.ServiceReplicated("STACK1_nginx", 0),
|
||||
mocks.ServiceReplicated("STACK2_nginx-2", 0),
|
||||
},
|
||||
response: types.ServiceUpdateResponse{
|
||||
Warnings: []string{},
|
||||
},
|
||||
want: instance.State{
|
||||
Name: "nginx (STACK1_nginx)",
|
||||
CurrentReplicas: 0,
|
||||
DesiredReplicas: 1,
|
||||
Status: instance.NotReady,
|
||||
},
|
||||
wantService: mocks.ServiceReplicated("STACK1_nginx", 1),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "nginx is not a replicated service",
|
||||
args: args{
|
||||
@@ -189,28 +146,6 @@ func TestDockerSwarmProvider_Stop(t *testing.T) {
|
||||
wantService: mocks.ServiceReplicated("nginx", 0),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "ambiguous service name",
|
||||
args: args{
|
||||
name: "nginx",
|
||||
},
|
||||
serviceList: []swarm.Service{
|
||||
mocks.ServiceReplicated("STACK1_nginx", 1),
|
||||
mocks.ServiceReplicated("STACK2_nginx", 1),
|
||||
},
|
||||
response: types.ServiceUpdateResponse{
|
||||
Warnings: []string{},
|
||||
},
|
||||
want: instance.State{
|
||||
Name: "nginx",
|
||||
CurrentReplicas: 0,
|
||||
DesiredReplicas: 1,
|
||||
Status: instance.Unrecoverable,
|
||||
Message: "ambiguous service names found for \"nginx\" (STACK1_nginx, STACK2_nginx)",
|
||||
},
|
||||
wantService: mocks.ServiceReplicated("nginx", 1),
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "exact match service name",
|
||||
args: args{
|
||||
@@ -233,27 +168,6 @@ func TestDockerSwarmProvider_Stop(t *testing.T) {
|
||||
wantService: mocks.ServiceReplicated("nginx", 0),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "service match on suffix",
|
||||
args: args{
|
||||
name: "nginx",
|
||||
},
|
||||
serviceList: []swarm.Service{
|
||||
mocks.ServiceReplicated("STACK1_nginx", 1),
|
||||
mocks.ServiceReplicated("STACK2_nginx-2", 1),
|
||||
},
|
||||
response: types.ServiceUpdateResponse{
|
||||
Warnings: []string{},
|
||||
},
|
||||
want: instance.State{
|
||||
Name: "nginx (STACK1_nginx)",
|
||||
CurrentReplicas: 0,
|
||||
DesiredReplicas: 1,
|
||||
Status: instance.NotReady,
|
||||
},
|
||||
wantService: mocks.ServiceReplicated("STACK1_nginx", 0),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "nginx is not a replicated service",
|
||||
args: args{
|
||||
@@ -342,22 +256,6 @@ func TestDockerSwarmProvider_GetState(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "nginx service is not ready",
|
||||
args: args{
|
||||
name: "nginx",
|
||||
},
|
||||
serviceList: []swarm.Service{
|
||||
mocks.ServiceNotReadyReplicated("STACK_nginx", 1, 0),
|
||||
},
|
||||
want: instance.State{
|
||||
Name: "nginx (STACK_nginx)",
|
||||
CurrentReplicas: 0,
|
||||
DesiredReplicas: 1,
|
||||
Status: instance.NotReady,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "nginx is not a replicated service",
|
||||
args: args{
|
||||
|
||||
Reference in New Issue
Block a user