Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service: remove duplicate name check during validation #10868

Merged
merged 2 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/10868.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
consul: Fixed a bug where services may incorrectly fail conflicting name validation
```
13 changes: 2 additions & 11 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down