-
Notifications
You must be signed in to change notification settings - Fork 2k
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
api: enable support for setting original job source #16763
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eaddac3
api: enable support for setting original source alongside job
shoenig 7cb92c2
api: avoid writing var content to disk for parsing
shoenig 1699883
api: move submission validation into RPC layer
shoenig f19721c
api: return an error if updating a job submission without namespace o…
shoenig 37e71b2
api: be exact about the job index we associate a submission with (mod…
shoenig 097e7c2
api: reword api docs scheduling
shoenig ca315b5
api: prune all but the last 6 job submissions
shoenig dc6ebe6
api: protect against nil job submission in job validation
shoenig ee22376
api: set max job source size in test server
shoenig c9ef5c9
api: fixups from pr
shoenig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
api: enable support for storing original job source | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |||||||
"time" | ||||||||
|
||||||||
"github.com/hashicorp/cronexpr" | ||||||||
"golang.org/x/exp/maps" | ||||||||
) | ||||||||
|
||||||||
const ( | ||||||||
|
@@ -68,6 +69,11 @@ type JobsParseRequest struct { | |||||||
// HCLv1 indicates whether the JobHCL should be parsed with the hcl v1 parser | ||||||||
HCLv1 bool `json:"hclv1,omitempty"` | ||||||||
|
||||||||
// Variables are HCL2 variables associated with the job. Only works with hcl2. | ||||||||
// | ||||||||
// Interpreted as if it were the content of a variables file. | ||||||||
Variables string | ||||||||
|
||||||||
// Canonicalize is a flag as to if the server should return default values | ||||||||
// for unset fields | ||||||||
Canonicalize bool | ||||||||
|
@@ -78,7 +84,7 @@ func (c *Client) Jobs() *Jobs { | |||||||
return &Jobs{client: c} | ||||||||
} | ||||||||
|
||||||||
// ParseHCL is used to convert the HCL repesentation of a Job to JSON server side. | ||||||||
// ParseHCL is used to convert the HCL representation of a Job to JSON server side. | ||||||||
// To parse the HCL client side see package github.com/hashicorp/nomad/jobspec | ||||||||
// Use ParseHCLOpts if you need to customize JobsParseRequest. | ||||||||
func (j *Jobs) ParseHCL(jobHCL string, canonicalize bool) (*Job, error) { | ||||||||
|
@@ -89,10 +95,8 @@ func (j *Jobs) ParseHCL(jobHCL string, canonicalize bool) (*Job, error) { | |||||||
return j.ParseHCLOpts(req) | ||||||||
} | ||||||||
|
||||||||
// ParseHCLOpts is used to convert the HCL representation of a Job to JSON | ||||||||
// server side. To parse the HCL client side see package | ||||||||
// github.com/hashicorp/nomad/jobspec. | ||||||||
// ParseHCL is an alternative convenience API for HCLv2 users. | ||||||||
// ParseHCLOpts is used to request the server convert the HCL representation of a | ||||||||
// Job to JSON on our behalf. Accepts HCL1 or HCL2 jobs as input. | ||||||||
func (j *Jobs) ParseHCLOpts(req *JobsParseRequest) (*Job, error) { | ||||||||
var job Job | ||||||||
_, err := j.client.put("/v1/jobs/parse", req, &job, nil) | ||||||||
|
@@ -116,6 +120,7 @@ type RegisterOptions struct { | |||||||
PolicyOverride bool | ||||||||
PreserveCounts bool | ||||||||
EvalPriority int | ||||||||
Submission *JobSubmission | ||||||||
} | ||||||||
|
||||||||
// Register is used to register a new job. It returns the ID | ||||||||
|
@@ -134,9 +139,7 @@ func (j *Jobs) EnforceRegister(job *Job, modifyIndex uint64, q *WriteOptions) (* | |||||||
// returns the ID of the evaluation, along with any errors encountered. | ||||||||
func (j *Jobs) RegisterOpts(job *Job, opts *RegisterOptions, q *WriteOptions) (*JobRegisterResponse, *WriteMeta, error) { | ||||||||
// Format the request | ||||||||
req := &JobRegisterRequest{ | ||||||||
Job: job, | ||||||||
} | ||||||||
req := &JobRegisterRequest{Job: job} | ||||||||
if opts != nil { | ||||||||
if opts.EnforceIndex { | ||||||||
req.EnforceIndex = true | ||||||||
|
@@ -145,6 +148,7 @@ func (j *Jobs) RegisterOpts(job *Job, opts *RegisterOptions, q *WriteOptions) (* | |||||||
req.PolicyOverride = opts.PolicyOverride | ||||||||
req.PreserveCounts = opts.PreserveCounts | ||||||||
req.EvalPriority = opts.EvalPriority | ||||||||
req.Submission = opts.Submission | ||||||||
} | ||||||||
|
||||||||
var resp JobRegisterResponse | ||||||||
|
@@ -252,6 +256,19 @@ func (j *Jobs) Versions(jobID string, diffs bool, q *QueryOptions) ([]*Job, []*J | |||||||
return resp.Versions, resp.Diffs, qm, nil | ||||||||
} | ||||||||
|
||||||||
// Submission is used to retrieve the original submitted source of a job given its | ||||||||
// namespace, jobID, and version number. The original source might not be available, | ||||||||
// which case nil is returned with no error. | ||||||||
func (j *Jobs) Submission(jobID string, version int, q *QueryOptions) (*JobSubmission, *QueryMeta, error) { | ||||||||
var sub JobSubmission | ||||||||
s := fmt.Sprintf("/v1/job/%s/submission?version=%d", url.PathEscape(jobID), version) | ||||||||
qm, err := j.client.query(s, &sub, q) | ||||||||
if err != nil { | ||||||||
return nil, nil, err | ||||||||
} | ||||||||
return &sub, qm, nil | ||||||||
} | ||||||||
|
||||||||
// Allocations is used to return the allocs for a given job ID. | ||||||||
func (j *Jobs) Allocations(jobID string, allAllocs bool, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error) { | ||||||||
var resp []*AllocationListStub | ||||||||
|
@@ -863,6 +880,51 @@ type ParameterizedJobConfig struct { | |||||||
MetaOptional []string `mapstructure:"meta_optional" hcl:"meta_optional,optional"` | ||||||||
} | ||||||||
|
||||||||
// JobSubmission is used to hold information about the original content of a job | ||||||||
// specification being submitted to Nomad. | ||||||||
// | ||||||||
// At any time a JobSubmission may be nil, indicating no information is known about | ||||||||
// the job submission. | ||||||||
type JobSubmission struct { | ||||||||
// Source contains the original job definition (may be in the format of | ||||||||
// hcl1, hcl2, or json). | ||||||||
Source string | ||||||||
|
||||||||
// Format indicates what the Source content was (hcl1, hcl2, or json). | ||||||||
Format string | ||||||||
|
||||||||
// VariableFlags contains the CLI "-var" flag arguments as submitted with the | ||||||||
// job (hcl2 only). | ||||||||
VariableFlags map[string]string | ||||||||
|
||||||||
// Variables contains the opaque variables configuration as coming from | ||||||||
// a var-file or the WebUI variables input (hcl2 only). | ||||||||
Variables string | ||||||||
} | ||||||||
|
||||||||
func (js *JobSubmission) Canonicalize() { | ||||||||
if js == nil { | ||||||||
return | ||||||||
} | ||||||||
|
||||||||
if len(js.VariableFlags) == 0 { | ||||||||
js.VariableFlags = nil | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
func (js *JobSubmission) Copy() *JobSubmission { | ||||||||
if js == nil { | ||||||||
return nil | ||||||||
} | ||||||||
|
||||||||
return &JobSubmission{ | ||||||||
Source: js.Source, | ||||||||
Format: js.Format, | ||||||||
VariableFlags: maps.Clone(js.VariableFlags), | ||||||||
Variables: js.Variables, | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
// Job is used to serialize a job. | ||||||||
type Job struct { | ||||||||
/* Fields parsed from HCL config */ | ||||||||
|
@@ -1248,7 +1310,9 @@ type JobRevertRequest struct { | |||||||
|
||||||||
// JobRegisterRequest is used to update a job | ||||||||
type JobRegisterRequest struct { | ||||||||
Job *Job | ||||||||
Submission *JobSubmission | ||||||||
Job *Job | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
// If EnforceIndex is set then the job will only be registered if the passed | ||||||||
// JobModifyIndex matches the current Jobs index. If the index is zero, the | ||||||||
// register only occurs if the job is new. | ||||||||
|
@@ -1386,6 +1450,12 @@ type JobVersionsResponse struct { | |||||||
QueryMeta | ||||||||
} | ||||||||
|
||||||||
// JobSubmissionResponse is used for a job get submission request | ||||||||
type JobSubmissionResponse struct { | ||||||||
Submission *JobSubmission | ||||||||
QueryMeta | ||||||||
} | ||||||||
|
||||||||
// JobStabilityRequest is used to marked a job as stable. | ||||||||
type JobStabilityRequest struct { | ||||||||
// Job to set the stability on | ||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this a
map[string]string
to preserve each filename and and its contents?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the parse endpoint is really only used by the webUI and the webUI's variable content is coming from a html form, I don't think it quite make sense to associate the content with a file name