nomad icon indicating copy to clipboard operation
nomad copied to clipboard

Job variables page in the Nomad UI uses the job name instead of its ID

Open dpogorzelski opened this issue 1 year ago • 2 comments

Nomad version

1.7.5

Operating system and Environment details

Debian 12

Issue

If you set a name=foobar in the job spec, the job won't be able to look up variables under nomad/jobs/foobar with error: Missing: nomad.var.block(nomad/jobs/[email protected])

Reproduction steps

Create sample variables under the nomad/jobs/foobar path, then run this job:

variable "env" {
  type    = string
  default = "foobar"
}

job "docs" {
  datacenters = ["dc1"]
  name        = var.env

  group "example" {
    network {
      port "http" {
        static = "5678"
      }
    }
    task "server" {
      driver = "docker"

      template {
        data        = <<EOH
{{ with nomadVar "nomad/jobs/${var.env}" }}
{{ range .Tuples }}
{{.K}}={{.V}}
{{ end }}
{{ end }}
    EOH
        destination = ".env"
        env         = true
      }

      config {
        image = "hashicorp/http-echo"
        ports = ["http"]
        args = [
          "-listen",
          ":5678",
          "-text",
          "hello world",
        ]
      }
    }
  }
}

nomad run sample.hcl

Expected Result

I would expect the job to find the variables under nomad/jobs/JOBNAME

Actual Result

Missing: nomad.var.block(nomad/jobs/[email protected])

If I remove the name=${var.env} from the job spec and use job ID in the variables path all works as intended. The reason for using name=${var.env} is that it allows interpolation of user supplied variables.

Another misleading point here is that if you go to the web UI and navigate to the foobar job; under Variables the UI will suggest that there are no variables under nomad/jobs/foobar and will suggest to create one but it actually already exists:

image image

Job file (if appropriate)

Nomad Server logs (if appropriate)

Nomad Client logs (if appropriate)

dpogorzelski avatar Mar 18 '24 13:03 dpogorzelski

setting id = var.env in addition to name = var.env seems to solve this issue but in the absence of id the web UI seems to be confused as originally mentioned. the documentation doesn't seem to mention that the job spec accepts setting id attribute :)

dpogorzelski avatar Mar 18 '24 15:03 dpogorzelski

Hi @dpogorzelski 👋

Thanks for the report. As mentioned in our docs, the variable path that the task has automatic access to is defined by the job ID, not the job name, so that part is working as intended.

The workload identity for each task grants it automatic read and list access to Variables found at Nomad-owned paths with the prefix nomad/jobs/, followed by the job ID, task group name, and task name.

Internally, everything in Nomad uses the Job ID, so I would recommend not having different values for them.

The UI may be using the job name in that page though, so I will rephrase the issue title to focus on this part.

lgfa29 avatar Mar 18 '24 22:03 lgfa29