mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
Check for nils before accessing data
This commit is contained in:
@@ -111,22 +111,26 @@ func PopulateEnvironment(ctx *ExecContext, task *structs.Task) []string {
|
||||
env := []string{}
|
||||
|
||||
env = append(env, fmt.Sprintf("NOMAD_ALLOC_DIR=%s", ctx.AllocDir))
|
||||
env = append(env, fmt.Sprintf("NOMAD_MEMORY_LIMIT=%d", task.Resources.MemoryMB))
|
||||
env = append(env, fmt.Sprintf("NOMAD_CPU_LIMIT=%d", task.Resources.CPU))
|
||||
|
||||
if task.Resources != nil {
|
||||
env = append(env, fmt.Sprintf("NOMAD_MEMORY_LIMIT=%d", task.Resources.MemoryMB))
|
||||
env = append(env, fmt.Sprintf("NOMAD_CPU_LIMIT=%d", task.Resources.CPU))
|
||||
|
||||
// Named Ports
|
||||
if len(task.Resources.Networks) > 0 {
|
||||
network := task.Resources.Networks[0]
|
||||
|
||||
env = append(env, fmt.Sprintf("NOMAD_HOST_IP=%d", network.IP))
|
||||
for idx, port := range network.ListDynamicPorts() {
|
||||
env = append(env, fmt.Sprintf("NOMAD_PORT_%s=%d", strings.ToUpper(network.DynamicPorts[idx]), port))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Meta values
|
||||
for key, value := range task.Meta {
|
||||
env = append(env, fmt.Sprintf("NOMAD_META_%s=%s", strings.ToUpper(key), value))
|
||||
}
|
||||
|
||||
// Named Ports
|
||||
// TODO make this work with multiple network interfaces.
|
||||
network := task.Resources.Networks[0]
|
||||
|
||||
env = append(env, fmt.Sprintf("NOMAD_HOST_IP=%d", network.IP))
|
||||
for idx, port := range network.ListDynamicPorts() {
|
||||
env = append(env, fmt.Sprintf("NOMAD_PORT_%s=%d", strings.ToUpper(network.DynamicPorts[idx]), port))
|
||||
}
|
||||
|
||||
return env
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user