nomad icon indicating copy to clipboard operation
nomad copied to clipboard

some network-related environment variables don't coerce "-" in port label to "_"

Open ORuessel opened this issue 3 months ago • 2 comments

Nomad version

Output from nomad version In use Nomad Version 1.9.5

Operating system and Environment details

Linux Ubuntu Server / Client and Windows Server 2022

Issue

NOMAD_IP_label interpolation is not working if in network block port definition a "-" is in use switch to "_" everything it is working as expected. I havent found in network block documentation nothing about limitation and the network block in general is working as expected.

Reproduction steps

create sample nomad job

network { port "host-server-service" static = "27001" }

use single template file {{ env "NOMAD_IP_host-server-service" }} - will be empty

################################################

network { port "host_server_service" static = "27001" }

use single template file {{ env "NOMAD_IP_host_server_service" }} - receive IP exepected IP

Expected Result

restrict network port defintion or allow "-" in NOMAD_IP_label definition to have a consistent approach.

Actual Result

Job file (if appropriate)

Nomad Server logs (if appropriate)

Nomad Client logs (if appropriate)

ORuessel avatar Nov 06 '25 13:11 ORuessel

Hi @ORuessel! If you take a look at the Network Related Variables docs you'll see the following comment underneath the table:

Nomad replaces characters that are neither alphanumeric nor underscores in port labels or task names with underscores when generating environment variable names such as NOMAD_ADDR__

If I run a job with the following network block:

network {
  mode = "bridge"
  port "www-foo" {
    to = 8001
  }
}

Then if I run nomad alloc exec to read the environment variables, I see the following network-related variables:

NOMAD_ADDR_www_foo=192.168.1.194:25490
NOMAD_ALLOC_ADDR_www-foo=172.26.64.2:8001
NOMAD_ALLOC_IP_www-foo=172.26.64.2
NOMAD_ALLOC_PORT_www-foo=8001
NOMAD_HOST_ADDR_www-foo=192.168.1.194:25490
NOMAD_HOST_IP_www-foo=192.168.1.194
NOMAD_HOST_PORT_www_foo=25490
NOMAD_IP_www_foo=192.168.1.194
NOMAD_PORT_www_foo=8001

But I see a bug here! For the NOMAD_IP_*, NOMAD_ADDR_*, NOMAD_HOST_PORT_*, and NOMAD_PORT_* variables Nomad is coercing the - to _, but for the NOMAD_ALLOC_*, NOMAD_HOST_ADDR_*, and NOMAD_HOST_IP_* variables it's not. That's going to be a bit of pain to fix because of backwards compatibility concerns (we don't want to remove variables that folks were expecting to be there), but should be possible to gradually migrate out from.

I'm going to adjust the title of this issue to reflect the bug and mark it for roadmapping.

tgross avatar Nov 06 '25 16:11 tgross

Hi @tgross, thank you very much for clarification. This is working as expected.

ORuessel avatar Nov 08 '25 11:11 ORuessel