Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable interpolation does not work in the meta stanza #6506

Closed
brooms opened this issue Oct 17, 2019 · 4 comments · Fixed by #10876
Closed

Variable interpolation does not work in the meta stanza #6506

brooms opened this issue Oct 17, 2019 · 4 comments · Fixed by #10876

Comments

@brooms
Copy link

brooms commented Oct 17, 2019

Nomad version

Nomad v0.10.0-rc1 (c49bf41)

Operating system and Environment details

Distribution: Ubuntu Xenial 16.04.6
Kernel Version: Linux 4.4.0-165-generic x86_64
Docker Version: 19.03.3, build a872fc2

Issue

It appears that variable interpolation (using either node attributes or runtime environment variables) does not work in the meta stanza. I'm not sure whether this is an intended feature or not, but the documentation does suggest variable interpolation should work in the meta stanza.

Moving the meta stanza under the task stanza still results in the same output.

Reproduction steps

  1. Run the sample job
  2. Perform a docker inspect on the running container to see env variable output

Job file

job "meta-stanza-test-job" {

  type = "service"
  datacenters = ["dc1"]

  meta {
    TEST_NUMBER = 1
    TEST_STRING = "string"
    # Interpolation here fails for both node attributes (e.g. ${node.datacenter}) and runtime environment variables
    TEST_INTERPOLATION = "${NOMAD_DC}-${NOMAD_JOB_NAME}"
  }

  group "meta-stanza-test-group" {

    task "meta-stanza-test-task" {

      env {
        TEST_NUMBER = "${NOMAD_META_TEST_NUMBER}"
        TEST_STRING = "${NOMAD_META_TEST_STRING}"
        TEST_INTERPOLATION = "${NOMAD_META_TEST_INTERPOLATION}"
        ENV_TEST_INTERPOLATION = "${NOMAD_DC}-${NOMAD_JOB_NAME}"
      }

      driver = "docker"

      config {
        image = "registry:latest"

        port_map {
          http = 5000
        }
      }

      resources {
        cpu    = 500
        memory = 512 

        network {
          mbits = 25

          port "http" {
          }
        }
      }
    }
  }
}

Job output

Running docker inspect <container_id> gives:

"Env": [
"ENV_TEST_INTERPOLATION=dc1-meta-stanza-test-job",
"NOMAD_ADDR_http=172.16.1.10:31850",
"NOMAD_ALLOC_DIR=/alloc",
"NOMAD_ALLOC_ID=9f4e46c2-a707-e96b-dd44-f7440111d984",
"NOMAD_ALLOC_INDEX=0",
"NOMAD_ALLOC_NAME=meta-stanza-test-job.meta-stanza-test-group[0]",
"NOMAD_CPU_LIMIT=500",
"NOMAD_DC=dc1",
"NOMAD_GROUP_NAME=meta-stanza-test-group",
"NOMAD_HOST_PORT_http=31850",
"NOMAD_IP_http=172.16.1.10",
"NOMAD_JOB_NAME=meta-stanza-test-job",
"NOMAD_MEMORY_LIMIT=512",
"NOMAD_META_TEST_INTERPOLATION=${NOMAD_DC}-${NOMAD_JOB_NAME}",
"NOMAD_META_TEST_NUMBER=1",
"NOMAD_META_TEST_STRING=string",
"NOMAD_NAMESPACE=default",
"NOMAD_PORT_http=5000",
"NOMAD_REGION=global",
"NOMAD_SECRETS_DIR=/secrets",
"NOMAD_TASK_DIR=/local",
"NOMAD_TASK_NAME=meta-stanza-test-task",
"TEST_INTERPOLATION=${NOMAD_DC}-${NOMAD_JOB_NAME}",
"TEST_NUMBER=1",
"TEST_STRING=string",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],

@langmartin
Copy link
Contributor

This is correct, the meta stanza does not interpolate variables.

@djenriquez
Copy link

@langmartin verified, just saw this in 0.10.0. I'm confused by your comment, are you saying this is intended behaviors, or are you confirming the issue?
The problem we're seeing is trying to interpret node meta into consul service tags defined in the service stanza. This worked fine in Consul 0.9.6 and earlier. Given this worked before, this should be marked as regression.

@tgross tgross added this to Needs Roadmapping in Nomad - Community Issues Triage Feb 12, 2021
@tgross tgross removed this from Needs Roadmapping in Nomad - Community Issues Triage Mar 3, 2021
@andycui66
Copy link

I am experiencing the same issue. Hope it can be fixed.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants