Skip to content

Commit

Permalink
shadowing 'new' is meh
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Feb 4, 2021
1 parent dd6367f commit 9c1a431
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions nomad/structs/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -1566,22 +1566,22 @@ Loop:

// volumeDiffs returns the diff of a group's volume requests. If contextual
// diff is enabled, all fields will be returned, even if no diff occurred.
func volumeDiffs(old, new map[string]*VolumeRequest, contextual bool) []*ObjectDiff {
if reflect.DeepEqual(old, new) {
func volumeDiffs(oldVR, newVR map[string]*VolumeRequest, contextual bool) []*ObjectDiff {
if reflect.DeepEqual(oldVR, newVR) {
return nil
}

diffs := []*ObjectDiff{} //Type: DiffTypeNone, Name: "Volumes"}
seen := map[string]bool{}
for name, oReq := range old {
nReq := new[name] // might be nil, that's ok
for name, oReq := range oldVR {
nReq := newVR[name] // might be nil, that's ok
seen[name] = true
diff := volumeDiff(oReq, nReq, contextual)
if diff != nil {
diffs = append(diffs, diff)
}
}
for name, nReq := range new {
for name, nReq := range newVR {
if !seen[name] {
// we know old is nil at this point, or we'd have hit it before
diff := volumeDiff(nil, nReq, contextual)
Expand All @@ -1595,31 +1595,31 @@ func volumeDiffs(old, new map[string]*VolumeRequest, contextual bool) []*ObjectD

// volumeDiff returns the diff between two volume requests. If contextual diff
// is enabled, all fields will be returned, even if no diff occurred.
func volumeDiff(old, new *VolumeRequest, contextual bool) *ObjectDiff {
if reflect.DeepEqual(old, new) {
func volumeDiff(oldVR, newVR *VolumeRequest, contextual bool) *ObjectDiff {
if reflect.DeepEqual(oldVR, newVR) {
return nil
}

diff := &ObjectDiff{Type: DiffTypeNone, Name: "Volume"}
var oldPrimitiveFlat, newPrimitiveFlat map[string]string

if old == nil {
old = &VolumeRequest{}
if oldVR == nil {
oldVR = &VolumeRequest{}
diff.Type = DiffTypeAdded
newPrimitiveFlat = flatmap.Flatten(new, nil, true)
} else if new == nil {
new = &VolumeRequest{}
newPrimitiveFlat = flatmap.Flatten(newVR, nil, true)
} else if newVR == nil {
newVR = &VolumeRequest{}
diff.Type = DiffTypeDeleted
oldPrimitiveFlat = flatmap.Flatten(old, nil, true)
oldPrimitiveFlat = flatmap.Flatten(oldVR, nil, true)
} else {
diff.Type = DiffTypeEdited
oldPrimitiveFlat = flatmap.Flatten(old, nil, true)
newPrimitiveFlat = flatmap.Flatten(new, nil, true)
oldPrimitiveFlat = flatmap.Flatten(oldVR, nil, true)
newPrimitiveFlat = flatmap.Flatten(newVR, nil, true)
}

diff.Fields = fieldDiffs(oldPrimitiveFlat, newPrimitiveFlat, contextual)

mOptsDiff := volumeCSIMountOptionsDiff(old.MountOptions, new.MountOptions, contextual)
mOptsDiff := volumeCSIMountOptionsDiff(oldVR.MountOptions, newVR.MountOptions, contextual)
if mOptsDiff != nil {
diff.Objects = append(diff.Objects, mOptsDiff)
}
Expand All @@ -1630,31 +1630,31 @@ func volumeDiff(old, new *VolumeRequest, contextual bool) *ObjectDiff {
// volumeCSIMountOptionsDiff returns the diff between volume mount options. If
// contextual diff is enabled, all fields will be returned, even if no diff
// occurred.
func volumeCSIMountOptionsDiff(old, new *CSIMountOptions, contextual bool) *ObjectDiff {
if reflect.DeepEqual(old, new) {
func volumeCSIMountOptionsDiff(oldMO, newMO *CSIMountOptions, contextual bool) *ObjectDiff {
if reflect.DeepEqual(oldMO, newMO) {
return nil
}

diff := &ObjectDiff{Type: DiffTypeNone, Name: "MountOptions"}
var oldPrimitiveFlat, newPrimitiveFlat map[string]string

if old == nil && new != nil {
old = &CSIMountOptions{}
if oldMO == nil && newMO != nil {
oldMO = &CSIMountOptions{}
diff.Type = DiffTypeAdded
newPrimitiveFlat = flatmap.Flatten(new, nil, true)
} else if old == nil && new != nil {
new = &CSIMountOptions{}
newPrimitiveFlat = flatmap.Flatten(newMO, nil, true)
} else if oldMO == nil && newMO != nil {
newMO = &CSIMountOptions{}
diff.Type = DiffTypeDeleted
oldPrimitiveFlat = flatmap.Flatten(old, nil, true)
oldPrimitiveFlat = flatmap.Flatten(oldMO, nil, true)
} else {
diff.Type = DiffTypeEdited
oldPrimitiveFlat = flatmap.Flatten(old, nil, true)
newPrimitiveFlat = flatmap.Flatten(new, nil, true)
oldPrimitiveFlat = flatmap.Flatten(oldMO, nil, true)
newPrimitiveFlat = flatmap.Flatten(newMO, nil, true)
}

diff.Fields = fieldDiffs(oldPrimitiveFlat, newPrimitiveFlat, contextual)

setDiff := stringSetDiff(old.MountFlags, new.MountFlags, "MountFlags", contextual)
setDiff := stringSetDiff(oldMO.MountFlags, newMO.MountFlags, "MountFlags", contextual)
if setDiff != nil {
diff.Objects = append(diff.Objects, setDiff)
}
Expand Down

0 comments on commit 9c1a431

Please sign in to comment.