Merge pull request #3298 from hashicorp/b-fix-check-restart-plan
Diff CheckRestart objects
This commit is contained in:
commit
f1a8676ee4
|
@ -598,6 +598,11 @@ func serviceCheckDiff(old, new *ServiceCheck, contextual bool) *ObjectDiff {
|
|||
diff.Objects = append(diff.Objects, headerDiff)
|
||||
}
|
||||
|
||||
// Diff check_restart
|
||||
if crDiff := checkRestartDiff(old.CheckRestart, new.CheckRestart, contextual); crDiff != nil {
|
||||
diff.Objects = append(diff.Objects, crDiff)
|
||||
}
|
||||
|
||||
return diff
|
||||
}
|
||||
|
||||
|
@ -606,17 +611,48 @@ func serviceCheckDiff(old, new *ServiceCheck, contextual bool) *ObjectDiff {
|
|||
// occurred.
|
||||
func checkHeaderDiff(old, new map[string][]string, contextual bool) *ObjectDiff {
|
||||
diff := &ObjectDiff{Type: DiffTypeNone, Name: "Header"}
|
||||
var oldFlat, newFlat map[string]string
|
||||
|
||||
if reflect.DeepEqual(old, new) {
|
||||
return nil
|
||||
} else if len(old) == 0 {
|
||||
diff.Type = DiffTypeAdded
|
||||
newFlat = flatmap.Flatten(new, nil, false)
|
||||
} else if len(new) == 0 {
|
||||
diff.Type = DiffTypeDeleted
|
||||
oldFlat = flatmap.Flatten(old, nil, false)
|
||||
} else {
|
||||
diff.Type = DiffTypeEdited
|
||||
oldFlat = flatmap.Flatten(old, nil, false)
|
||||
newFlat = flatmap.Flatten(new, nil, false)
|
||||
}
|
||||
oldFlat := flatmap.Flatten(old, nil, false)
|
||||
newFlat := flatmap.Flatten(new, nil, false)
|
||||
|
||||
diff.Fields = fieldDiffs(oldFlat, newFlat, contextual)
|
||||
return diff
|
||||
}
|
||||
|
||||
// checkRestartDiff returns the diff of two service check check_restart
|
||||
// objects. If contextual diff is enabled, all fields will be returned, even if
|
||||
// no diff occurred.
|
||||
func checkRestartDiff(old, new *CheckRestart, contextual bool) *ObjectDiff {
|
||||
diff := &ObjectDiff{Type: DiffTypeNone, Name: "CheckRestart"}
|
||||
var oldFlat, newFlat map[string]string
|
||||
|
||||
if reflect.DeepEqual(old, new) {
|
||||
return nil
|
||||
} else if old == nil {
|
||||
diff.Type = DiffTypeAdded
|
||||
newFlat = flatmap.Flatten(new, nil, true)
|
||||
diff.Type = DiffTypeAdded
|
||||
} else if new == nil {
|
||||
diff.Type = DiffTypeDeleted
|
||||
oldFlat = flatmap.Flatten(old, nil, true)
|
||||
} else {
|
||||
diff.Type = DiffTypeEdited
|
||||
oldFlat = flatmap.Flatten(old, nil, true)
|
||||
newFlat = flatmap.Flatten(new, nil, true)
|
||||
}
|
||||
|
||||
diff.Fields = fieldDiffs(oldFlat, newFlat, contextual)
|
||||
return diff
|
||||
}
|
||||
|
|
|
@ -3196,6 +3196,9 @@ func TestTaskDiff(t *testing.T) {
|
|||
Protocol: "http",
|
||||
Interval: 1 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
Header: map[string][]string{
|
||||
"Foo": {"bar"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "bar",
|
||||
|
@ -3245,6 +3248,9 @@ func TestTaskDiff(t *testing.T) {
|
|||
Protocol: "http",
|
||||
Interval: 1 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
Header: map[string][]string{
|
||||
"Eggs": {"spam"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "bam",
|
||||
|
@ -3278,6 +3284,20 @@ func TestTaskDiff(t *testing.T) {
|
|||
New: "tcp",
|
||||
},
|
||||
},
|
||||
Objects: []*ObjectDiff{
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Header",
|
||||
Fields: []*FieldDiff{
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Eggs[0]",
|
||||
Old: "",
|
||||
New: "spam",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
|
@ -3386,6 +3406,19 @@ func TestTaskDiff(t *testing.T) {
|
|||
New: "",
|
||||
},
|
||||
},
|
||||
Objects: []*ObjectDiff{
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "Header",
|
||||
Fields: []*FieldDiff{
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "Foo[0]",
|
||||
Old: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -3573,6 +3606,192 @@ func TestTaskDiff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "CheckRestart edited",
|
||||
Old: &Task{
|
||||
Services: []*Service{
|
||||
{
|
||||
Name: "foo",
|
||||
Checks: []*ServiceCheck{
|
||||
{
|
||||
Name: "foo",
|
||||
Type: "http",
|
||||
Command: "foo",
|
||||
Args: []string{"foo"},
|
||||
Path: "foo",
|
||||
Protocol: "http",
|
||||
Interval: 1 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
},
|
||||
{
|
||||
Name: "bar",
|
||||
Type: "http",
|
||||
Command: "foo",
|
||||
Args: []string{"foo"},
|
||||
Path: "foo",
|
||||
Protocol: "http",
|
||||
Interval: 1 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
CheckRestart: &CheckRestart{
|
||||
Limit: 2,
|
||||
Grace: 2 * time.Second,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "baz",
|
||||
Type: "http",
|
||||
Command: "foo",
|
||||
Args: []string{"foo"},
|
||||
Path: "foo",
|
||||
Protocol: "http",
|
||||
Interval: 1 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
CheckRestart: &CheckRestart{
|
||||
Limit: 3,
|
||||
Grace: 3 * time.Second,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
New: &Task{
|
||||
Services: []*Service{
|
||||
{
|
||||
Name: "foo",
|
||||
Checks: []*ServiceCheck{
|
||||
{
|
||||
Name: "foo",
|
||||
Type: "http",
|
||||
Command: "foo",
|
||||
Args: []string{"foo"},
|
||||
Path: "foo",
|
||||
Protocol: "http",
|
||||
Interval: 1 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
CheckRestart: &CheckRestart{
|
||||
Limit: 1,
|
||||
Grace: 1 * time.Second,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "bar",
|
||||
Type: "http",
|
||||
Command: "foo",
|
||||
Args: []string{"foo"},
|
||||
Path: "foo",
|
||||
Protocol: "http",
|
||||
Interval: 1 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
},
|
||||
{
|
||||
Name: "baz",
|
||||
Type: "http",
|
||||
Command: "foo",
|
||||
Args: []string{"foo"},
|
||||
Path: "foo",
|
||||
Protocol: "http",
|
||||
Interval: 1 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
CheckRestart: &CheckRestart{
|
||||
Limit: 4,
|
||||
Grace: 4 * time.Second,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Expected: &TaskDiff{
|
||||
Type: DiffTypeEdited,
|
||||
Objects: []*ObjectDiff{
|
||||
{
|
||||
Type: DiffTypeEdited,
|
||||
Name: "Service",
|
||||
Objects: []*ObjectDiff{
|
||||
{
|
||||
Type: DiffTypeEdited,
|
||||
Name: "Check",
|
||||
Objects: []*ObjectDiff{
|
||||
{
|
||||
Type: DiffTypeEdited,
|
||||
Name: "CheckRestart",
|
||||
Fields: []*FieldDiff{
|
||||
{
|
||||
Type: DiffTypeEdited,
|
||||
Name: "Grace",
|
||||
Old: "3000000000",
|
||||
New: "4000000000",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeEdited,
|
||||
Name: "Limit",
|
||||
Old: "3",
|
||||
New: "4",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: DiffTypeEdited,
|
||||
Name: "Check",
|
||||
Objects: []*ObjectDiff{
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "CheckRestart",
|
||||
Fields: []*FieldDiff{
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Grace",
|
||||
New: "1000000000",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "IgnoreWarnings",
|
||||
New: "false",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Limit",
|
||||
New: "1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: DiffTypeEdited,
|
||||
Name: "Check",
|
||||
Objects: []*ObjectDiff{
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "CheckRestart",
|
||||
Fields: []*FieldDiff{
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "Grace",
|
||||
Old: "2000000000",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "IgnoreWarnings",
|
||||
Old: "false",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "Limit",
|
||||
Old: "2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Vault added",
|
||||
Old: &Task{},
|
||||
|
|
Loading…
Reference in New Issue