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

cli: add -json flag to support job commands #12591

Merged
merged 2 commits into from
Apr 21, 2022
Merged

cli: add -json flag to support job commands #12591

merged 2 commits into from
Apr 21, 2022

Conversation

schmichael
Copy link
Member

@schmichael schmichael commented Apr 16, 2022

Fixes #6758
Fixes #1749

While the CLI has always supported running JSON jobs, its support has
been via HCLv2's JSON parsing. I have no idea what format it expects the
job to be in, but it's absolutely not in the same format as the API
expects.

So I ignored that and added a new -json flag to explicitly support API
style JSON jobspecs.

@schmichael schmichael changed the title wip add json jobspec support to cli cli: add -json flag to support job commands Apr 20, 2022
@schmichael schmichael marked this pull request as ready for review April 20, 2022 00:07
Copy link
Member

@jrasell jrasell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!!!

Copy link
Member

@jrasell jrasell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed the test failure on my original review. It looks like the plan command is failing with a redefined flag:

panic: job plan flag redefined: hcl1 [recovered]
	panic: job plan flag redefined: hcl1

goroutine 19967 [running]:
testing.tRunner.func1.2({0x22f6e60, 0xc003aae680})
	/usr/local/go/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1212 +0x218
panic({0x22f6e60, 0xc003aae680})
	/usr/local/go/src/runtime/panic.go:1038 +0x215
flag.(*FlagSet).Var(0xc0042ff920, {0x2ea2d28, 0xc0048eb3b0}, {0x2907e23, 0x4}, {0x0, 0x0})
	/usr/local/go/src/flag/flag.go:879 +0x2f4
flag.(*FlagSet).BoolVar(...)
	/usr/local/go/src/flag/flag.go:632
github.com/hashicorp/nomad/command.(*JobPlanCommand).Run(0xc0048eb300, {0xc004f6f410, 0x3, 0x3})
	/home/circleci/go/src/github.com/hashicorp/nomad/command/job_plan.go:142 +0x237
github.com/hashicorp/nomad/command.TestPlanCommand_Fails(0xc00429b6c0)
	/home/circleci/go/src/github.com/hashicorp/nomad/command/job_plan_test.go:33 +0x198
testing.tRunner(0xc00429b6c0, 0x2a227d8)
	/usr/local/go/src/testing/testing.go:1259 +0x102
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1306 +0x35a
	``

Copy link
Contributor

@lgfa29 lgfa29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ nomad job inspect example | jq '.Job.TaskGroups[0].Count = 2' | nomad job run -json -

🎉

Just needs a quick fix in the CHANGELOG file.

.changelog/12591.txt Show resolved Hide resolved
While the CLI has always supported running JSON jobs, its support has
been via HCLv2's JSON parsing. I have no idea what format it expects the
job to be in, but it's absolutely not in the same format as the API
expects.

So I ignored that and added a new -json flag to explicitly support *API*
style JSON jobspecs.

The jobspecs can even have the wrapping {"Job": {...}} envelope or not!
We haven't been able to validate inside driver config stanzas ever since
the move to task driver plugins. 😭
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accept JSON via nomad job run CLI should accept JSON job specs
3 participants