From 57fdb81433e85a0fa3e264678b4fc24bb14a3ce3 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Fri, 18 Jun 2021 11:55:33 -0500 Subject: [PATCH] consul: set task name only for group service checks This PR fixes a bug introduced in a refactoring https://github.com/hashicorp/nomad/pull/10764/files#diff-56b3c82fcbc857f8fb93a903f1610f6e6859b3610a4eddf92bad9ea27fdc85ec where task level service checks would inherent the task name field, when they shouldn't. Fixes #10781 --- command/agent/job_endpoint.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index a5c6131c1..f6c1cefa4 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -874,7 +874,7 @@ func ApiTgToStructsTG(job *structs.Job, taskGroup *api.TaskGroup, tg *structs.Ta tg.Constraints = ApiConstraintsToStructs(taskGroup.Constraints) tg.Affinities = ApiAffinitiesToStructs(taskGroup.Affinities) tg.Networks = ApiNetworkResourceToStructs(taskGroup.Networks) - tg.Services = ApiServicesToStructs(taskGroup.Services) + tg.Services = ApiServicesToStructs(taskGroup.Services, true) tg.Consul = apiConsulToStructs(taskGroup.Consul) tg.RestartPolicy = &structs.RestartPolicy{ @@ -1044,7 +1044,7 @@ func ApiTaskToStructsTask(job *structs.Job, group *structs.TaskGroup, } } - structsTask.Services = ApiServicesToStructs(apiTask.Services) + structsTask.Services = ApiServicesToStructs(apiTask.Services, false) structsTask.Resources = ApiResourcesToStructs(apiTask.Resources) @@ -1212,7 +1212,7 @@ func ApiPortToStructs(in api.Port) structs.Port { } } -func ApiServicesToStructs(in []*api.Service) []*structs.Service { +func ApiServicesToStructs(in []*api.Service, group bool) []*structs.Service { if len(in) == 0 { return nil } @@ -1258,11 +1258,16 @@ func ApiServicesToStructs(in []*api.Service) []*structs.Service { Body: check.Body, GRPCService: check.GRPCService, GRPCUseTLS: check.GRPCUseTLS, - TaskName: check.TaskName, SuccessBeforePassing: check.SuccessBeforePassing, FailuresBeforeCritical: check.FailuresBeforeCritical, OnUpdate: onUpdate, } + + if group { + // only copy over task name for group level checks + out[i].Checks[j].TaskName = check.TaskName + } + if check.CheckRestart != nil { out[i].Checks[j].CheckRestart = &structs.CheckRestart{ Limit: check.CheckRestart.Limit,