diff --git a/nomad/structs/diff_test.go b/nomad/structs/diff_test.go index 379f1a239..4574bcb64 100644 --- a/nomad/structs/diff_test.go +++ b/nomad/structs/diff_test.go @@ -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", diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index fa29071aa..7fdc06fdb 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -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) } }