Skip to content

Commit aac15a9

Browse files
authored
Merge branch 'main' into config-upgrade-314
2 parents 5a617dd + ef04ee6 commit aac15a9

File tree

5 files changed

+187
-108
lines changed

5 files changed

+187
-108
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG GO_VERSION=1.25.6
1+
ARG GO_VERSION=1.25.7
22
FROM golang:${GO_VERSION} AS build
33
WORKDIR /deck
44
COPY go.mod ./

cmd/common.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,12 @@ func syncMain(ctx context.Context, filenames []string, dry bool, parallelism,
146146
jsonOutput.Errors = []string{}
147147
jsonOutput.Warnings = []string{}
148148
jsonOutput.Changes = diff.EntityChanges{
149-
Creating: []diff.EntityState{},
150-
Updating: []diff.EntityState{},
151-
Deleting: []diff.EntityState{},
149+
Creating: []diff.EntityState{},
150+
Updating: []diff.EntityState{},
151+
Deleting: []diff.EntityState{},
152+
DroppedCreations: []diff.EntityState{},
153+
DroppedUpdates: []diff.EntityState{},
154+
DroppedDeletions: []diff.EntityState{},
152155
}
153156
}
154157
targetContent, err := file.GetContentFromFiles(filenames, false)
@@ -706,20 +709,18 @@ func performDiff(ctx context.Context, currentState, targetState *state.KongState
706709
}
707710

708711
stats, errs, changes := s.Solve(ctx, parallelism, dry, enableJSONOutput)
712+
totalOps := stats.CreateOps.Count() + stats.UpdateOps.Count() + stats.DeleteOps.Count()
709713
// print stats before error to report completed operations
710714
if !enableJSONOutput {
711715
printStats(stats)
712-
}
713-
if errs != nil {
714-
return 0, reconcilerUtils.ErrArray{Errors: errs}
715-
}
716-
totalOps := stats.CreateOps.Count() + stats.UpdateOps.Count() + stats.DeleteOps.Count()
717-
718-
if enableJSONOutput {
716+
} else {
719717
jsonOutput.Changes = diff.EntityChanges{
720-
Creating: append(jsonOutput.Changes.Creating, changes.Creating...),
721-
Updating: append(jsonOutput.Changes.Updating, changes.Updating...),
722-
Deleting: append(jsonOutput.Changes.Deleting, changes.Deleting...),
718+
Creating: append(jsonOutput.Changes.Creating, changes.Creating...),
719+
Updating: append(jsonOutput.Changes.Updating, changes.Updating...),
720+
Deleting: append(jsonOutput.Changes.Deleting, changes.Deleting...),
721+
DroppedCreations: append(jsonOutput.Changes.DroppedCreations, changes.DroppedCreations...),
722+
DroppedUpdates: append(jsonOutput.Changes.DroppedUpdates, changes.DroppedUpdates...),
723+
DroppedDeletions: append(jsonOutput.Changes.DroppedDeletions, changes.DroppedDeletions...),
723724
}
724725
jsonOutput.Summary = diff.Summary{
725726
Creating: stats.CreateOps.Count(),
@@ -728,6 +729,10 @@ func performDiff(ctx context.Context, currentState, targetState *state.KongState
728729
Total: totalOps,
729730
}
730731
}
732+
if errs != nil {
733+
return 0, reconcilerUtils.ErrArray{Errors: errs}
734+
}
735+
731736
return int(totalOps), nil
732737
}
733738

cmd/common_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package cmd
22

33
import (
4+
"context"
45
"reflect"
56
"testing"
67

8+
"github.com/kong/go-database-reconciler/pkg/diff"
79
"github.com/kong/go-database-reconciler/pkg/dump"
810
"github.com/kong/go-database-reconciler/pkg/file"
11+
"github.com/kong/go-database-reconciler/pkg/state"
12+
"github.com/kong/go-kong/kong"
13+
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
915
)
1016

1117
func TestDetermineSelectorTag(t *testing.T) {
@@ -96,3 +102,64 @@ func TestDetermineSelectorTag(t *testing.T) {
96102
})
97103
}
98104
}
105+
106+
func TestPerformDiff_JSONOutput(t *testing.T) {
107+
// Reset global jsonOutput to a known state
108+
jsonOutput = diff.JSONOutputObject{}
109+
// This is initialized in syncMain() in the actual application,
110+
// but we need to set it up here for testing
111+
jsonOutput.Changes = diff.EntityChanges{
112+
Creating: []diff.EntityState{},
113+
Updating: []diff.EntityState{},
114+
Deleting: []diff.EntityState{},
115+
DroppedCreations: []diff.EntityState{},
116+
DroppedUpdates: []diff.EntityState{},
117+
DroppedDeletions: []diff.EntityState{},
118+
}
119+
120+
currentState, err := state.NewKongState()
121+
require.NoError(t, err)
122+
123+
// mock target state
124+
targetState, err := state.NewKongState()
125+
require.NoError(t, err)
126+
service := state.Service{
127+
Service: kong.Service{
128+
ID: kong.String("service-1"),
129+
Name: kong.String("Service 1"),
130+
},
131+
}
132+
err = targetState.Services.Add(service)
133+
require.NoError(t, err)
134+
135+
// Calling performDiff with dry=true to avoid actual API calls
136+
totalOps, err := performDiff(
137+
context.Background(),
138+
currentState,
139+
targetState,
140+
true, // dry mode
141+
1, // parallelism
142+
0, // delay
143+
nil, // client (not used in dry mode)
144+
false, // isKonnect
145+
true, // enabled Json output
146+
ApplyTypeFull,
147+
)
148+
149+
require.NoError(t, err)
150+
assert.Equal(t, 1, totalOps)
151+
152+
// Verify jsonOutput is populated correctly
153+
assert.Equal(t, int32(1), jsonOutput.Summary.Creating)
154+
assert.Equal(t, int32(0), jsonOutput.Summary.Updating)
155+
assert.Equal(t, int32(0), jsonOutput.Summary.Deleting)
156+
assert.Equal(t, int32(1), jsonOutput.Summary.Total)
157+
158+
// Verify changes are populated
159+
assert.Len(t, jsonOutput.Changes.Creating, 1)
160+
assert.Empty(t, jsonOutput.Changes.Updating)
161+
assert.Empty(t, jsonOutput.Changes.Deleting)
162+
assert.Empty(t, jsonOutput.Changes.DroppedCreations)
163+
assert.Empty(t, jsonOutput.Changes.DroppedUpdates)
164+
assert.Empty(t, jsonOutput.Changes.DroppedDeletions)
165+
}

go.mod

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/kong/deck
22

3-
go 1.25.6
3+
go 1.25.7
44

55
replace github.com/yudai/gojsondiff v1.0.0 => github.com/Kong/gojsondiff v1.3.0
66

@@ -18,17 +18,17 @@ require (
1818
github.com/kong/go-kong v0.72.1
1919
github.com/mitchellh/go-homedir v1.1.0
2020
github.com/spf13/cobra v1.9.1
21-
github.com/spf13/pflag v1.0.6
21+
github.com/spf13/pflag v1.0.9
2222
github.com/spf13/viper v1.20.1
23-
github.com/stretchr/testify v1.10.0
24-
golang.org/x/sync v0.15.0
25-
k8s.io/api v0.33.2
23+
github.com/stretchr/testify v1.11.1
24+
golang.org/x/sync v0.18.0
25+
k8s.io/api v0.35.1
2626
k8s.io/apiextensions-apiserver v0.33.1
27-
k8s.io/apimachinery v0.33.3
28-
k8s.io/client-go v0.33.2
27+
k8s.io/apimachinery v0.35.1
28+
k8s.io/client-go v0.35.1
2929
k8s.io/code-generator v0.33.3
3030
sigs.k8s.io/gateway-api v1.3.0
31-
sigs.k8s.io/yaml v1.5.0
31+
sigs.k8s.io/yaml v1.6.0
3232
)
3333

