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: 6 additions & 6 deletions pkg/app/piped/cloudprovider/kubernetes/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,22 @@ func groupManifests(olds, news []Manifest) (adds, deletes, newChanges, oldChange
o++
continue
}
// Has in new but not in old so this should be a deleted one.
// Has in news but not in olds so this should be a added one.
if news[n].Key.IsLessWithIgnoringNamespace(olds[o].Key) {
deletes = append(deletes, news[n])
adds = append(adds, news[n])
n++
continue
}
// Has in old but not in new so this should be an added one.
adds = append(adds, olds[o])
// Has in olds but not in news so this should be an deleted one.
deletes = append(deletes, olds[o])
o++
}

if len(news) > n {
deletes = append(deletes, news[n:]...)
adds = append(adds, news[n:]...)
}
if len(olds) > o {
adds = append(adds, olds[o:]...)
deletes = append(deletes, olds[o:]...)
}
return
}
14 changes: 7 additions & 7 deletions pkg/app/piped/cloudprovider/kubernetes/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
func TestGroupManifests(t *testing.T) {
testcases := []struct {
name string
news []Manifest
olds []Manifest
news []Manifest
expectedAdds []Manifest
expectedDeletes []Manifest
expectedNewChanges []Manifest
Expand All @@ -35,7 +35,7 @@ func TestGroupManifests(t *testing.T) {
},
{
name: "only adds",
olds: []Manifest{
news: []Manifest{
{Key: ResourceKey{Name: "b"}},
{Key: ResourceKey{Name: "a"}},
},
Expand All @@ -46,7 +46,7 @@ func TestGroupManifests(t *testing.T) {
},
{
name: "only deletes",
news: []Manifest{
olds: []Manifest{
{Key: ResourceKey{Name: "b"}},
{Key: ResourceKey{Name: "a"}},
},
Expand All @@ -57,11 +57,11 @@ func TestGroupManifests(t *testing.T) {
},
{
name: "only inters",
news: []Manifest{
olds: []Manifest{
{Key: ResourceKey{Name: "b"}},
{Key: ResourceKey{Name: "a"}},
},
olds: []Manifest{
news: []Manifest{
{Key: ResourceKey{Name: "a"}},
{Key: ResourceKey{Name: "b"}},
},
Expand All @@ -76,12 +76,12 @@ func TestGroupManifests(t *testing.T) {
},
{
name: "all kinds",
news: []Manifest{
olds: []Manifest{
{Key: ResourceKey{Name: "b"}},
{Key: ResourceKey{Name: "a"}},
{Key: ResourceKey{Name: "c"}},
},
olds: []Manifest{
news: []Manifest{
{Key: ResourceKey{Name: "a"}},
{Key: ResourceKey{Name: "d"}},
{Key: ResourceKey{Name: "b"}},
Expand Down
8 changes: 5 additions & 3 deletions pkg/app/piped/driftdetector/kubernetes/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ func (d *detector) checkApplication(ctx context.Context, app *model.Application,
liveManifests = filterIgnoringManifests(liveManifests)
d.logger.Info(fmt.Sprintf("application %s has %d live manifests", app.Id, len(liveManifests)))

result, err := provider.DiffList(liveManifests, headManifests,
result, err := provider.DiffList(
headManifests,
liveManifests,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug was caused by this order change in the last refactoring.

diff.WithEquateEmpty(),
diff.WithIgnoreAddingMapKeys(),
diff.WithCompareNumberAndNumericString(),
Expand Down Expand Up @@ -360,8 +362,8 @@ func makeSyncState(r *provider.DiffListResult, commit string) model.ApplicationS
}

var b strings.Builder
b.WriteString(fmt.Sprintf("Diff between the running resources and the definitions in Git at commit %q:\n", commit))
b.WriteString("--- Git\n+++ Cluster\n\n")
b.WriteString(fmt.Sprintf("Diff between the defined state in Git at commit %s and actual state in cluster:\n\n", commit))
b.WriteString("--- Expected\n+++ Actual\n\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier to understand!

b.WriteString(r.DiffString())

return model.ApplicationSyncState{
Expand Down
5 changes: 3 additions & 2 deletions pkg/app/piped/planpreview/kubernetesdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ func (b *builder) kubernetesDiff(
}
}

result, err := provider.DiffList(oldManifests, newManifests,
result, err := provider.DiffList(
oldManifests,
newManifests,
diff.WithEquateEmpty(),
diff.WithIgnoreAddingMapKeys(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this option because plan-preview is comparing between 2 commits, not using the live state.

diff.WithCompareNumberAndNumericString(),
)
if err != nil {
Expand Down