Skip to content

Commit

Permalink
Improve port label validation and diff testing
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Dec 8, 2017
1 parent b731f7f commit c68ed09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions nomad/structs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3507,6 +3507,12 @@ func TestTaskDiff(t *testing.T) {
Type: DiffTypeEdited,
Name: "Check",
Fields: []*FieldDiff{
{
Type: DiffTypeNone,
Name: "AddressMode",
Old: "",
New: "",
},
{
Type: DiffTypeNone,
Name: "Command",
Expand Down
10 changes: 7 additions & 3 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3473,10 +3473,14 @@ func validateServices(t *Task) error {
knownServices[service.Name+service.PortLabel] = struct{}{}

if service.PortLabel != "" {
if _, err := strconv.Atoi(service.PortLabel); service.AddressMode == "driver" && err == nil {
// Numeric ports are valid when AddressMode=driver
if service.AddressMode == "driver" {
// Numeric port labels are valid for address_mode=driver
_, err := strconv.Atoi(service.PortLabel)
if err != nil {
// Not a numeric port label, add it to list to check
servicePorts[service.PortLabel] = append(servicePorts[service.PortLabel], service.Name)
}
} else {

servicePorts[service.PortLabel] = append(servicePorts[service.PortLabel], service.Name)
}
}
Expand Down

0 comments on commit c68ed09

Please sign in to comment.