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

Service tags job/group/task interpolation #16629

Closed
michael-strigo opened this issue Mar 24, 2023 · 2 comments
Closed

Service tags job/group/task interpolation #16629

michael-strigo opened this issue Mar 24, 2023 · 2 comments
Assignees

Comments

@michael-strigo
Copy link

michael-strigo commented Mar 24, 2023

Proposal

In the service{} stanza, the name parameter has access to few special template placeholders:

  • ${JOB}
  • ${TASK}
  • ${TASKGROUP}
  • ${BASE}

It would be nice if the tags of the service would have access to the same placeholders.

Use-cases

System such as Traefik can be configured via tags. For example here's a simple service called "whoami":

job "whoami" {
  ..
    service {
      name = "${JOB}"
      port   = "http"

      tags = [
        "traefik.enable=true",
        "traefik.http.services.whoami.loadBalancer.healthCheck.path=/health",
        "traefik.http.routers.whoami.entryPoints=web,websecure",
        "traefik.http.routers.whoami.rule=Host(`...`)",
      ]
    }
  ..
}

It's very common for people to copy a service definition like this and to forget to change the router/service name inside of the tags array. It would be nice if we could do something like:

    service {
      name = "${JOB}"
      port   = "http"

      tags = [
        "traefik.enable=true",
        "traefik.http.services.${JOB}.loadBalancer.healthCheck.path=/health",
        "traefik.http.routers.${JOB}.entryPoints=web,websecure",
        "traefik.http.routers.${JOB}.rule=Host(`...`)",
      ]
    }
@jrasell
Copy link
Member

jrasell commented Mar 24, 2023

Hi @michael-strigo and thanks for raising this issue.

I want to be careful of adding more special cases for this use, as it would be easy to spread. I could imagine if we added this, additional requests to make these available in service checks and other areas of the jobspec. Therefore I wonder if we can't use the traditional interpolation variables that are available for this? The mapping is as follows:

  • ${JOB} == ${NOMAD_JOB_NAME} or ${NOMAD_JOB_ID}
  • ${TASKGROUP} == ${NOMAD_GROUP_NAME}
  • ${TASK} == ${NOMAD_TASK_NAME}
  • ${BASE} == ${NOMAD_JOB_NAME}-${NOMAD_GROUP_NAME}-${NOMAD_TASK_NAME} (I understand this is a bit annoying)

@jrasell jrasell self-assigned this Mar 24, 2023
@michael-strigo
Copy link
Author

oh, I was under the impression these are only available values to the running task as an environment variable and cannot be used for interpolation in the tags values. Seems like it does!

In that case it raises the question - what's the point of having special job/taskgroup/task/base placeholders?

Going to close this issue because I think the suggested solution makes the suggestion unnecessary. Thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants