Skip to content

client: Fix task env calculation of alloc addr using static ports.#27305

Merged
jrasell merged 2 commits intomainfrom
b-client-alloc-env-var-port-identification
Dec 30, 2025
Merged

client: Fix task env calculation of alloc addr using static ports.#27305
jrasell merged 2 commits intomainfrom
b-client-alloc-env-var-port-identification

Conversation

@jrasell
Copy link
Copy Markdown
Member

@jrasell jrasell commented Dec 30, 2025

The "NOMAD_ALLOC_ADDR_" task env var was not correctly generating the value when the allocation used a static port allocation. The resulting env var would always have an address with its port as 0.

The change correctly handles dynamic and static port definitions, so the "NOMAD_ALLOC_ADDR_" is properly formed.

Testing & Reproduction steps

The following job spec can be used on Linux to observe the behaviour:

job "example" {

  group "cache" {
    network {
      mode = "bridge"
      port "db" {
        static = 6379
      }
    }

    task "redis" {
      driver = "docker"

      config {
        image          = "redis:7"
        ports          = ["db"]
        auth_soft_fail = true
      }

      identity {
        env  = true
        file = true
      }

      resources {
        cpu    = 500
        memory = 256
      }
    }
  }
}

You can then use the command nomad alloc exec <alloc_id> env to query the task environment and identify the incorrect task env var.

Contributor Checklist

  • Changelog Entry If this PR changes user-facing behavior, please generate and add a
    changelog entry using the make cl command.
  • Testing Please add tests to cover any new functionality or to demonstrate bug fixes and
    ensure regressions will be caught.
  • Documentation If the change impacts user-facing functionality such as the CLI, API, UI,
    and job configuration, please update the Nomad product documentation, which is stored in the
    web-unified-docs repo. Refer to the web-unified-docs contributor guide for docs guidelines.
    Please also consider whether the change requires notes within the upgrade
    guide
    . If you would like help with the docs, tag the nomad-docs team in this PR.

Reviewer Checklist

  • Backport Labels Please add the correct backport labels as described by the internal
    backporting document.
  • Commit Type Ensure the correct merge method is selected which should be "squash and merge"
    in the majority of situations. The main exceptions are long-lived feature branches or merges where
    history should be preserved.
  • Enterprise PRs If this is an enterprise only PR, please add any required changelog entry
    within the public repository.

The "NOMAD_ALLOC_ADDR_" task env var was not correctly generating
the value when the allocation used a static port allocation. The
resulting env var would always have an address with its port as 0.

The change correctly handles dynamic and static port definitions,
so the "NOMAD_ALLOC_ADDR_" is properly formed.
@jrasell jrasell self-assigned this Dec 30, 2025
@jrasell jrasell added backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/ent/1.10.x+ent backport to 1.10.x+ent release line backport/1.11.x backport to 1.11.x release line labels Dec 30, 2025
Copy link
Copy Markdown
Contributor

@pkazmierczak pkazmierczak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jrasell jrasell merged commit 8d07c29 into main Dec 30, 2025
38 checks passed
@jrasell jrasell deleted the b-client-alloc-env-var-port-identification branch December 30, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/ent/1.10.x+ent backport to 1.10.x+ent release line backport/1.11.x backport to 1.11.x release line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants