Skip to content

Commit

Permalink
Merge pull request #6653 from hashicorp/b-6646
Browse files Browse the repository at this point in the history
nomad: fix bug that didn't allow for multiple connect services in same tg
  • Loading branch information
nickethier authored Nov 8, 2019
2 parents e715e14 + fa4ea8a commit 1f6dbea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ IMPROVEMENTS:
BUG FIXES:

* cli: Make scoring column orders consistent `nomad alloc status` [[GH-6609](https://github.com/hashicorp/nomad/issues/6609)]
* nomad: Multiple connect enabled services in the same taskgroup failed to
register [[GH-6646](https://github.com/hashicorp/nomad/issues/6646)]
* scheduler: Changes to devices in resource stanza should cause rescheduling [[GH-6644](https://github.com/hashicorp/nomad/issues/6644)]

## 0.10.1 (November 4, 2019)
Expand Down
1 change: 0 additions & 1 deletion nomad/job_endpoint_hook_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func groupConnectHook(g *structs.TaskGroup) error {
if !found {
g.Networks[0].DynamicPorts = append(g.Networks[0].DynamicPorts, port)
}
return nil
}
}
return nil
Expand Down
12 changes: 12 additions & 0 deletions nomad/job_endpoint_hook_connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,30 @@ func Test_groupConnectHook(t *testing.T) {
SidecarService: &structs.ConsulSidecarService{},
},
},
{
Name: "admin",
PortLabel: "9090",
Connect: &structs.ConsulConnect{
SidecarService: &structs.ConsulSidecarService{},
},
},
},
}

tgOut := tgIn.Copy()
tgOut.Tasks = []*structs.Task{
newConnectTask(tgOut.Services[0]),
newConnectTask(tgOut.Services[1]),
}
tgOut.Networks[0].DynamicPorts = []structs.Port{
{
Label: fmt.Sprintf("%s-%s", structs.ConnectProxyPrefix, "backend"),
To: -1,
},
{
Label: fmt.Sprintf("%s-%s", structs.ConnectProxyPrefix, "admin"),
To: -1,
},
}

require.NoError(t, groupConnectHook(tgIn))
Expand Down
5 changes: 4 additions & 1 deletion nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5013,13 +5013,16 @@ func (tg *TaskGroup) validateNetworks() error {
}
}

if port.To != 0 {
if port.To > 0 {
if other, ok := mappedPorts[port.To]; ok {
err := fmt.Errorf("Port mapped to %d already in use by %s", port.To, other)
mErr.Errors = append(mErr.Errors, err)
} else {
mappedPorts[port.To] = fmt.Sprintf("taskgroup network:%s", port.Label)
}
} else if port.To < -1 {
err := fmt.Errorf("Port %q cannot be mapped to negative value %d", port.Label, port.To)
mErr.Errors = append(mErr.Errors, err)
}
}
}
Expand Down

0 comments on commit 1f6dbea

Please sign in to comment.