Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ func Command() *cobra.Command { //nolint:funlen
nil,
"exclude resources by substring contents")

// Define --diff flag.
mf.StringErrorMatcher(matcher.NewDiffMatcher,
"diff",
"",
"include resources which differ from those in a file")

// Define --not-diff flag.
mf.StringErrorMatcher(matcher.NewDiffMatcher,
"not-diff",
"",
"exclude resources which differ from those in a file")

// Define --exec flag.
mf.StringErrorMatcher(matcher.NewExecMatcher,
"exec",
Expand Down
12 changes: 8 additions & 4 deletions matcher/matcher-diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ type diffMatcher struct {
func (m diffMatcher) Matches(item resources.Resource) bool {
for _, original := range m.originals {
switch {
// Check if the resource under investigation is the counterpart of any original resources.
// Check if the resource under investigation is the counterpart of any
// original resources.
case item.GetAPIVersion() != original.GetAPIVersion():
continue
case item.GetKind() != original.GetKind():
Expand All @@ -46,11 +47,14 @@ func (m diffMatcher) Matches(item resources.Resource) bool {
continue
case item.GetNamespace() != original.GetNamespace():
continue
// Diff the resource under investigation against its original counterpart.
case cmp.Equal(item.Object, original.Object):
return false
}

// Diff the resource under investigation against its original
// counterpart.
return !cmp.Equal(item.Object, original.Object)
}

// The resource under investigation did not have an original counterpart,
// and has therefore differed.
return true
}
1 change: 1 addition & 0 deletions matcher/matcher-diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestDiffMatcher(t *testing.T) {
title: "diff resources",
matcher: must(matcher.NewDiffMatcher("testdata/resources.txt")),
matches: []string{
"ConfigMap/my-configmap",
"Deployment/nginx-deployment",
"Pod/test-pod",
},
Expand Down
2 changes: 1 addition & 1 deletion matcher/testdata/resources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ metadata:
labels:
app.kubernetes.io/component: auth
name: my-configmap
namespace: custom-app
namespace: custom-app-other # <------------------------------- changed value