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

Cannot use go templates for job status output #24050

Closed
pgporada opened this issue Sep 23, 2024 · 5 comments · Fixed by #24054
Closed

Cannot use go templates for job status output #24050

pgporada opened this issue Sep 23, 2024 · 5 comments · Fixed by #24054
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/cli type/bug

Comments

@pgporada
Copy link
Contributor

Nomad version

$ nomad version
Nomad v1.8.2
BuildDate 2024-07-16T08:50:09Z
Revision 7f0822c1e4f25907d9f60e2d595411950dd1bd28

Operating system and Environment details

Ubuntu 24.04

Issue

Reproduction steps

Outputting the job status with no flags works as intended.

$ nomad job status unbound
ID            = unbound
Name          = unbound
Submit Date   = 2024-08-26T15:12:03Z
Type          = service
Priority      = 50
Datacenters   = *
Namespace     = default
Node Pool     = default
Status        = running
Periodic      = false
Parameterized = false

Summary
Task Group  Queued  Starting  Running  Failed  Complete  Lost  Unknown
unbound     0       0         1        10      7         0     0

Allocations
ID        Node ID   Task Group  Version  Desired  Status   Created    Modified
6434d73b  91601963  unbound     1        run      running  6h33m ago  6h32m ago

Outputting json works too

$ nomad job status -json unbound
[
    {
        "Allocations": [
            {
                "ClientDescription": "Tasks are running",
                "ClientStatus": "running",
                "CreateIndex": 54792,
                "CreateTime": 1727102074670516215,
                "DeploymentStatus": {
                    "Canary": false,
                    "Healthy": true,
                    "ModifyIndex": 54798,
                    "Timestamp": "2024-09-23T14:35:00.770167884Z"
                },
                "DesiredDescription": "",
                "DesiredStatus": "run",
...

Using the go template flag fails

$ nomad job status -t unbound
Both json and template formatting are not allowed

Expected Result

That's a good question, I was just playing around seeing what I could output without needing to filter with grep or jq.

Actual Result

See above in reproduction steps

Job file (if appropriate)

N/A

Nomad Server logs (if appropriate)

N/A

Nomad Client logs (if appropriate)

N/A

@tgross
Copy link
Member

tgross commented Sep 24, 2024

Hi @pgporada! Yup, that's working as expected (although we should probably document it). Go template works on the in-memory representation of the objects we're sending, so once we've serialized it to JSON it's no longer "structured" (to the CLI it's now just a string of bytes) and Go templates won't work anymore.

@pgporada
Copy link
Contributor Author

pgporada commented Sep 24, 2024

How should that -t flag be used then because to me it seems to provide no benefit to the user?

@tgross
Copy link
Member

tgross commented Sep 24, 2024

🤦 I'm having a whole morning of reading issue reports too quickly. I blame lack of coffee. You're right, if you're not also using the -json flag that -t flag should work fine. The bug is here: job_status.go#L176. That true parameter should instead be json to pass the value of the -json flag.

That'll let you do Go template evaluations like this, using this weirdly gnarly JobJson object

$ nomad job status -t '{{ range $job := . }}{{$job.Summary.JobID}}{{end}}' example

Fixed in #24054

@tgross tgross reopened this Sep 24, 2024
@github-project-automation github-project-automation bot moved this from Done to Needs Triage in Nomad - Community Issues Triage Sep 24, 2024
@pgporada
Copy link
Contributor Author

Cool, thank you! Cheers on ☕

tgross added a commit that referenced this issue Sep 24, 2024
In #18925 we added a `-json` flag to the `job status` command, but the argument
handling had a bug where it would always set the `-json` flag if either the `-t`
or `-json` flags were set, resulting in a misleading error. Instead, pass the
`-json` flag value into the formatter.

Fixes: #24050
@tgross tgross added stage/accepted Confirmed, and intend to work on. No timeline committment though. and removed stage/not-a-bug labels Sep 24, 2024
@tgross tgross closed this as completed in 65ec00d Sep 25, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Nomad - Community Issues Triage Sep 25, 2024
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 Jan 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/cli type/bug
Projects
Development

Successfully merging a pull request may close this issue.

2 participants