2019-06-06 19:18:45 +00:00
|
|
|
# New `jobspec` Entry Checklist
|
|
|
|
|
|
|
|
## Code
|
|
|
|
|
2020-12-15 20:38:33 +00:00
|
|
|
* [ ] Consider similar features in Consul, Kubernetes, and other tools. Is there prior art we should match? Terminology, structure, etc?
|
2019-06-12 22:35:48 +00:00
|
|
|
* [ ] Add structs/fields to `api/` package
|
2020-12-15 20:38:33 +00:00
|
|
|
* `api/` structs usually have Canonicalize and Copy methods
|
|
|
|
* New fields should be added to existing Canonicalize, Copy methods
|
|
|
|
* Test the structs/fields via methods mentioned above
|
2019-06-12 22:35:48 +00:00
|
|
|
* [ ] Add structs/fields to `nomad/structs` package
|
2023-03-14 14:46:00 +00:00
|
|
|
* `structs/` structs usually have Copy, Equal, and Validate methods
|
|
|
|
* `Validate` methods in this package _must_ be implemented
|
|
|
|
* `Equal` methods are used when comparing one job to another (e.g. did this thing get updated?)
|
|
|
|
* `Copy` methods ensure modifications do not modify the copy of a job in the state store
|
|
|
|
* Use `slices.CloneFunc` and `maps.CloneFunc` to ensure creation of deep copies
|
2020-04-10 23:44:19 +00:00
|
|
|
* Note that analogous struct field names should match with `api/` package
|
2020-12-15 20:38:33 +00:00
|
|
|
* Test the structs/fields via methods mentioned above
|
|
|
|
* Implement and test other logical methods
|
2021-03-23 17:55:34 +00:00
|
|
|
* [ ] Add conversion between `api/` and `nomad/structs/` in `command/agent/job_endpoint.go`
|
2020-12-15 20:38:33 +00:00
|
|
|
* Add test for conversion
|
2021-03-23 17:55:34 +00:00
|
|
|
* [ ] Determine JSON encoding strategy for responses from RPC (see "JSON Encoding" below)
|
|
|
|
* [ ] Write `nomad/structs/` to `api/` conversions if necessary and write tests
|
2020-12-15 20:38:33 +00:00
|
|
|
* [ ] Implement diff logic for new structs/fields in `nomad/structs/diff.go`
|
2020-03-25 15:33:27 +00:00
|
|
|
* Note that fields must be listed in alphabetical order in `FieldDiff` slices in `nomad/structs/diff_test.go`
|
2020-12-15 20:38:33 +00:00
|
|
|
* Add test for diff of new structs/fields
|
2021-02-11 15:40:59 +00:00
|
|
|
* [ ] Add change detection for new structs/fields in `scheduler/util.go/tasksUpdated`
|
2020-12-15 20:38:33 +00:00
|
|
|
* Might be covered by `.Equals` but might not be, check.
|
|
|
|
* Should return true if the task must be replaced as a result of the change.
|
2019-06-06 19:18:45 +00:00
|
|
|
|
2020-11-30 15:46:40 +00:00
|
|
|
## HCL1 (deprecated)
|
|
|
|
|
|
|
|
New jobspec entries should only be added to `jobspec2`. It makes use of HCL2
|
|
|
|
and the `api` package for automatic parsing. Before, additional parsing was
|
|
|
|
required in the original `jobspec` package.
|
|
|
|
|
|
|
|
* [ ] ~~Parse in `jobspec/parse.go`~~ (HCL1 only)
|
|
|
|
* [ ] ~~Test in `jobspec/parse_test.go` (preferably with a
|
|
|
|
`jobspec/text-fixtures/<feature>.hcl` test file)~~ (HCL1 only)
|
|
|
|
|
2019-06-06 19:18:45 +00:00
|
|
|
## Docs
|
|
|
|
|
2019-06-12 22:35:48 +00:00
|
|
|
* [ ] Changelog
|
|
|
|
* [ ] Jobspec entry https://www.nomadproject.io/docs/job-specification/index.html
|
2021-03-08 13:50:13 +00:00
|
|
|
* [ ] Jobspec sidebar entry https://github.com/hashicorp/nomad/blob/main/website/data/docs-navigation.js
|
2019-06-12 22:35:48 +00:00
|
|
|
* [ ] Job JSON API entry https://www.nomadproject.io/api/json-jobs.html
|
|
|
|
* [ ] Sample Response output in API https://www.nomadproject.io/api/jobs.html
|
|
|
|
* [ ] Consider if it needs a guide https://www.nomadproject.io/guides/index.html
|
2021-03-23 17:55:34 +00:00
|
|
|
|
|
|
|
## JSON Encoding
|
|
|
|
|
|
|
|
As a general rule, HTTP endpoints (under `command/agent/`) will make RPC calls that return structs belonging to
|
|
|
|
`nomad/structs/`. These handlers ultimately return an object that is encoded by the Nomad HTTP server. The encoded form
|
|
|
|
needs to match the Nomad API; specifically, it should have the form of the corresponding struct from `api/`. There are
|
|
|
|
a few ways that this can be accomplished:
|
|
|
|
* directly return the struct from the RPC call, if it has the same shape as the corresponding struct in `api/`.
|
|
|
|
This is convenient when possible, resulting in the least work for the developer.
|
|
|
|
Examples of this approach include [GET `/v1/evaluation/:id`](https://github.com/hashicorp/nomad/blob/v1.0.
|
|
|
|
0/command/agent/eval_endpoint.go#L88).
|
|
|
|
* convert the struct from the RPC call to the appropriate `api/` struct.
|
|
|
|
This approach is the most developer effort, but it does have a strong guarantee that the HTTP response matches the
|
|
|
|
API, due to the explicit conversion (assuming proper implementation, which requires tests).
|
|
|
|
Examples of this approach include [GET `/v1/volume/csi/:id`](https://github.com/hashicorp/nomad/blob/v1.0.0/command/agent/csi_endpoint.go#L108)
|
|
|
|
* convert to an intermediate struct with the same shape as the `api/` struct.
|
|
|
|
This approach strikes a balance between the former two approaches.
|
|
|
|
This conversion can be performed in-situ in the agent HTTP handler, as long as the conversion doesn't need to
|
|
|
|
appear in other handlers.
|
|
|
|
Otherwise, it is possible to register an extension on the JSON encoding used by the HTTP agent; these extensions
|
2021-03-26 17:13:50 +00:00
|
|
|
can be put in `nomad/jsonhandles/extensions.go`.
|