3434
require (
@@ -45,13 +45,13 @@ require (
4545
github.com/docker/docker v27.1.2+incompatible // indirect
4646
github.com/docker/go-connections v0.5.0 // indirect
4747
github.com/docker/go-units v0.5.0 // indirect
48-
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
48+
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
4949
github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731 // indirect
5050
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
5151
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
5252
github.com/fatih/camelcase v1.0.0 // indirect
5353
github.com/felixge/httpsnoop v1.0.4 // indirect
54-
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
54+
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
5555
github.com/go-errors/errors v1.4.2 // indirect
5656
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
5757
github.com/google/btree v1.1.3 // indirect
@@ -99,21 +99,22 @@ require (
9999
go.opentelemetry.io/otel/metric v1.33.0 // indirect
100100
go.opentelemetry.io/otel/trace v1.33.0 // indirect
101101
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
102-
go.yaml.in/yaml/v2 v2.4.2 // indirect
103-
go.yaml.in/yaml/v3 v3.0.3 // indirect
102+
go.yaml.in/yaml/v2 v2.4.3 // indirect
103+
go.yaml.in/yaml/v3 v3.0.4 // indirect
104104
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
105-
golang.org/x/oauth2 v0.27.0 // indirect
105+
golang.org/x/oauth2 v0.30.0 // indirect
106106
golang.org/x/time v0.9.0 // indirect
107-
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
107+
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
108108
gopkg.in/yaml.v2 v2.4.0 // indirect
109109
k8s.io/cli-runtime v0.31.0 // indirect
110110
k8s.io/component-base v0.33.1 // indirect
111-
k8s.io/gengo/v2 v2.0.0-20250207200755-1244d31929d7 // indirect
111+
k8s.io/gengo/v2 v2.0.0-20250604051438-85fd79dbfd9f // indirect
112112
k8s.io/kubectl v0.31.0 // indirect
113113
sigs.k8s.io/kind v0.24.0 // indirect
114114
sigs.k8s.io/kustomize/api v0.17.3 // indirect
115115
sigs.k8s.io/kustomize/kyaml v0.17.2 // indirect
116116
sigs.k8s.io/randfill v1.0.0 // indirect
117+
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
117118
)
118119

119120
require (
@@ -132,16 +133,16 @@ require (
132133
github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097 // indirect
133134
github.com/fsnotify/fsnotify v1.8.0 // indirect
134135
github.com/ghodss/yaml v1.0.0 // indirect
135-
github.com/go-logr/logr v1.4.2 // indirect
136+
github.com/go-logr/logr v1.4.3 // indirect
136137
github.com/go-logr/stdr v1.2.2 // indirect
137138
github.com/go-ole/go-ole v1.2.6 // indirect
138139
github.com/go-openapi/jsonpointer v0.21.0 // indirect
139140
github.com/go-openapi/jsonreference v0.21.0 // indirect
140141
github.com/go-openapi/swag v0.23.0 // indirect
141142
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
142143
github.com/gogo/protobuf v1.3.2 // indirect
143-
github.com/google/gnostic-models v0.6.9 // indirect
144-
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
144+
github.com/google/gnostic-models v0.7.0 // indirect
145+
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
145146
github.com/gookit/color v1.5.4 // indirect
146147
github.com/gosimple/slug v1.15.0
147148
github.com/gosimple/unidecode v1.0.1 // indirect
@@ -163,7 +164,7 @@ require (
163164
github.com/mattn/go-runewidth v0.0.15 // indirect
164165
github.com/mitchellh/mapstructure v1.5.0 // indirect
165166
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
166-
github.com/modern-go/reflect2 v1.0.2 // indirect
167+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
167168
github.com/mozillazg/go-unidecode v0.2.0 // indirect
168169
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
169170
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
@@ -190,19 +191,18 @@ require (
190191
github.com/yusufpapurcu/wmi v1.2.4 // indirect
191192
go.uber.org/multierr v1.11.0 // indirect
192193
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
193-
golang.org/x/mod v0.24.0 // indirect
194-
golang.org/x/net v0.39.0 // indirect
195-
golang.org/x/sys v0.34.0 // indirect
196-
golang.org/x/term v0.32.0 // indirect
197-
golang.org/x/text v0.24.0 // indirect
198-
golang.org/x/tools v0.32.0 // indirect
199-
google.golang.org/protobuf v1.36.6 // indirect
194+
golang.org/x/mod v0.29.0 // indirect
195+
golang.org/x/net v0.47.0 // indirect
196+
golang.org/x/sys v0.38.0 // indirect
197+
golang.org/x/term v0.37.0 // indirect
198+
golang.org/x/text v0.31.0 // indirect
199+
golang.org/x/tools v0.38.0 // indirect
200+
google.golang.org/protobuf v1.36.8 // indirect
200201
gopkg.in/inf.v0 v0.9.1 // indirect
201202
gopkg.in/yaml.v3 v3.0.1 // indirect
202203
k8s.io/klog/v2 v2.130.1 // indirect
203-
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
204-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
204+
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
205+
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
205206
sigs.k8s.io/controller-runtime v0.20.4 // indirect
206-
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
207-
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect
207+
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
208208
)

0 commit comments

Comments
 (0)