From d97baa5c8f41b20841be17f1b632373eb9ec8429 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Thu, 8 Jul 2021 08:26:34 -0400 Subject: [PATCH 1/2] service: remove duplicate name check during validation When a task group with `service` block(s) is validated, we validate that there are no duplicates, but this validation doesn't have access to the task environment because it hasn't been created yet. Services and checks with interpolation can be flagged incorrectly as conflicting. Name conflicts in services are not actually an error in Consul and users have reported wanting to use the same service name for task groups differentiated by tags. --- .changelog/10868.txt | 3 +++ nomad/structs/structs.go | 13 ++----------- 2 files changed, 5 insertions(+), 11 deletions(-) create mode 100644 .changelog/10868.txt diff --git a/.changelog/10868.txt b/.changelog/10868.txt new file mode 100644 index 000000000000..dfc2e95f08a8 --- /dev/null +++ b/.changelog/10868.txt @@ -0,0 +1,3 @@ +```release-note:bug +service: Removed duplicate name checking for `service` and `task` to prevent sprurious validation failures for services using interpolation or using tags for differentiating versions of a service. +``` diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index e7c0f49aa787..00b6c7be59ce 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -6331,13 +6331,11 @@ func (tg *TaskGroup) validateNetworks() error { return mErr.ErrorOrNil() } -// validateServices runs Service.Validate() on group-level services, -// checks that group services do not conflict with task services and that +// validateServices runs Service.Validate() on group-level services, checks // group service checks that refer to tasks only refer to tasks that exist. func (tg *TaskGroup) validateServices() error { var mErr multierror.Error knownTasks := make(map[string]struct{}) - knownServices := make(map[string]struct{}) // Create a map of known tasks and their services so we can compare // vs the group-level services and checks @@ -6347,15 +6345,11 @@ func (tg *TaskGroup) validateServices() error { continue } for _, service := range task.Services { - if _, ok := knownServices[service.Name+service.PortLabel]; ok { - mErr.Errors = append(mErr.Errors, fmt.Errorf("Service %s is duplicate", service.Name)) - } for _, check := range service.Checks { if check.TaskName != "" { mErr.Errors = append(mErr.Errors, fmt.Errorf("Check %s is invalid: only task group service checks can be assigned tasks", check.Name)) } } - knownServices[service.Name+service.PortLabel] = struct{}{} } } for i, service := range tg.Services { @@ -6370,10 +6364,7 @@ func (tg *TaskGroup) validateServices() error { if service.AddressMode == AddressModeDriver { mErr.Errors = append(mErr.Errors, fmt.Errorf("service %q cannot use address_mode=\"driver\", only services defined in a \"task\" block can use this mode", service.Name)) } - if _, ok := knownServices[service.Name+service.PortLabel]; ok { - mErr.Errors = append(mErr.Errors, fmt.Errorf("Service %s is duplicate", service.Name)) - } - knownServices[service.Name+service.PortLabel] = struct{}{} + for _, check := range service.Checks { if check.TaskName != "" { if check.Type != ServiceCheckScript && check.Type != ServiceCheckGRPC { From e2af6f37ca7b44e1c3df82d436952f7726b355ca Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Thu, 8 Jul 2021 09:21:27 -0400 Subject: [PATCH 2/2] Update .changelog/10868.txt Co-authored-by: Seth Hoenig --- .changelog/10868.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/10868.txt b/.changelog/10868.txt index dfc2e95f08a8..eaff667f55ec 100644 --- a/.changelog/10868.txt +++ b/.changelog/10868.txt @@ -1,3 +1,3 @@ ```release-note:bug -service: Removed duplicate name checking for `service` and `task` to prevent sprurious validation failures for services using interpolation or using tags for differentiating versions of a service. +consul: Fixed a bug where services may incorrectly fail conflicting name validation ```