|
|
|
|
@ -343,6 +343,8 @@ func marathonTestAppListWithPortDefinitions(labels map[string]string, runningTas |
|
|
|
|
task = Task{ |
|
|
|
|
ID: "test-task-1", |
|
|
|
|
Host: "mesos-slave1", |
|
|
|
|
// Auto-generated ports when requirePorts is false
|
|
|
|
|
Ports: []uint32{1234, 5678}, |
|
|
|
|
} |
|
|
|
|
docker = DockerContainer{ |
|
|
|
|
Image: "repo/image:tag", |
|
|
|
|
@ -358,6 +360,7 @@ func marathonTestAppListWithPortDefinitions(labels map[string]string, runningTas |
|
|
|
|
{Labels: make(map[string]string), Port: 31000}, |
|
|
|
|
{Labels: labels, Port: 32000}, |
|
|
|
|
}, |
|
|
|
|
RequirePorts: false, // default
|
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
return &AppList{ |
|
|
|
|
@ -386,7 +389,7 @@ func TestMarathonSDSendGroupWithPortDefinitions(t *testing.T) { |
|
|
|
|
t.Fatalf("Wrong number of targets: %v", tg.Targets) |
|
|
|
|
} |
|
|
|
|
tgt := tg.Targets[0] |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:31000" { |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:1234" { |
|
|
|
|
t.Fatalf("Wrong target address: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "" { |
|
|
|
|
@ -396,7 +399,7 @@ func TestMarathonSDSendGroupWithPortDefinitions(t *testing.T) { |
|
|
|
|
t.Fatalf("Wrong first portDefinitions label from the first port: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
tgt = tg.Targets[1] |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:32000" { |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:5678" { |
|
|
|
|
t.Fatalf("Wrong target address: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "" { |
|
|
|
|
@ -410,7 +413,7 @@ func TestMarathonSDSendGroupWithPortDefinitions(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func marathonTestAppListWithPorts(labels map[string]string, runningTasks int) *AppList { |
|
|
|
|
func marathonTestAppListWithPortDefinitionsRequirePorts(labels map[string]string, runningTasks int) *AppList { |
|
|
|
|
var ( |
|
|
|
|
task = Task{ |
|
|
|
|
ID: "test-task-1", |
|
|
|
|
@ -427,6 +430,11 @@ func marathonTestAppListWithPorts(labels map[string]string, runningTasks int) *A |
|
|
|
|
RunningTasks: runningTasks, |
|
|
|
|
Labels: labels, |
|
|
|
|
Container: container, |
|
|
|
|
PortDefinitions: []PortDefinition{ |
|
|
|
|
{Labels: make(map[string]string), Port: 31000}, |
|
|
|
|
{Labels: labels, Port: 32000}, |
|
|
|
|
}, |
|
|
|
|
RequirePorts: true, |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
return &AppList{ |
|
|
|
|
@ -434,11 +442,11 @@ func marathonTestAppListWithPorts(labels map[string]string, runningTasks int) *A |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMarathonSDSendGroupWithPorts(t *testing.T) { |
|
|
|
|
func TestMarathonSDSendGroupWithPortDefinitionsRequirePorts(t *testing.T) { |
|
|
|
|
var ( |
|
|
|
|
ch = make(chan []*targetgroup.Group, 1) |
|
|
|
|
client = func(client *http.Client, url string) (*AppList, error) { |
|
|
|
|
return marathonTestAppListWithPorts(marathonValidLabel, 1), nil |
|
|
|
|
return marathonTestAppListWithPortDefinitionsRequirePorts(marathonValidLabel, 1), nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
if err := testUpdateServices(client, ch); err != nil { |
|
|
|
|
@ -471,7 +479,7 @@ func TestMarathonSDSendGroupWithPorts(t *testing.T) { |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "" { |
|
|
|
|
t.Fatalf("Wrong portMappings label from the second port: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portDefinitionLabelPrefix+"prometheus")] != "" { |
|
|
|
|
if tgt[model.LabelName(portDefinitionLabelPrefix+"prometheus")] != "yes" { |
|
|
|
|
t.Fatalf("Wrong portDefinitions label from the second port: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
default: |
|
|
|
|
@ -479,27 +487,18 @@ func TestMarathonSDSendGroupWithPorts(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func marathonTestAppListWithContainerPortMappings(labels map[string]string, runningTasks int) *AppList { |
|
|
|
|
func marathonTestAppListWithPorts(labels map[string]string, runningTasks int) *AppList { |
|
|
|
|
var ( |
|
|
|
|
task = Task{ |
|
|
|
|
ID: "test-task-1", |
|
|
|
|
Host: "mesos-slave1", |
|
|
|
|
Ports: []uint32{ |
|
|
|
|
12345, // 'Automatically-generated' port
|
|
|
|
|
32000, |
|
|
|
|
}, |
|
|
|
|
ID: "test-task-1", |
|
|
|
|
Host: "mesos-slave1", |
|
|
|
|
Ports: []uint32{31000, 32000}, |
|
|
|
|
} |
|
|
|
|
docker = DockerContainer{ |
|
|
|
|
Image: "repo/image:tag", |
|
|
|
|
} |
|
|
|
|
container = Container{ |
|
|
|
|
Docker: docker, |
|
|
|
|
PortMappings: []PortMapping{ |
|
|
|
|
{Labels: labels, HostPort: 0}, |
|
|
|
|
{Labels: make(map[string]string), HostPort: 32000}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
app = App{ |
|
|
|
|
container = Container{Docker: docker} |
|
|
|
|
app = App{ |
|
|
|
|
ID: "test-service", |
|
|
|
|
Tasks: []Task{task}, |
|
|
|
|
RunningTasks: runningTasks, |
|
|
|
|
@ -512,11 +511,11 @@ func marathonTestAppListWithContainerPortMappings(labels map[string]string, runn |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMarathonSDSendGroupWithContainerPortMappings(t *testing.T) { |
|
|
|
|
func TestMarathonSDSendGroupWithPorts(t *testing.T) { |
|
|
|
|
var ( |
|
|
|
|
ch = make(chan []*targetgroup.Group, 1) |
|
|
|
|
client = func(client *http.Client, url string) (*AppList, error) { |
|
|
|
|
return marathonTestAppListWithContainerPortMappings(marathonValidLabel, 1), nil |
|
|
|
|
return marathonTestAppListWithPorts(marathonValidLabel, 1), nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
if err := testUpdateServices(client, ch); err != nil { |
|
|
|
|
@ -533,10 +532,10 @@ func TestMarathonSDSendGroupWithContainerPortMappings(t *testing.T) { |
|
|
|
|
t.Fatalf("Wrong number of targets: %v", tg.Targets) |
|
|
|
|
} |
|
|
|
|
tgt := tg.Targets[0] |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:12345" { |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:31000" { |
|
|
|
|
t.Fatalf("Wrong target address: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "yes" { |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "" { |
|
|
|
|
t.Fatalf("Wrong first portMappings label from the first port: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portDefinitionLabelPrefix+"prometheus")] != "" { |
|
|
|
|
@ -557,25 +556,25 @@ func TestMarathonSDSendGroupWithContainerPortMappings(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func marathonTestAppListWithDockerContainerPortMappings(labels map[string]string, runningTasks int) *AppList { |
|
|
|
|
func marathonTestAppListWithContainerPortMappings(labels map[string]string, runningTasks int) *AppList { |
|
|
|
|
var ( |
|
|
|
|
task = Task{ |
|
|
|
|
ID: "test-task-1", |
|
|
|
|
Host: "mesos-slave1", |
|
|
|
|
Ports: []uint32{ |
|
|
|
|
31000, |
|
|
|
|
12345, // 'Automatically-generated' port
|
|
|
|
|
32000, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
docker = DockerContainer{ |
|
|
|
|
Image: "repo/image:tag", |
|
|
|
|
PortMappings: []PortMapping{ |
|
|
|
|
{Labels: labels, HostPort: 31000}, |
|
|
|
|
{Labels: make(map[string]string), HostPort: 0}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
container = Container{ |
|
|
|
|
Docker: docker, |
|
|
|
|
PortMappings: []PortMapping{ |
|
|
|
|
{Labels: labels, HostPort: 0}, |
|
|
|
|
{Labels: make(map[string]string), HostPort: 32000}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
app = App{ |
|
|
|
|
ID: "test-service", |
|
|
|
|
@ -590,11 +589,11 @@ func marathonTestAppListWithDockerContainerPortMappings(labels map[string]string |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMarathonSDSendGroupWithDockerContainerPortMappings(t *testing.T) { |
|
|
|
|
func TestMarathonSDSendGroupWithContainerPortMappings(t *testing.T) { |
|
|
|
|
var ( |
|
|
|
|
ch = make(chan []*targetgroup.Group, 1) |
|
|
|
|
client = func(client *http.Client, url string) (*AppList, error) { |
|
|
|
|
return marathonTestAppListWithDockerContainerPortMappings(marathonValidLabel, 1), nil |
|
|
|
|
return marathonTestAppListWithContainerPortMappings(marathonValidLabel, 1), nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
if err := testUpdateServices(client, ch); err != nil { |
|
|
|
|
@ -611,7 +610,7 @@ func TestMarathonSDSendGroupWithDockerContainerPortMappings(t *testing.T) { |
|
|
|
|
t.Fatalf("Wrong number of targets: %v", tg.Targets) |
|
|
|
|
} |
|
|
|
|
tgt := tg.Targets[0] |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:31000" { |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:12345" { |
|
|
|
|
t.Fatalf("Wrong target address: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "yes" { |
|
|
|
|
@ -621,7 +620,7 @@ func TestMarathonSDSendGroupWithDockerContainerPortMappings(t *testing.T) { |
|
|
|
|
t.Fatalf("Wrong first portDefinitions label from the first port: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
tgt = tg.Targets[1] |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:12345" { |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:32000" { |
|
|
|
|
t.Fatalf("Wrong target address: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "" { |
|
|
|
|
@ -635,28 +634,25 @@ func TestMarathonSDSendGroupWithDockerContainerPortMappings(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func marathonTestAppListWithContainerNetworkAndPortMappings(labels map[string]string, runningTasks int) *AppList { |
|
|
|
|
func marathonTestAppListWithDockerContainerPortMappings(labels map[string]string, runningTasks int) *AppList { |
|
|
|
|
var ( |
|
|
|
|
task = Task{ |
|
|
|
|
ID: "test-task-1", |
|
|
|
|
Host: "mesos-slave1", |
|
|
|
|
IPAddresses: []IPAddress{ |
|
|
|
|
{Address: "1.2.3.4"}, |
|
|
|
|
Ports: []uint32{ |
|
|
|
|
31000, |
|
|
|
|
12345, // 'Automatically-generated' port
|
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
docker = DockerContainer{ |
|
|
|
|
Image: "repo/image:tag", |
|
|
|
|
} |
|
|
|
|
portMappings = []PortMapping{ |
|
|
|
|
{Labels: labels, ContainerPort: 8080, HostPort: 31000}, |
|
|
|
|
{Labels: make(map[string]string), ContainerPort: 1234, HostPort: 32000}, |
|
|
|
|
PortMappings: []PortMapping{ |
|
|
|
|
{Labels: labels, HostPort: 31000}, |
|
|
|
|
{Labels: make(map[string]string), HostPort: 0}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
container = Container{ |
|
|
|
|
Docker: docker, |
|
|
|
|
PortMappings: portMappings, |
|
|
|
|
} |
|
|
|
|
networks = []Network{ |
|
|
|
|
{Mode: "container", Name: "test-network"}, |
|
|
|
|
Docker: docker, |
|
|
|
|
} |
|
|
|
|
app = App{ |
|
|
|
|
ID: "test-service", |
|
|
|
|
@ -664,7 +660,6 @@ func marathonTestAppListWithContainerNetworkAndPortMappings(labels map[string]st |
|
|
|
|
RunningTasks: runningTasks, |
|
|
|
|
Labels: labels, |
|
|
|
|
Container: container, |
|
|
|
|
Networks: networks, |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
return &AppList{ |
|
|
|
|
@ -672,11 +667,11 @@ func marathonTestAppListWithContainerNetworkAndPortMappings(labels map[string]st |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMarathonSDSendGroupWithContainerNetworkAndPortMapping(t *testing.T) { |
|
|
|
|
func TestMarathonSDSendGroupWithDockerContainerPortMappings(t *testing.T) { |
|
|
|
|
var ( |
|
|
|
|
ch = make(chan []*targetgroup.Group, 1) |
|
|
|
|
client = func(client *http.Client, url string) (*AppList, error) { |
|
|
|
|
return marathonTestAppListWithContainerNetworkAndPortMappings(marathonValidLabel, 1), nil |
|
|
|
|
return marathonTestAppListWithDockerContainerPortMappings(marathonValidLabel, 1), nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
if err := testUpdateServices(client, ch); err != nil { |
|
|
|
|
@ -693,7 +688,7 @@ func TestMarathonSDSendGroupWithContainerNetworkAndPortMapping(t *testing.T) { |
|
|
|
|
t.Fatalf("Wrong number of targets: %v", tg.Targets) |
|
|
|
|
} |
|
|
|
|
tgt := tg.Targets[0] |
|
|
|
|
if tgt[model.AddressLabel] != "1.2.3.4:8080" { |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:31000" { |
|
|
|
|
t.Fatalf("Wrong target address: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "yes" { |
|
|
|
|
@ -703,7 +698,7 @@ func TestMarathonSDSendGroupWithContainerNetworkAndPortMapping(t *testing.T) { |
|
|
|
|
t.Fatalf("Wrong first portDefinitions label from the first port: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
tgt = tg.Targets[1] |
|
|
|
|
if tgt[model.AddressLabel] != "1.2.3.4:1234" { |
|
|
|
|
if tgt[model.AddressLabel] != "mesos-slave1:12345" { |
|
|
|
|
t.Fatalf("Wrong target address: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "" { |
|
|
|
|
@ -717,7 +712,7 @@ func TestMarathonSDSendGroupWithContainerNetworkAndPortMapping(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func marathonTestAppListWithContainerNetworkAndPortDefinition(labels map[string]string, runningTasks int) *AppList { |
|
|
|
|
func marathonTestAppListWithContainerNetworkAndPortMappings(labels map[string]string, runningTasks int) *AppList { |
|
|
|
|
var ( |
|
|
|
|
task = Task{ |
|
|
|
|
ID: "test-task-1", |
|
|
|
|
@ -729,24 +724,24 @@ func marathonTestAppListWithContainerNetworkAndPortDefinition(labels map[string] |
|
|
|
|
docker = DockerContainer{ |
|
|
|
|
Image: "repo/image:tag", |
|
|
|
|
} |
|
|
|
|
portDefinitions = []PortDefinition{ |
|
|
|
|
{Labels: labels, Port: 8080}, |
|
|
|
|
{Labels: make(map[string]string), Port: 1234}, |
|
|
|
|
portMappings = []PortMapping{ |
|
|
|
|
{Labels: labels, ContainerPort: 8080, HostPort: 31000}, |
|
|
|
|
{Labels: make(map[string]string), ContainerPort: 1234, HostPort: 32000}, |
|
|
|
|
} |
|
|
|
|
container = Container{ |
|
|
|
|
Docker: docker, |
|
|
|
|
Docker: docker, |
|
|
|
|
PortMappings: portMappings, |
|
|
|
|
} |
|
|
|
|
networks = []Network{ |
|
|
|
|
{Mode: "container", Name: "test-network"}, |
|
|
|
|
} |
|
|
|
|
app = App{ |
|
|
|
|
ID: "test-service", |
|
|
|
|
Tasks: []Task{task}, |
|
|
|
|
RunningTasks: runningTasks, |
|
|
|
|
Labels: labels, |
|
|
|
|
Container: container, |
|
|
|
|
Networks: networks, |
|
|
|
|
PortDefinitions: portDefinitions, |
|
|
|
|
ID: "test-service", |
|
|
|
|
Tasks: []Task{task}, |
|
|
|
|
RunningTasks: runningTasks, |
|
|
|
|
Labels: labels, |
|
|
|
|
Container: container, |
|
|
|
|
Networks: networks, |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
return &AppList{ |
|
|
|
|
@ -754,11 +749,11 @@ func marathonTestAppListWithContainerNetworkAndPortDefinition(labels map[string] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMarathonSDSendGroupWithContainerNetworkAndPortDefinition(t *testing.T) { |
|
|
|
|
func TestMarathonSDSendGroupWithContainerNetworkAndPortMapping(t *testing.T) { |
|
|
|
|
var ( |
|
|
|
|
ch = make(chan []*targetgroup.Group, 1) |
|
|
|
|
client = func(client *http.Client, url string) (*AppList, error) { |
|
|
|
|
return marathonTestAppListWithContainerNetworkAndPortDefinition(marathonValidLabel, 1), nil |
|
|
|
|
return marathonTestAppListWithContainerNetworkAndPortMappings(marathonValidLabel, 1), nil |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
if err := testUpdateServices(client, ch); err != nil { |
|
|
|
|
@ -778,10 +773,10 @@ func TestMarathonSDSendGroupWithContainerNetworkAndPortDefinition(t *testing.T) |
|
|
|
|
if tgt[model.AddressLabel] != "1.2.3.4:8080" { |
|
|
|
|
t.Fatalf("Wrong target address: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "" { |
|
|
|
|
if tgt[model.LabelName(portMappingLabelPrefix+"prometheus")] != "yes" { |
|
|
|
|
t.Fatalf("Wrong first portMappings label from the first port: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
if tgt[model.LabelName(portDefinitionLabelPrefix+"prometheus")] != "yes" { |
|
|
|
|
if tgt[model.LabelName(portDefinitionLabelPrefix+"prometheus")] != "" { |
|
|
|
|
t.Fatalf("Wrong first portDefinitions label from the first port: %s", tgt[model.AddressLabel]) |
|
|
|
|
} |
|
|
|
|
tgt = tg.Targets[1] |
|
|
|
|
|