diff --git a/nomad/structs/diff.go b/nomad/structs/diff.go index 0c2d943c7..1d057b824 100644 --- a/nomad/structs/diff.go +++ b/nomad/structs/diff.go @@ -98,7 +98,7 @@ func (j *Job) Diff(other *Job, contextual bool) (*JobDiff, error) { diff.Fields = fieldDiffs(oldPrimitiveFlat, newPrimitiveFlat, false) // Datacenters diff - if setDiff := stringSetDiff(j.Datacenters, other.Datacenters, "Datacenters", false); setDiff != nil { + if setDiff := stringSetDiff(j.Datacenters, other.Datacenters, "Datacenters", contextual); setDiff != nil && setDiff.Type != DiffTypeNone { diff.Objects = append(diff.Objects, setDiff) } diff --git a/nomad/structs/diff_test.go b/nomad/structs/diff_test.go index 10c589e31..1b8f7a946 100644 --- a/nomad/structs/diff_test.go +++ b/nomad/structs/diff_test.go @@ -397,7 +397,7 @@ func TestJobDiff(t *testing.T) { }, }, { - // Datacenter contextual + // Datacenter contextual no change Contextual: true, Old: &Job{ Datacenters: []string{"foo", "bar"}, @@ -409,6 +409,45 @@ func TestJobDiff(t *testing.T) { Type: DiffTypeNone, }, }, + { + // Datacenter contextual + Contextual: true, + Old: &Job{ + Datacenters: []string{"foo", "bar"}, + }, + New: &Job{ + Datacenters: []string{"foo", "bar", "baz"}, + }, + Expected: &JobDiff{ + Type: DiffTypeEdited, + Objects: []*ObjectDiff{ + { + Type: DiffTypeAdded, + Name: "Datacenters", + Fields: []*FieldDiff{ + { + Type: DiffTypeAdded, + Name: "Datacenters", + Old: "", + New: "baz", + }, + { + Type: DiffTypeNone, + Name: "Datacenters", + Old: "bar", + New: "bar", + }, + { + Type: DiffTypeNone, + Name: "Datacenters", + Old: "foo", + New: "foo", + }, + }, + }, + }, + }, + }, { // Update strategy edited Old: &Job{