-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Tag and Untag job versions #23863
base: epic/23794-golden-versions
Are you sure you want to change the base?
Tag and Untag job versions #23863
Conversation
Ember Test Audit comparison
|
86153aa
to
233f051
Compare
a3b6b5e
to
bb9ef81
Compare
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.
looks pretty good! few comments for ye
s.parseWriteRequest(req, &rpcArgs.WriteRequest) | ||
|
||
var out structs.JobTagResponse | ||
if err := s.agent.RPC("Job.TagVersion", &rpcArgs, &out); err != nil { |
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.
these two httpserver methods are almost identical except for the RPC that they call, so you could save a decent little bit of duplicate code by moving the logic into the main jobTagVersion
method instead.
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.
I ended up splitting these up a bit more — the differences started compounding (unset
doesn't get version
passed in now that we go by tag name; they both get their own structs for req/resp, etc.)
Not opposed to having a single method to handle these but they look to me like they should be separated currently
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.
(This did in fact end up being a fence I straddled and continue to straddle — see "request for reviewers" code comment)
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.
This is looking great @philrenaud!
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.
LGTM!
I've left a couple last items but once you've resolved those this is good-to-merge.
* TaggedVersion information in structs, rather than job_endpoint * Test for taggedVersion description length * Some API plumbing
21ec042
to
7568f47
Compare
17e3baf
to
86d89c7
Compare
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.
mostly easy stuff, couple of concerns for your consideration!
|
||
// parseVersion parses the version flag and returns the index, whether it | ||
// was set and potentially an error during parsing. | ||
func parseVersion(input string) (uint64, bool, error) { |
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.
this doesn't appear to be used; I suspect it was orphaned here when the version str->int logic was moved to command
jobID, namespace, err := c.JobIDByPrefix(client, jobIDPrefix, nil) | ||
if err != nil { | ||
c.Ui.Error(err.Error()) | ||
return 1 | ||
} | ||
|
||
// If the version is not provided, get the "active" version of the job | ||
var versionInt uint64 | ||
if versionStr == "" { | ||
q := &api.QueryOptions{ | ||
Namespace: namespace, | ||
} | ||
latestVersion, _, err := client.Jobs().Info(job, q) |
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.
couldn't this be a single call? or is it two so that users can provide just a prefix?
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.
Because versions can be 0, we need to query in order to have a TagVersion
API that's both ergonomic and unambiguous.
// err := state.UpsertJob(structs.MsgTypeTestSetup, 1000, nil, v0) | ||
// must.NoError(t, err) |
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.
vestigial
func (c *JobTagUnsetCommand) AutocompleteFlags() complete.Flags { | ||
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), | ||
complete.Flags{ | ||
// "-version": complete.PredictNothing, |
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.
vestigial
return j, nil | ||
} | ||
} | ||
return nil, nil |
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.
my nil pointer sense is tingling! to me nil, nil
return for (*pointer, error)
is a capital offense.
shouldn't it be an error if they asked for a tag by name, but no such tag exists?
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.
Most of the single-object state store methods return nil, nil
on non-existing objects, rather than some kind of NotFound
error.
latestJob, err := s.JobByID(nil, namespace, jobID) | ||
if err != nil { | ||
return err | ||
} | ||
if versionCopy.Version == latestJob.Version { | ||
if err := txn.Insert("jobs", versionCopy); err != nil { | ||
return err | ||
} | ||
} |
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.
I sure hope that versionCopy
and latestJob
are otherwise totally identical, since this replaces the latter with the former in the "jobs" table.
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.
job
and latestJob
are pointers to the exact same struct, so versionCopy
is a copy of job
that for safe upsert that needs to be done to any table where we have that pointer.
via
curl
:Adds a tag to Version 3:
Removes the tag:
via Nomad CLI:
Adds a tag to Version 0:
Adds a tag to the latest/current version:
Removes a tag: