-
Notifications
You must be signed in to change notification settings - Fork 2k
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
HCL2 split
function doesn't evaluate its parameters
#12020
Comments
Hey @axsuul Thanks for finding this! We'll have to look into this and see if it's an issue with HCL or the nomad parser 🤔 . We'll keep this issue updated with what we find |
Hey just wanted to follow up on this 👍 |
Bumping this again |
I believe this is still an issue, bumping |
Hi @axsuul there's no need to bump issues. We'll update when there's an update to be had. Thanks. |
I'm also experiencing an issue where the split function isn't working as expected, so I'm adding the details of this scenario here... Nomad version1.6.0-beta.1 Operating system and Environment detailsManjaro Ultima Thule 23.0.0 IssueUsing a template to read key -> value pairs from a nomad variable into environment variables and then splitting one of the string ENV VARs on a comma doesn't work. Reproduction stepsDefine a nomad variable that contains multiple key value pairs, with one of them being: {
"extra_hosts": "extra-host:172.17.0.1,demo.extra-host:172.17.0.1"
} job "job-name-same-as-var-name" {
group "group1" {
task "task1" {
template {
change_mode = "restart"
error_on_missing_key = true
destination = "${NOMAD_SECRETS_DIR}/.env"
env = true
data = <<EOT
{{- with nomadVar (env "NOMAD_JOB_NAME") -}}
EXTRA_HOSTS = {{ .extra_hosts }}
{{- end -}}
EOT
}
driver = "docker"
config {
image = "path.to/image:tag"
extra_hosts = flatten(["hard-coded-host:123.45.67.8", split(",", EXTRA_HOSTS)])
}
}
}
} Expected result
Actual result
|
@tgross I'm still seeing this issue in Nomad 1.6.1 |
Hi @axsuul there's no need to bump issues. We'll update when there's an update to be had. Thanks. |
Doing a bit of issue cleanup and dug into the syntax used here. I've tried this jobspec with a couple of variations: jobspeclocals {
variants = "${meta.variants}"
}
job "example" {
group "issue" {
task "issue" {
driver = "raw_exec"
env {
VARIANTS_COMMA_SEPARTED = "${meta.variants}"
VARIANT_PATHS_1 = join(":", formatlist("/mnt/media-variant-%s", split(",", "base,uhd")))
VARIANT_PATHS_2 = join(":", [for v in split(",", "base,uhd") : "/mnt/media-variant-${v}"])
META_VARIANT_PATHS_1 = join(":", formatlist("/mnt/media-variant-%s", split(",", "${meta.variants}")))
META_VARIANT_PATHS_2 = join(":", [for v in split(",", "${meta.variants}") : "/mnt/media-variant-${v}"])
META_VARIANT_PATHS_3 = join(":", formatlist("/mnt/media-variant-%s", split(",", "${local.variants}")))
META_VARIANT_PATHS_4 = join(":", [for v in split(",", "${local.variants}") : "/mnt/media-variant-${v}"])
OTHER_FUNCTIONS = join(":", ["${meta.variants}", local.variants])
}
config {
command = "/bin/bash"
args = ["${NOMAD_TASK_DIR}/test.sh"]
}
template {
data = <<-EOF
#!/bin/bash
echo $VARIANTS_COMMA_SEPARTED
echo $VARIANT_PATHS_1
echo $VARIANT_PATHS_2
echo $META_VARIANT_PATHS_1
echo $META_VARIANT_PATHS_2
echo $META_VARIANT_PATHS_3
echo $META_VARIANT_PATHS_4
echo $OTHER_FUNCTIONS
# Keep script running
tail -f /dev/null
EOF
destination = "local/test.sh"
}
}
}
} That returns:
It looks like the parameters of the I'm going to re-title this for clarity and mark it for roadmapping. The issue will be updated when someone is working on it. For @heatzync's report:
Correct. See the HCL Parsing Context docs. The value you're trying to interpolate into |
split
function doesn't evaluate its parameters
Thanks @tgross for the followup! |
Nomad version
1.2.3
Operating system and Environment details
Ubuntu 20.04 LTS
Issue
With
meta.variants_comma_separated
being set to"base,uhd"
, using HCL2, the output doesn't appear to be split properly. For example,join(":", [for v in split(",", meta.variants_comma_separated) : "/mnt/media-variant-${v}"])
returns/mnt/media-variant-base,uhd
However, if the value is hardcoded
join(":", [for v in split(",", "base,uhd") : "/mnt/media-variant-${v}"])
returns/mnt/media-variant-base:/mnt/media-variant-uhd
Reproduction steps
/etc/nomad.d/nomad.hcl
with job file
Expected Result
STDOUT
should returnActual Result
STDOUT
instead returnsNomad Server logs (if appropriate)
Nomad Client logs (if appropriate)
The text was updated successfully, but these errors were encountered: