From 925d34798621cb9620c3d598922a44409f7dc7f9 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Fri, 10 Mar 2023 13:18:05 -0500 Subject: [PATCH] client: skip variable interpolation if environment is not available --- client/allochealth/tracker.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/allochealth/tracker.go b/client/allochealth/tracker.go index 7f9d5ed0b956..488f2ea9dd49 100644 --- a/client/allochealth/tracker.go +++ b/client/allochealth/tracker.go @@ -519,18 +519,18 @@ OUTER: // interpolate services to replace runtime variables consulServices := t.tg.ConsulServices() - interpolatedServices := make([]*structs.Service, len(consulServices)) - for i, service := range consulServices { + interpolatedServices := make([]*structs.Service, 0, len(consulServices)) + for _, service := range consulServices { env := t.taskEnvs[service.TaskName] if env == nil { // This is not expected to happen, but guard against a nil - // task environment by using the group environment since it has - // most of the same values. - t.logger.Warn("task environment not found, using group level environment for variable interpolation", + // task environment that could case a panic. + t.logger.Error("failed to interpolate service runtime variables: task environment not found", "alloc_id", t.alloc.ID, "task", service.TaskName) - env = t.taskEnvs[""] + continue } - interpolatedServices[i] = taskenv.InterpolateService(env, service) + interpolatedService := taskenv.InterpolateService(env, service) + interpolatedServices = append(interpolatedServices, interpolatedService) } // scan for missing or unhealthy consul checks