From 8fc2d792454b9252a066992416ef70f95f0603e4 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Wed, 7 Jul 2021 11:03:20 +0200 Subject: [PATCH 1/2] api: Added `NewSystemJob` job creation helper function. --- api/jobs.go | 7 +++++++ api/jobs_test.go | 15 +++++++++++++++ vendor/github.com/hashicorp/nomad/api/jobs.go | 7 +++++++ 3 files changed, 29 insertions(+) diff --git a/api/jobs.go b/api/jobs.go index 1fed52c7ca3..416fce1fa57 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -1035,6 +1035,13 @@ func NewBatchJob(id, name, region string, pri int) *Job { return newJob(id, name, region, JobTypeBatch, pri) } +// NewSystemJob creates and returns a new system-style job for processes +// designed to run on all clients, using the provided name and ID along with +// the relative job priority. +func NewSystemJob(id, name, region string, pri int) *Job { + return newJob(id, name, region, JobTypeSystem, pri) +} + // newJob is used to create a new Job struct. func newJob(id, name, region, typ string, pri int) *Job { return &Job{ diff --git a/api/jobs_test.go b/api/jobs_test.go index 250f33717d5..56ecaa20fbe 100644 --- a/api/jobs_test.go +++ b/api/jobs_test.go @@ -1861,6 +1861,21 @@ func TestJobs_NewServiceJob(t *testing.T) { } } +func TestJobs_NewSystemJob(t *testing.T) { + t.Parallel() + job := NewSystemJob("job1", "myjob", "global", 5) + expect := &Job{ + Region: stringToPtr("global"), + ID: stringToPtr("job1"), + Name: stringToPtr("myjob"), + Type: stringToPtr(JobTypeSystem), + Priority: intToPtr(5), + } + if !reflect.DeepEqual(job, expect) { + t.Fatalf("expect: %#v, got: %#v", expect, job) + } +} + func TestJobs_SetMeta(t *testing.T) { t.Parallel() job := &Job{Meta: nil} diff --git a/vendor/github.com/hashicorp/nomad/api/jobs.go b/vendor/github.com/hashicorp/nomad/api/jobs.go index 1fed52c7ca3..416fce1fa57 100644 --- a/vendor/github.com/hashicorp/nomad/api/jobs.go +++ b/vendor/github.com/hashicorp/nomad/api/jobs.go @@ -1035,6 +1035,13 @@ func NewBatchJob(id, name, region string, pri int) *Job { return newJob(id, name, region, JobTypeBatch, pri) } +// NewSystemJob creates and returns a new system-style job for processes +// designed to run on all clients, using the provided name and ID along with +// the relative job priority. +func NewSystemJob(id, name, region string, pri int) *Job { + return newJob(id, name, region, JobTypeSystem, pri) +} + // newJob is used to create a new Job struct. func newJob(id, name, region, typ string, pri int) *Job { return &Job{ From 01a551faafa211e94becb92a19dd97f7d429595b Mon Sep 17 00:00:00 2001 From: James Rasell Date: Wed, 7 Jul 2021 11:03:39 +0200 Subject: [PATCH 2/2] changelog: add entry for #10861 --- .changelog/10861.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/10861.txt diff --git a/.changelog/10861.txt b/.changelog/10861.txt new file mode 100644 index 00000000000..f55d0bfa806 --- /dev/null +++ b/.changelog/10861.txt @@ -0,0 +1,3 @@ +```release-note:improvement +api: Added `NewSystemJob` helper function to create base system job object. +```