mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
api: add DefaultUpdateStrategy to system jobs if missing (#26777)
From 1.11, Nomad system jobs will feature deployments, and thus jobspecs missing an update block should be canonicalized to have one.
This commit is contained in:
committed by
GitHub
parent
3ef25e5867
commit
f42239bf6c
@@ -1227,7 +1227,7 @@ func (j *Job) Canonicalize() {
|
||||
}
|
||||
if j.Update != nil {
|
||||
j.Update.Canonicalize()
|
||||
} else if *j.Type == JobTypeService {
|
||||
} else if *j.Type == JobTypeService || *j.Type == JobTypeSystem {
|
||||
j.Update = DefaultUpdateStrategy()
|
||||
}
|
||||
if j.Multiregion != nil {
|
||||
|
||||
@@ -999,6 +999,70 @@ func TestJobs_Canonicalize(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing update for system job",
|
||||
input: &Job{
|
||||
Name: pointerOf("foo"),
|
||||
ID: pointerOf("bar"),
|
||||
ParentID: pointerOf("lol"),
|
||||
Type: pointerOf(JobTypeSystem),
|
||||
TaskGroups: []*TaskGroup{
|
||||
{
|
||||
Name: pointerOf("bar"),
|
||||
Tasks: []*Task{
|
||||
{
|
||||
Name: "task1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &Job{
|
||||
Namespace: pointerOf(DefaultNamespace),
|
||||
ID: pointerOf("bar"),
|
||||
ParentID: pointerOf("lol"),
|
||||
Name: pointerOf("foo"),
|
||||
Region: pointerOf("global"),
|
||||
Type: pointerOf(JobTypeSystem),
|
||||
Priority: pointerOf(JobDefaultPriority),
|
||||
NodePool: pointerOf(""),
|
||||
AllAtOnce: pointerOf(false),
|
||||
ConsulNamespace: pointerOf(""),
|
||||
VaultNamespace: pointerOf(""),
|
||||
NomadTokenID: pointerOf(""),
|
||||
Stop: pointerOf(false),
|
||||
Stable: pointerOf(false),
|
||||
Version: pointerOf(uint64(0)),
|
||||
Status: pointerOf(""),
|
||||
StatusDescription: pointerOf(""),
|
||||
CreateIndex: pointerOf(uint64(0)),
|
||||
ModifyIndex: pointerOf(uint64(0)),
|
||||
JobModifyIndex: pointerOf(uint64(0)),
|
||||
Update: DefaultUpdateStrategy(),
|
||||
TaskGroups: []*TaskGroup{
|
||||
{
|
||||
Name: pointerOf("bar"),
|
||||
Count: pointerOf(1),
|
||||
RestartPolicy: defaultServiceJobRestartPolicy(),
|
||||
EphemeralDisk: &EphemeralDisk{
|
||||
Sticky: pointerOf(false),
|
||||
Migrate: pointerOf(false),
|
||||
SizeMB: pointerOf(300),
|
||||
},
|
||||
Update: DefaultUpdateStrategy(),
|
||||
Tasks: []*Task{
|
||||
{
|
||||
Name: "task1",
|
||||
LogConfig: DefaultLogConfig(),
|
||||
Resources: DefaultResources(),
|
||||
KillTimeout: pointerOf(5 * time.Second),
|
||||
RestartPolicy: defaultServiceJobRestartPolicy(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "restart_merge",
|
||||
input: &Job{
|
||||
|
||||
@@ -3582,7 +3582,7 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
|
||||
|
||||
structsJob := ApiJobToStructJob(apiJob)
|
||||
|
||||
require.Equal(t, expected, structsJob)
|
||||
must.Eq(t, expected, structsJob)
|
||||
|
||||
systemAPIJob := &api.Job{
|
||||
Stop: pointer.Of(true),
|
||||
@@ -3725,6 +3725,10 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
|
||||
Operand: "c",
|
||||
},
|
||||
},
|
||||
Update: structs.UpdateStrategy{
|
||||
Stagger: 30 * time.Second,
|
||||
MaxParallel: 1,
|
||||
},
|
||||
TaskGroups: []*structs.TaskGroup{
|
||||
{
|
||||
Name: "group1",
|
||||
@@ -3743,6 +3747,17 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
|
||||
Mode: "delay",
|
||||
RenderTemplates: false,
|
||||
},
|
||||
Update: &structs.UpdateStrategy{
|
||||
Stagger: 30 * time.Second,
|
||||
MaxParallel: 1,
|
||||
HealthCheck: structs.UpdateStrategyHealthCheck_Checks,
|
||||
MinHealthyTime: 10 * time.Second,
|
||||
HealthyDeadline: 5 * time.Minute,
|
||||
ProgressDeadline: 10 * time.Minute,
|
||||
AutoRevert: false,
|
||||
AutoPromote: false,
|
||||
Canary: 0,
|
||||
},
|
||||
EphemeralDisk: &structs.EphemeralDisk{
|
||||
SizeMB: 100,
|
||||
Sticky: true,
|
||||
@@ -3832,7 +3847,7 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
|
||||
}
|
||||
|
||||
systemStructsJob := ApiJobToStructJob(systemAPIJob)
|
||||
require.Equal(t, expectedSystemJob, systemStructsJob)
|
||||
must.Eq(t, expectedSystemJob, systemStructsJob)
|
||||
}
|
||||
|
||||
func TestJobs_ApiJobToStructsJobUpdate(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user