hashicorp / nomad

Nomad is an easy-to-use, flexible, and performant workload orchestrator that can deploy a mix of microservice, batch, containerized, and non-containerized applications. Nomad is easy to operate and scale and has native Consul and Vault integrations.
https://www.nomadproject.io/
Other
14.91k stars 1.95k forks source link

Version tag HTTP API doesn't tag latest version (docs+api inaccurate) #24266

Open maxramqvist opened 2 weeks ago

maxramqvist commented 2 weeks ago

Nomad version

Nomad v1.9.1 BuildDate 2024-10-21T09:00:50Z Revision d9ec23f0c1035401e9df6c64d6ffb8bffc555a5e

With ACLs enabled and using Nomad namespaces.

Operating system and Environment details

Ubuntu 22.04, kernel 6.9.3 on x86_64

Issue

According to the docs:

Optionally, you can also supply a tag description and a version number. If you do not supply a version number, Nomad tags the latest version.

If I don't supply the version number the oldest version gets tagged instead of the latest version.

Reproduction steps

  1. Nomad doesn't tag the latest version. The version must be specified in the POST body for the tagging to work.
    curl -H "x-nomad-token: $NOMAD_TOKEN" http://localhost:4646/v1/job/test-service/versions/vLatest/tag\?namespace\=mynamespace -X POST -d '{}'  
    {"Name":"vLatest","Description":"","TaggedTime":1729537471780368140,"Index":232,"LastContact":0,"KnownLeader":false,"NextToken":""}

    image

Adding Version to the body tags the version intended. curl -H "x-nomad-token: $NOMAD_TOKEN" http://localhost:4646/v1/job/test-service/versions/vActualLatest/tag\?namespace\=mynamespace -X POST -d '{"Version": 3}' Results in: {"Name":"vActualLatest","Description":"","TaggedTime":1729537656801230518,"Index":270,"LastContact":0,"KnownLeader":false,"NextToken":""} Results in the desired version getting tagged: image

  1. An empty body isn't accepted, but a body with an empty JSON object {} is accepted. No biggie really, just not obvious that its required.

curl -X POST -H "x-nomad-token: $NOMAD_TOKEN" http://localhost:4646/v1/job/test-service/versions/v3/tag\?namespace\=mynamespace results in the response: Request body is empty. Specifying an empty JSON as request body works: curl -H "x-nomad-token: $NOMAD_TOKEN" http://localhost:4646/v1/job/test-service/versions/v3/tag\?namespace\=mynamespace -X POST -d '{}', response: ``{"Name":"v3","Description":"","TaggedTime":1729537150671061477,"Index":186,"LastContact":0,"KnownLeader":false,"NextToken":""}

Expected Result

I could create a tag on the latest version of a job without specifying the exact version of the job, as the docs say.

Actual Result

The first version, number 0, gets tagged if I don't specify the exact version I want to tag.

maxramqvist commented 2 weeks ago

Another issue is that diffs doesn't work in the UI. As you can see in the screenshots, the web ui shows "No changes" - but I've made changes to a few different things in the job. Meta, Docker configuration (labels, image) and some Consul tags.

Using the "Diff against"-button results in that button changing and the url changing but nothing else. I checked the browsers dev tools aswell, no requests get sent when using that button.

Can confirm it both happens on when running Nomad in dev mode and proper production mode with a server cluster and separate clients.

Perhaps I should post a separate issue?

philrenaud commented 2 weeks ago

Yes, I'd appreciate a second issue for that one — should definitely be showing you diffs between job versions. For a minimum reproduction, could you try modifying a task group's count value to see if that shows up in the diff?

maxramqvist commented 2 weeks ago

Yep, I'll post a proper issue for that tomorrow. Can confirm no diffs are shown when just changing count.

Thanks in the meantime. Nomad really is a great product!

philrenaud commented 2 weeks ago

Thanks for saying so!

And regarding the original issue:

So that's two upcoming changes: one to clarify in the docs that latest-version is only presumed for CLI requests, and another to throw an error when a version is not supplied to the HTTP API.