Skip to content

Commit

Permalink
fix swapped old/new multiregion plan diffs (#8378)
Browse files Browse the repository at this point in the history
The multiregion plan diffs swap the old and new versions for each region when
they're edited (rather than added/removed). The `multiregionRegionDiff`
function call incorrectly reversed its arguments for existing regions.
  • Loading branch information
tgross authored Jul 8, 2020
1 parent 37d6db6 commit a7d7992
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nomad/structs/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ func multiregionDiff(old, new *Multiregion, contextual bool) *ObjectDiff {
for name, oldRegion := range oldMap {
// Diff the same, deleted and edited
newRegion := newMap[name]
rdiff := multiregionRegionDiff(newRegion, oldRegion, contextual)
rdiff := multiregionRegionDiff(oldRegion, newRegion, contextual)
if rdiff != nil {
diff.Objects = append(diff.Objects, rdiff)
}
Expand Down
37 changes: 34 additions & 3 deletions nomad/structs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,8 @@ func TestJobDiff(t *testing.T) {
Regions: []*MultiregionRegion{
{
Name: "west",
Count: 1,
Datacenters: []string{"west-1"},
Count: 3,
Datacenters: []string{"west-2"},
Meta: map[string]string{"region_code": "W"},
},
{
Expand All @@ -1223,14 +1223,45 @@ func TestJobDiff(t *testing.T) {
},
},
},

Expected: &JobDiff{
Type: DiffTypeEdited,
Objects: []*ObjectDiff{
{
Type: DiffTypeEdited,
Name: "Multiregion",
Objects: []*ObjectDiff{
{
Type: DiffTypeEdited,
Name: "Region",
Fields: []*FieldDiff{
{
Type: DiffTypeEdited,
Name: "Count",
Old: "1",
New: "3",
},
},
Objects: []*ObjectDiff{
{
Type: DiffTypeEdited,
Name: "Datacenters",
Fields: []*FieldDiff{
{
Type: DiffTypeAdded,
Name: "Datacenters",
Old: "",
New: "west-2",
},
{
Type: DiffTypeDeleted,
Name: "Datacenters",
Old: "west-1",
New: "",
},
},
},
},
},
{
Type: DiffTypeAdded,
Name: "Region",
Expand Down

0 comments on commit a7d7992

Please sign in to comment.