diff --git a/cmd/common.go b/cmd/common.go index 1a0e80f14..8788e914a 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -146,9 +146,12 @@ func syncMain(ctx context.Context, filenames []string, dry bool, parallelism, jsonOutput.Errors = []string{} jsonOutput.Warnings = []string{} jsonOutput.Changes = diff.EntityChanges{ - Creating: []diff.EntityState{}, - Updating: []diff.EntityState{}, - Deleting: []diff.EntityState{}, + Creating: []diff.EntityState{}, + Updating: []diff.EntityState{}, + Deleting: []diff.EntityState{}, + DroppedCreations: []diff.EntityState{}, + DroppedUpdates: []diff.EntityState{}, + DroppedDeletions: []diff.EntityState{}, } } targetContent, err := file.GetContentFromFiles(filenames, false) @@ -691,20 +694,18 @@ func performDiff(ctx context.Context, currentState, targetState *state.KongState } stats, errs, changes := s.Solve(ctx, parallelism, dry, enableJSONOutput) + totalOps := stats.CreateOps.Count() + stats.UpdateOps.Count() + stats.DeleteOps.Count() // print stats before error to report completed operations if !enableJSONOutput { printStats(stats) - } - if errs != nil { - return 0, reconcilerUtils.ErrArray{Errors: errs} - } - totalOps := stats.CreateOps.Count() + stats.UpdateOps.Count() + stats.DeleteOps.Count() - - if enableJSONOutput { + } else { jsonOutput.Changes = diff.EntityChanges{ - Creating: append(jsonOutput.Changes.Creating, changes.Creating...), - Updating: append(jsonOutput.Changes.Updating, changes.Updating...), - Deleting: append(jsonOutput.Changes.Deleting, changes.Deleting...), + Creating: append(jsonOutput.Changes.Creating, changes.Creating...), + Updating: append(jsonOutput.Changes.Updating, changes.Updating...), + Deleting: append(jsonOutput.Changes.Deleting, changes.Deleting...), + DroppedCreations: append(jsonOutput.Changes.DroppedCreations, changes.DroppedCreations...), + DroppedUpdates: append(jsonOutput.Changes.DroppedUpdates, changes.DroppedUpdates...), + DroppedDeletions: append(jsonOutput.Changes.DroppedDeletions, changes.DroppedDeletions...), } jsonOutput.Summary = diff.Summary{ Creating: stats.CreateOps.Count(), @@ -713,6 +714,10 @@ func performDiff(ctx context.Context, currentState, targetState *state.KongState Total: totalOps, } } + if errs != nil { + return 0, reconcilerUtils.ErrArray{Errors: errs} + } + return int(totalOps), nil } diff --git a/go.mod b/go.mod index 87db2f47a..90d9bf87d 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/fatih/color v1.18.0 github.com/google/go-cmp v0.7.0 github.com/kong/go-apiops v0.2.1 - github.com/kong/go-database-reconciler v1.31.0 + github.com/kong/go-database-reconciler v1.31.1-0.20251222062637-7b26eddcaf74 github.com/kong/go-kong v0.71.0 github.com/mitchellh/go-homedir v1.1.0 github.com/spf13/cobra v1.9.1 diff --git a/go.sum b/go.sum index 8f44a6c2c..06af2fcfe 100644 --- a/go.sum +++ b/go.sum @@ -244,8 +244,8 @@ github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/q github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kong/go-apiops v0.2.1 h1:6HtyQyOj+CLA86iRtXA6rpTqemp7VqJJ6gpHyNHdB7o= github.com/kong/go-apiops v0.2.1/go.mod h1:yPwbl3P2eQinVGAEA0d3legaYmzPJ+WtJf9fSeGF4b8= -github.com/kong/go-database-reconciler v1.31.0 h1:LITt0L/EhajVaSNDMj/TOxh4Cst7CRhiTykYMMlOoLk= -github.com/kong/go-database-reconciler v1.31.0/go.mod h1:kw4+JGF6iv70LcLBmuY2UuMr8KSdqop77IR86B1mYvU= +github.com/kong/go-database-reconciler v1.31.1-0.20251222062637-7b26eddcaf74 h1:CZH3uu/dNY3U53w/LycO03pt+ekR6YqznkWgdjkjzeo= +github.com/kong/go-database-reconciler v1.31.1-0.20251222062637-7b26eddcaf74/go.mod h1:kw4+JGF6iv70LcLBmuY2UuMr8KSdqop77IR86B1mYvU= github.com/kong/go-kong v0.71.0 h1:unPik6osV1DD3DF+jLs9oMedxWQsnepPYTm1dRQSIa4= github.com/kong/go-kong v0.71.0/go.mod h1:J0vGB3wsZ2i99zly1zTRe3v7rOKpkhQZRwbcTFP76qM= github.com/kong/go-slugify v1.0.0 h1:vCFAyf2sdoSlBtLcrmDWUFn0ohlpKiKvQfXZkO5vSKY=