Skip to content

Commit

Permalink
client: skip variable interpolation if environment is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed Mar 10, 2023
1 parent d209dcd commit 925d347
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions client/allochealth/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 925d347

Please sign in to comment.