-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This Commit, - enhances update event notifications with details of what Spec is getting changed - adds custom `SpecDiffReporter` and `utils.Diff()` method. - adds update events in all config.yaml files - adds unit-test for utils.Diff() - adds update events for Deployment, Statefulset and Job by default.
- Loading branch information
Showing
11 changed files
with
188 additions
and
77 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
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
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,48 @@ | ||
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") | ||
} | ||
|
||
// 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() | ||
} |
Oops, something went wrong.