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

set Consul service meta from Nomad service definition #4652

Closed
shantanugadgil opened this issue Sep 7, 2018 · 5 comments
Closed

set Consul service meta from Nomad service definition #4652

shantanugadgil opened this issue Sep 7, 2018 · 5 comments

Comments

@shantanugadgil
Copy link
Contributor

Nomad version

Nomad v0.8.4 (dbee1d7)

Operating system and Environment details

CentOS 7.5+, Ubuntu 14.04.5+

Issue

Using these as reference:
https://www.consul.io/docs/agent/services.html
https://www.nomadproject.io/docs/job-specification/service.html

How can I set the Consul service metadata ("meta") from Nomad's service definition?
As I can gather it doesn't seem to be doable for now.

My final use case is to propagate info like the AWS region, availability zone, machine type, etc. into the service definition.
A Consul Template based job (running on a separate machine) will then use this information to do some other things.

Regards,
Shantanu

@jeteon
Copy link

jeteon commented Sep 27, 2018

What would be nice is if the job, group and task level meta would be merged and then sent to Consul when setting up the service entry. From the Consul end of things it looks like the API already supports setting the meta key:
https://github.com/hashicorp/consul/blob/eddcf228ea1a0b90030db3c820d469ff5b8106a9/api/agent.go#L119-L134.

so it could be added here:

serviceReg := &api.AgentServiceRegistration{
ID: id,
Name: service.Name,
Tags: service.Tags,
Address: host,
Port: port,
}
.

I would expect that the meta keys are already aggregated on the task but I'm not yet sure. Technically, it doesn't seem too difficult to implement this. There's probably a design issue I'm overlooking though.

@chenjpu
Copy link

chenjpu commented Feb 20, 2019

Is there any plan or progress?

@shoenig
Copy link
Member

shoenig commented Dec 18, 2020

Looks like this was implemented in #6193
(with a similar request in #4300)

What would be nice is if the job, group and task level meta would be merged and then sent to Consul when setting up the service entry.

@jeteon Although I don't think there's any technical reason this couldn't be implemented, it would at this point be a significant backwards incompatible change. Instead, you might be able to realize a similar effect by making use of HCL2 features.

@shoenig shoenig closed this as completed Dec 18, 2020
@shantanugadgil
Copy link
Contributor Author

Sorry for the delay, I had been trying to remember why I had originally opened that request. 🤭

Thanks, this seems to work as expected ... when I specify the following meta block inside the service stanza.

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

  group "cache" {

    task "sleep" {
      driver = "raw_exec"

      config {
        command = "/bin/sleep"
        args = ["600"]
      }

      service {
        meta {
          region = "${node.region}"
          dc     = "${node.datacenter}"
        }
      }

      resources {
        cpu    = 500
        memory = 256
      }
    }
  }
}

@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 26, 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

5 participants