diff --git a/api/jobs.go b/api/jobs.go index dab1bb3903e..907f548c434 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -270,7 +270,7 @@ func (j *Jobs) Versions(jobID string, diffs bool, q *QueryOptions) ([]*Job, []*J return j.VersionsOpts(jobID, opts, q) } -// VersionByTag is used to retrieve a job version by its TaggedVersion name. +// VersionByTag is used to retrieve a job version by its VersionTag name. func (j *Jobs) VersionByTag(jobID, tag string, q *QueryOptions) (*Job, *QueryMeta, error) { versions, _, qm, err := j.Versions(jobID, false, q) if err != nil { @@ -279,7 +279,7 @@ func (j *Jobs) VersionByTag(jobID, tag string, q *QueryOptions) (*Job, *QueryMet // Find the version with the matching tag for _, version := range versions { - if version.TaggedVersion != nil && version.TaggedVersion.Name == tag { + if version.VersionTag != nil && version.VersionTag.Name == tag { return version, qm, nil } } @@ -1030,18 +1030,18 @@ func (j *JobUILink) Copy() *JobUILink { } } -type JobTaggedVersion struct { +type JobVersionTag struct { Name string Description string TaggedTime int64 } -func (j *JobTaggedVersion) Copy() *JobTaggedVersion { +func (j *JobVersionTag) Copy() *JobVersionTag { if j == nil { return nil } - return &JobTaggedVersion{ + return &JobVersionTag{ Name: j.Name, Description: j.Description, TaggedTime: j.TaggedTime, @@ -1126,7 +1126,7 @@ type Job struct { CreateIndex *uint64 ModifyIndex *uint64 JobModifyIndex *uint64 - TaggedVersion *JobTaggedVersion + VersionTag *JobVersionTag } // IsPeriodic returns whether a job is periodic. diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index e60e1c38a10..19b30e81def 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -430,7 +430,7 @@ func (s *HTTPServer) jobVersionApplyTag(resp http.ResponseWriter, req *http.Requ JobID: jobID, Version: args.Version, Name: name, - Tag: &structs.JobTaggedVersion{ + Tag: &structs.JobVersionTag{ Name: name, Description: args.Description, }, @@ -1113,7 +1113,7 @@ func ApiJobToStructJob(job *api.Job) *structs.Job { Constraints: ApiConstraintsToStructs(job.Constraints), Affinities: ApiAffinitiesToStructs(job.Affinities), UI: ApiJobUIConfigToStructs(job.UI), - TaggedVersion: ApiJobTaggedVersionToStructs(job.TaggedVersion), + VersionTag: ApiJobVersionTagToStructs(job.VersionTag), } // Update has been pushed into the task groups. stagger and max_parallel are @@ -2218,15 +2218,15 @@ func ApiJobUIConfigToStructs(jobUI *api.JobUIConfig) *structs.JobUIConfig { } } -func ApiJobTaggedVersionToStructs(jobTaggedVersion *api.JobTaggedVersion) *structs.JobTaggedVersion { - if jobTaggedVersion == nil { +func ApiJobVersionTagToStructs(jobVersionTag *api.JobVersionTag) *structs.JobVersionTag { + if jobVersionTag == nil { return nil } - return &structs.JobTaggedVersion{ - Name: jobTaggedVersion.Name, - Description: jobTaggedVersion.Description, - TaggedTime: jobTaggedVersion.TaggedTime, + return &structs.JobVersionTag{ + Name: jobVersionTag.Name, + Description: jobVersionTag.Description, + TaggedTime: jobVersionTag.TaggedTime, } } diff --git a/command/agent/job_endpoint_test.go b/command/agent/job_endpoint_test.go index c5d2c1b9e33..def1fde1240 100644 --- a/command/agent/job_endpoint_test.go +++ b/command/agent/job_endpoint_test.go @@ -4449,34 +4449,34 @@ func TestConversion_ApiJobUIConfigToStructs(t *testing.T) { }) } -func TestConversion_ApiJobTaggedVersionToStructs(t *testing.T) { +func TestConversion_ApiJobVersionTagToStructs(t *testing.T) { t.Run("nil tagged version", func(t *testing.T) { - must.Nil(t, ApiJobTaggedVersionToStructs(nil)) + must.Nil(t, ApiJobVersionTagToStructs(nil)) }) t.Run("empty tagged version", func(t *testing.T) { - taggedVersion := &api.JobTaggedVersion{} - expected := &structs.JobTaggedVersion{ + versionTag := &api.JobVersionTag{} + expected := &structs.JobVersionTag{ Name: "", Description: "", TaggedTime: 0, } - result := ApiJobTaggedVersionToStructs(taggedVersion) + result := ApiJobVersionTagToStructs(versionTag) must.Eq(t, expected, result) }) t.Run("tagged version with tag and version", func(t *testing.T) { - taggedVersion := &api.JobTaggedVersion{ + versionTag := &api.JobVersionTag{ Name: "low-latency", Description: "Low latency version", TaggedTime: 1234567890, } - expected := &structs.JobTaggedVersion{ + expected := &structs.JobVersionTag{ Name: "low-latency", Description: "Low latency version", TaggedTime: 1234567890, } - result := ApiJobTaggedVersionToStructs(taggedVersion) + result := ApiJobVersionTagToStructs(versionTag) must.Eq(t, expected, result) }) } diff --git a/command/job_history.go b/command/job_history.go index fb1ae2b8015..8d513b31090 100644 --- a/command/job_history.go +++ b/command/job_history.go @@ -291,10 +291,10 @@ func (c *JobHistoryCommand) formatJobVersion(job *api.Job, diff *api.JobDiff, fu fmt.Sprintf("Submit Date|%v", formatTime(time.Unix(0, *job.SubmitTime))), } // if tagged version is not nil - if job.TaggedVersion != nil { - basic = append(basic, fmt.Sprintf("Tag Name|%v", *&job.TaggedVersion.Name)) - if job.TaggedVersion.Description != "" { - basic = append(basic, fmt.Sprintf("Tag Description|%v", *&job.TaggedVersion.Description)) + if job.VersionTag != nil { + basic = append(basic, fmt.Sprintf("Tag Name|%v", *&job.VersionTag.Name)) + if job.VersionTag.Description != "" { + basic = append(basic, fmt.Sprintf("Tag Description|%v", *&job.VersionTag.Description)) } } diff --git a/command/job_history_test.go b/command/job_history_test.go index 2170e44c285..a30256f1802 100644 --- a/command/job_history_test.go +++ b/command/job_history_test.go @@ -198,7 +198,7 @@ func TestJobHistoryCommand_Diffs(t *testing.T) { v1 := v0.Copy() v1.TaskGroups[0].Count = 2 - v1.TaggedVersion = &structs.JobTaggedVersion{ + v1.VersionTag = &structs.JobVersionTag{ Name: "example-tag", Description: "example-description", } diff --git a/command/job_revert_test.go b/command/job_revert_test.go index 5722f99cf11..a57179f3508 100644 --- a/command/job_revert_test.go +++ b/command/job_revert_test.go @@ -216,7 +216,7 @@ func TestJobRevertCommand_VersionTag(t *testing.T) { v1 := v0.Copy() v1.TaskGroups[0].Count = 2 - v1.TaggedVersion = &structs.JobTaggedVersion{ + v1.VersionTag = &structs.JobVersionTag{ Name: "v1-tag", Description: "Version 1 tag", } diff --git a/command/job_tag_test.go b/command/job_tag_test.go index 397a23b25c7..8fb313d9b4f 100644 --- a/command/job_tag_test.go +++ b/command/job_tag_test.go @@ -80,8 +80,8 @@ func TestJobTagApplyCommand_Run(t *testing.T) { code = cmd.Run([]string{"-address=" + url, "-name=test2", v0.ID}) apiJob, _, err := client.Jobs().Info(v0.ID, nil) must.NoError(t, err) - must.NotNil(t, apiJob.TaggedVersion) - must.Eq(t, "test2", apiJob.TaggedVersion.Name) + must.NotNil(t, apiJob.VersionTag) + must.Eq(t, "test2", apiJob.VersionTag.Name) must.StrContains(t, ui.OutputWriter.String(), "Job version 3 tagged with name \"test2\"") must.Zero(t, code) ui.OutputWriter.Reset() diff --git a/nomad/core_sched.go b/nomad/core_sched.go index a4bb53a1e2d..3433daac7cc 100644 --- a/nomad/core_sched.go +++ b/nomad/core_sched.go @@ -163,7 +163,7 @@ OUTER: continue } for _, v := range versions { - if v.TaggedVersion != nil { + if v.VersionTag != nil { continue OUTER } } diff --git a/nomad/core_sched_test.go b/nomad/core_sched_test.go index f77da894409..1ad94d3b6c8 100644 --- a/nomad/core_sched_test.go +++ b/nomad/core_sched_test.go @@ -611,7 +611,7 @@ func TestCoreScheduler_EvalGC_Batch(t *testing.T) { } // A job that has any of its versions tagged should not be GC-able. -func TestCoreScheduler_EvalGC_JobTaggedVersion(t *testing.T) { +func TestCoreScheduler_EvalGC_JobVersionTag(t *testing.T) { ci.Parallel(t) s1, cleanupS1 := TestServer(t, nil) @@ -661,7 +661,7 @@ func TestCoreScheduler_EvalGC_JobTaggedVersion(t *testing.T) { &structs.JobApplyTagRequest{ JobID: job.ID, Name: name, - Tag: &structs.JobTaggedVersion{ + Tag: &structs.JobVersionTag{ Name: name, Description: desc, }, diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index 06c47bfc490..e30ab29a611 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -656,8 +656,8 @@ func (j *Job) Revert(args *structs.JobRevertRequest, reply *structs.JobRegisterR revJob.VaultToken = args.VaultToken // use vault token from revert to perform (re)registration revJob.ConsulToken = args.ConsulToken // use consul token from revert to perform (re)registration - // Clear out the TaggedVersion to prevent tag duplication - revJob.TaggedVersion = nil + // Clear out the VersionTag to prevent tag duplication + revJob.VersionTag = nil reg := &structs.JobRegisterRequest{ Job: revJob, diff --git a/nomad/state/schema.go b/nomad/state/schema.go index 6182caf5137..2c798b06fbe 100644 --- a/nomad/state/schema.go +++ b/nomad/state/schema.go @@ -373,7 +373,7 @@ func jobIsGCable(obj interface{}) (bool, error) { } // job versions that are tagged should be kept - if j.TaggedVersion != nil { + if j.VersionTag != nil { return false, nil } diff --git a/nomad/state/schema_test.go b/nomad/state/schema_test.go index 9ffdf78434b..47415740fbc 100644 --- a/nomad/state/schema_test.go +++ b/nomad/state/schema_test.go @@ -245,7 +245,7 @@ func Test_jobIsGCable(t *testing.T) { { name: "tagged", inputObj: &structs.Job{ - TaggedVersion: &structs.JobTaggedVersion{Name: "any"}, + VersionTag: &structs.JobVersionTag{Name: "any"}, }, expectedOutput: false, expectedOutputError: nil, diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 30f05ed9e8a..c9bfbcbffe7 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -2191,7 +2191,7 @@ func (s *StateStore) upsertJobVersion(index uint64, job *structs.Job, txn *txn) // Find the oldest non-tagged version to delete deleteIdx := -1 for i := len(all) - 1; i >= max; i-- { - if all[i].TaggedVersion == nil { + if all[i].VersionTag == nil { deleteIdx = i break } @@ -2325,7 +2325,7 @@ func (s *StateStore) JobVersionByTagName(ws memdb.WatchSet, namespace, id string return nil, err } for _, j := range versions { - if j.TaggedVersion != nil && j.TaggedVersion.Name == tagName { + if j.VersionTag != nil && j.VersionTag.Name == tagName { return j, nil } } @@ -4952,7 +4952,7 @@ func (s *StateStore) UpdateJobVersionTag(index uint64, namespace string, req *st return txn.Commit() } -func (s *StateStore) updateJobVersionTagImpl(index uint64, namespace, jobID string, jobVersion uint64, tag *structs.JobTaggedVersion, txn *txn) error { +func (s *StateStore) updateJobVersionTagImpl(index uint64, namespace, jobID string, jobVersion uint64, tag *structs.JobVersionTag, txn *txn) error { // Note: could use JobByIDAndVersion to get the specific version we want here, // but then we'd have to make a second lookup to make sure we're not applying a duplicate tag name versions, err := s.JobVersionsByID(nil, namespace, jobID) @@ -4964,7 +4964,7 @@ func (s *StateStore) updateJobVersionTagImpl(index uint64, namespace, jobID stri for _, version := range versions { // Allow for a tag to be updated (new description, for example) but otherwise don't allow a same-tagname to a different version. - if version.TaggedVersion != nil && version.TaggedVersion.Name == tag.Name && version.Version != jobVersion { + if version.VersionTag != nil && version.VersionTag.Name == tag.Name && version.Version != jobVersion { return fmt.Errorf("tag %q already exists on a different version of job %q", tag.Name, jobID) } if version.Version == jobVersion { @@ -4977,7 +4977,7 @@ func (s *StateStore) updateJobVersionTagImpl(index uint64, namespace, jobID stri } versionCopy := job.Copy() - versionCopy.TaggedVersion = tag + versionCopy.VersionTag = tag versionCopy.ModifyIndex = index latestJob, err := s.JobByID(nil, namespace, jobID) @@ -5003,7 +5003,7 @@ func (s *StateStore) unsetJobVersionTagImpl(index uint64, namespace, jobID strin } versionCopy := job.Copy() - versionCopy.TaggedVersion = nil + versionCopy.VersionTag = nil versionCopy.ModifyIndex = index latestJob, err := s.JobByID(nil, namespace, jobID) if err != nil { diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 5e44988e437..bc9a328fa5c 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -2901,11 +2901,11 @@ func TestStateStore_DeleteJobTxn_BatchDeletes(t *testing.T) { require.Equal(t, deletionIndex, index) } -// TestStatestore_JobTaggedVersion tests that job versions which are tagged +// TestStatestore_JobVersionTag tests that job versions which are tagged // do not count against the configured server.job_tracked_versions count, // do not get deleted when new versions are created, // and *do* get deleted immediately when its tag is removed. -func TestStatestore_JobTaggedVersion(t *testing.T) { +func TestStatestore_JobVersionTag(t *testing.T) { ci.Parallel(t) state := testStateStore(t) @@ -2928,7 +2928,7 @@ func TestStatestore_JobTaggedVersion(t *testing.T) { req := &structs.JobApplyTagRequest{ JobID: job.ID, Name: name, - Tag: &structs.JobTaggedVersion{ + Tag: &structs.JobVersionTag{ Name: name, Description: desc, }, @@ -2940,8 +2940,8 @@ func TestStatestore_JobTaggedVersion(t *testing.T) { got, err := state.JobVersionByTagName(nil, job.Namespace, job.ID, name) must.NoError(t, err) must.Eq(t, version, got.Version) - must.Eq(t, name, got.TaggedVersion.Name) - must.Eq(t, desc, got.TaggedVersion.Description) + must.Eq(t, name, got.VersionTag.Name) + must.Eq(t, desc, got.VersionTag.Description) } unsetTag := func(t *testing.T, name string) { t.Helper() @@ -3018,7 +3018,7 @@ func TestStatestore_JobTaggedVersion(t *testing.T) { // job does not exist err := state.UpdateJobVersionTag(nextIndex(state), job.Namespace, &structs.JobApplyTagRequest{ JobID: "non-existent-job", - Tag: &structs.JobTaggedVersion{Name: "tag name"}, + Tag: &structs.JobVersionTag{Name: "tag name"}, Version: 0, }) must.ErrorContains(t, err, `job "non-existent-job" version 0 not found`) @@ -3026,7 +3026,7 @@ func TestStatestore_JobTaggedVersion(t *testing.T) { // version does not exist err = state.UpdateJobVersionTag(nextIndex(state), job.Namespace, &structs.JobApplyTagRequest{ JobID: job.ID, - Tag: &structs.JobTaggedVersion{Name: "tag name"}, + Tag: &structs.JobVersionTag{Name: "tag name"}, Version: 999, }) must.ErrorContains(t, err, fmt.Sprintf("job %q version 999 not found", job.ID)) @@ -3034,7 +3034,7 @@ func TestStatestore_JobTaggedVersion(t *testing.T) { // tag name already exists err = state.UpdateJobVersionTag(nextIndex(state), job.Namespace, &structs.JobApplyTagRequest{ JobID: job.ID, - Tag: &structs.JobTaggedVersion{Name: "v0"}, + Tag: &structs.JobVersionTag{Name: "v0"}, Version: 10, }) must.ErrorContains(t, err, fmt.Sprintf(`"v0" already exists on a different version of job %q`, job.ID)) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index fbe79e268a0..00282c8ba6b 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -4578,10 +4578,10 @@ type Job struct { UI *JobUIConfig // Metadata related to a tagged Job Version (which itself is really a Job) - TaggedVersion *JobTaggedVersion + VersionTag *JobVersionTag } -type JobTaggedVersion struct { +type JobVersionTag struct { Name string Description string TaggedTime int64 @@ -4590,7 +4590,7 @@ type JobTaggedVersion struct { type JobApplyTagRequest struct { JobID string Name string - Tag *JobTaggedVersion + Tag *JobVersionTag Version uint64 WriteRequest } @@ -4602,11 +4602,11 @@ type JobTagResponse struct { QueryMeta } -func (tv *JobTaggedVersion) Copy() *JobTaggedVersion { +func (tv *JobVersionTag) Copy() *JobVersionTag { if tv == nil { return nil } - return &JobTaggedVersion{ + return &JobVersionTag{ Name: tv.Name, Description: tv.Description, TaggedTime: tv.TaggedTime, @@ -4767,7 +4767,7 @@ func (j *Job) Copy() *Job { nj.Affinities = CopySliceAffinities(j.Affinities) nj.Multiregion = j.Multiregion.Copy() nj.UI = j.UI.Copy() - nj.TaggedVersion = j.TaggedVersion.Copy() + nj.VersionTag = j.VersionTag.Copy() if j.TaskGroups != nil { tgs := make([]*TaskGroup, len(j.TaskGroups)) @@ -4865,9 +4865,9 @@ func (j *Job) Validate() error { } } - if j.TaggedVersion != nil { - if len(j.TaggedVersion.Description) > MaxDescriptionCharacters { - mErr.Errors = append(mErr.Errors, fmt.Errorf("Tagged version description must be under 1000 characters, currently %d", len(j.TaggedVersion.Description))) + if j.VersionTag != nil { + if len(j.VersionTag.Description) > MaxDescriptionCharacters { + mErr.Errors = append(mErr.Errors, fmt.Errorf("Tagged version description must be under 1000 characters, currently %d", len(j.VersionTag.Description))) } } diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 727b0100980..520252b9530 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -398,10 +398,10 @@ func TestJob_Validate(t *testing.T) { }, }, { - name: "TaggedVersion Description length", + name: "VersionTag Description length", job: &Job{ Type: JobTypeService, - TaggedVersion: &JobTaggedVersion{ + VersionTag: &JobVersionTag{ Description: strings.Repeat("a", 1001), }, }, diff --git a/ui/app/components/job-version.js b/ui/app/components/job-version.js index b5376b1ff5e..3dbfb7f7f06 100644 --- a/ui/app/components/job-version.js +++ b/ui/app/components/job-version.js @@ -35,10 +35,10 @@ export default class JobVersion extends Component { } initializeEditableTag() { - if (this.version.taggedVersion) { + if (this.version.versionTag) { this.editableTag = this.store.createRecord('versionTag', { - name: this.version.taggedVersion.name, - description: this.version.taggedVersion.description, + name: this.version.versionTag.name, + description: this.version.versionTag.description, }); } else { this.editableTag = this.store.createRecord('versionTag'); @@ -128,8 +128,8 @@ export default class JobVersion extends Component { return; } const savedTag = await this.editableTag.save(); - this.version.taggedVersion = savedTag; - this.version.taggedVersion.setProperties({ + this.version.versionTag = savedTag; + this.version.versionTag.setProperties({ ...savedTag.toJSON(), }); this.initializeEditableTag(); @@ -165,8 +165,7 @@ export default class JobVersion extends Component { title: 'Job Version Un-Tagged', color: 'success', }); - // this.version.set('taggedVersion', null); - this.version.taggedVersion = null; + this.version.versionTag = null; this.initializeEditableTag(); this.isEditing = false; } catch (error) { diff --git a/ui/app/controllers/jobs/job/versions.js b/ui/app/controllers/jobs/job/versions.js index 091428189a5..7a14cc434b4 100644 --- a/ui/app/controllers/jobs/job/versions.js +++ b/ui/app/controllers/jobs/job/versions.js @@ -52,7 +52,7 @@ export default class VersionsController extends Controller.extend( get optionsDiff() { return this.job.versions.map((version) => { return { - label: version.taggedVersion?.name || `version ${version.number}`, + label: version.versionTag?.name || `version ${version.number}`, value: String(version.number), }; }); diff --git a/ui/app/models/job-version.js b/ui/app/models/job-version.js index 8fc1b3700b0..91f6cc55556 100644 --- a/ui/app/models/job-version.js +++ b/ui/app/models/job-version.js @@ -13,7 +13,7 @@ export default class JobVersion extends Model { @attr('date') submitTime; @attr('number') number; @attr() diff; - @fragment('version-tag') taggedVersion; + @fragment('version-tag') versionTag; revertTo() { return this.store.adapterFor('job-version').revertTo(this); diff --git a/ui/app/templates/components/job-version.hbs b/ui/app/templates/components/job-version.hbs index b901fdef8db..275b9794c0f 100644 --- a/ui/app/templates/components/job-version.hbs +++ b/ui/app/templates/components/job-version.hbs @@ -4,7 +4,7 @@ ~}}
-
+
Version #{{this.version.number}} @@ -61,20 +61,20 @@ {{! template-lint-enable no-down-event-binding }} - {{#if this.version.taggedVersion}} + {{#if this.version.versionTag}} {{/if}} {{else}}
- {{#if this.version.taggedVersion}} - + {{#if this.version.versionTag}} + {{else}} {{/if}} - - {{this.version.taggedVersion.description}} + + {{this.version.versionTag.description}}
diff --git a/ui/mirage/factories/job-version.js b/ui/mirage/factories/job-version.js index f7aedc01fbb..4dfa99e327b 100644 --- a/ui/mirage/factories/job-version.js +++ b/ui/mirage/factories/job-version.js @@ -32,7 +32,7 @@ export default Factory.extend({ activeDeployment: false, // version tags - taggedVersion: null, + versionTag: null, afterCreate(version, server) { const args = [ diff --git a/ui/mirage/scenarios/default.js b/ui/mirage/scenarios/default.js index a333ca5e504..6a069657f18 100644 --- a/ui/mirage/scenarios/default.js +++ b/ui/mirage/scenarios/default.js @@ -359,7 +359,7 @@ function smallCluster(server) { job: versionTaggedJob, namespace: 'default', version: 1, - taggedVersion: { + versionTag: { Name: 'burrito', Description: 'A delicious version', }, @@ -369,7 +369,7 @@ function smallCluster(server) { job: versionTaggedJob, namespace: 'default', version: 2, - taggedVersion: { + versionTag: { Name: 'enchilada', Description: 'A version with just a hint of spice', }, diff --git a/ui/tests/acceptance/job-versions-test.js b/ui/tests/acceptance/job-versions-test.js index 14c6651f570..b16ac6eda88 100644 --- a/ui/tests/acceptance/job-versions-test.js +++ b/ui/tests/acceptance/job-versions-test.js @@ -41,7 +41,7 @@ module('Acceptance | job versions', function (hooks) { server.create('job-version', { job: job, version: 1, - taggedVersion: { + versionTag: { Name: 'test-tag', Description: 'A tag with a brief description', },