-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update events configured to watch only specific fields
- Loading branch information
1 parent
d8f10a6
commit 329a7d8
Showing
9 changed files
with
228 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,29 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/infracloudio/botkube/pkg/config" | ||
) | ||
|
||
// SpecDiffReporter is a simple custom reporter that only records differences | ||
// detected in Object Spec during comparison. | ||
type SpecDiffReporter struct { | ||
path cmp.Path | ||
diffs []string | ||
} | ||
|
||
// PushStep custom implements Reporter interface | ||
func (r *SpecDiffReporter) PushStep(ps cmp.PathStep) { | ||
r.path = append(r.path, ps) | ||
} | ||
|
||
// Report custom implements Reporter interface | ||
func (r *SpecDiffReporter) Report(rs cmp.Result) { | ||
if !rs.Equal() { | ||
vx, vy := r.path.Last().Values() | ||
path := fmt.Sprintf("%#v", r.path) | ||
if ok := strings.Contains(path, ".Spec."); ok { | ||
r.diffs = append(r.diffs, fmt.Sprintf("%#v:\n\t-: %+v\n\t+: %+v\n", r.path, vx, vy)) | ||
// Diff provides differences between two objects spec | ||
func Diff(x, y interface{}, updatesetting config.UpdateSetting) string { | ||
msg := "" | ||
for _, val := range updatesetting.Fields { | ||
if val == config.SpecUpdate { | ||
var r SpecDiffReporter | ||
cmp.Equal(x, y, cmp.Reporter(&r)) | ||
msg = msg + r.String() | ||
} | ||
if val == config.MetadataUpdate { | ||
var r MetadataDiffReporter | ||
cmp.Equal(x, y, cmp.Reporter(&r)) | ||
msg = msg + r.String() | ||
} | ||
if val == config.StatusUpdate { | ||
var r StatusDiffReporter | ||
cmp.Equal(x, y, cmp.Reporter(&r)) | ||
msg = msg + r.String() | ||
} | ||
} | ||
} | ||
|
||
// PopStep custom implements Reporter interface | ||
func (r *SpecDiffReporter) PopStep() { | ||
r.path = r.path[:len(r.path)-1] | ||
} | ||
|
||
// String custom implements Reporter interface | ||
func (r *SpecDiffReporter) String() string { | ||
return strings.Join(r.diffs, "\n") | ||
} | ||
|
||
// Diff provides differences between two objects spec | ||
func Diff(x, y interface{}) string { | ||
var r SpecDiffReporter | ||
cmp.Equal(x, y, cmp.Reporter(&r)) | ||
return r.String() | ||
return msg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
// MetadataDiffReporter is a simple custom reporter that only records differences | ||
// detected in Object Spec during comparison. | ||
type MetadataDiffReporter struct { | ||
path cmp.Path | ||
diffs []string | ||
} | ||
|
||
// PushStep custom implements Reporter interface | ||
func (r *MetadataDiffReporter) PushStep(ps cmp.PathStep) { | ||
r.path = append(r.path, ps) | ||
} | ||
|
||
// Report custom implements Reporter interface | ||
func (r *MetadataDiffReporter) Report(rs cmp.Result) { | ||
if !rs.Equal() { | ||
vx, vy := r.path.Last().Values() | ||
path := fmt.Sprintf("%#v", r.path) | ||
if ok := strings.Contains(path, ".Metadata."); ok { | ||
r.diffs = append(r.diffs, fmt.Sprintf("%#v:\n\t-: %+v\n\t+: %+v\n", r.path, vx, vy)) | ||
} | ||
} | ||
} | ||
|
||
// PopStep custom implements Reporter interface | ||
func (r *MetadataDiffReporter) PopStep() { | ||
r.path = r.path[:len(r.path)-1] | ||
} | ||
|
||
// String custom implements Reporter interface | ||
func (r *MetadataDiffReporter) String() string { | ||
return strings.Join(r.diffs, "\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
// SpecDiffReporter is a simple custom reporter that only records differences | ||
// detected in Object Spec during comparison. | ||
type SpecDiffReporter struct { | ||
path cmp.Path | ||
diffs []string | ||
} | ||
|
||
// PushStep custom implements Reporter interface | ||
func (r *SpecDiffReporter) PushStep(ps cmp.PathStep) { | ||
r.path = append(r.path, ps) | ||
} | ||
|
||
// Report custom implements Reporter interface | ||
func (r *SpecDiffReporter) Report(rs cmp.Result) { | ||
if !rs.Equal() { | ||
vx, vy := r.path.Last().Values() | ||
path := fmt.Sprintf("%#v", r.path) | ||
if ok := strings.Contains(path, ".Spec."); ok { | ||
r.diffs = append(r.diffs, fmt.Sprintf("%#v:\n\t-: %+v\n\t+: %+v\n", r.path, vx, vy)) | ||
} | ||
} | ||
} | ||
|
||
// PopStep custom implements Reporter interface | ||
func (r *SpecDiffReporter) PopStep() { | ||
r.path = r.path[:len(r.path)-1] | ||
} | ||
|
||
// String custom implements Reporter interface | ||
func (r *SpecDiffReporter) String() string { | ||
return strings.Join(r.diffs, "\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
// StatusDiffReporter is a simple custom reporter that only records differences | ||
// detected in Object Spec during comparison. | ||
type StatusDiffReporter struct { | ||
path cmp.Path | ||
diffs []string | ||
} | ||
|
||
// PushStep custom implements Reporter interface | ||
func (r *StatusDiffReporter) PushStep(ps cmp.PathStep) { | ||
r.path = append(r.path, ps) | ||
} | ||
|
||
// Report custom implements Reporter interface | ||
func (r *StatusDiffReporter) Report(rs cmp.Result) { | ||
if !rs.Equal() { | ||
vx, vy := r.path.Last().Values() | ||
path := fmt.Sprintf("%#v", r.path) | ||
if ok := strings.Contains(path, ".Status."); ok { | ||
r.diffs = append(r.diffs, fmt.Sprintf("%#v:\n\t-: %+v\n\t+: %+v\n", r.path, vx, vy)) | ||
} | ||
} | ||
} | ||
|
||
// PopStep custom implements Reporter interface | ||
func (r *StatusDiffReporter) PopStep() { | ||
r.path = r.path[:len(r.path)-1] | ||
} | ||
|
||
// String custom implements Reporter interface | ||
func (r *StatusDiffReporter) String() string { | ||
return strings.Join(r.diffs, "\n") | ||
} |
Oops, something went wrong.