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

String interpolation with function call not working for meta properties #9870

Closed
TylerPachal opened this issue Jan 21, 2021 · 3 comments
Closed

Comments

@TylerPachal
Copy link

TylerPachal commented Jan 21, 2021

Nomad version

0.12.9

Issue

String interpolation with function call not working for meta properties.

I have two places in my .hcl file where I am using the substr function to grab the short version of my commit hash, which is used to tag my docker image. In the meta stanza, the string is not interpolated, and as show as-is in the UI (see the screenshot). In the task/config stanza, it works fine.

Job file

job "my-job" {
  
  meta { 
    image_tag = "${substr("[[ .DEPLOY_SUB___VERSION ]]", 0, 7)}"           # This doesn't work, and is show in the UI as-is
  }

  group "my-group" {
    task "my-task" {
      config {
        image = "uri.for.my.image:${substr("[[ .DEPLOY_SUB___VERSION ]]", 0, 7)}"       # This works
      }
    }
  }

  # ...
} 

This is what is presented in the UI:
nomad

I also tried doing the following, but it was invalid hcl:

image_tag = substr("[[ .DEPLOY_SUB___VERSION ]]", 0, 7)

Edit: We are using Levant to do the replacement of DEPLOY_SUB___VERSION.

@tgross
Copy link
Member

tgross commented Jan 21, 2021

@TylerPachal the HCL2 functions like substr are only available in Nomad 1.0 and above, so Nomad is trying that as a plain old string. Even for Nomad 1.0 the syntax needs to be a little different because of a bug in quote-escaping (ref #9838), but this job works:

job "example" {
  datacenters = ["dc1"]

  meta {
    tag = substr("SOMEVALUE", 0, 7)
  }

  group "cache" {
    network {
      port "db" {
        to = 6379
      }
    }

    task "redis" {
      driver = "docker"

      config {
        image = "redis:3.2"

        ports = ["db"]
      }

      resources {
        cpu    = 500
        memory = 256
      }
    }
  }
}
$ nomad job run ./example.nomad
==> Monitoring evaluation "2e7c51eb"
    Evaluation triggered by job "example"
    Allocation "5108edaf" created: node "5005e621", group "cache"
==> Monitoring evaluation "2e7c51eb"
    Evaluation within deployment: "88bcb501"
    Evaluation status changed: "pending" -> "complete"
==> Evaluation "2e7c51eb" finished with status "complete"

$ nomad alloc exec 5108 env | grep META
NOMAD_META_TAG=SOMEVAL
NOMAD_META_tag=SOMEVAL

@tgross
Copy link
Member

tgross commented Feb 1, 2021

Even for Nomad 1.0 the syntax needs to be a little different because of a bug in quote-escaping (ref #9838), but this job works:

Looks like #9838 was the wrong bug, as this works in master now. But looks like this is safe to close.

@tgross tgross closed this as completed Feb 1, 2021
@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 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants