Skip to content

Commit cd70f16

Browse files
committed
pkg: Migrate from k8s.io/apimachinery/pkg/util/diff to github.com/google/go-cmp/cmp
Catching up with the kubernetes/kubernetes@1e9ce46f0a67 (migrate k8s.io/apimachinery/pkg/util/diff to cmp, 2019-05-14, kubernetes/kubernetes#70929) deprecation and kubernetes/kubernetes@03afe6471bdb (Add a replacement for cmp.Diff using json+go-difflib, 2025-06-16, kubernetes/kubernetes#132221) removal.
1 parent 7382576 commit cd70f16

7 files changed

Lines changed: 27 additions & 29 deletions

File tree

pkg/cvo/cvo_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
apiruntime "k8s.io/apimachinery/pkg/runtime"
2626
"k8s.io/apimachinery/pkg/runtime/schema"
2727
"k8s.io/apimachinery/pkg/types"
28-
"k8s.io/apimachinery/pkg/util/diff"
2928
"k8s.io/apimachinery/pkg/util/wait"
3029
"k8s.io/apimachinery/pkg/watch"
3130
"k8s.io/client-go/informers"
@@ -2783,7 +2782,7 @@ func TestOperator_availableUpdatesSync(t *testing.T) {
27832782
}
27842783

27852784
if !reflect.DeepEqual(optr.availableUpdates, tt.wantUpdates) {
2786-
t.Fatalf("unexpected: %s", diff.ObjectReflectDiff(tt.wantUpdates, optr.availableUpdates))
2785+
t.Fatalf("unexpected: %s", cmp.Diff(tt.wantUpdates, optr.availableUpdates))
27872786
}
27882787
if (optr.queue.Len() > 0) != (optr.availableUpdates != nil) {
27892788
t.Fatalf("unexpected queue")
@@ -3884,7 +3883,7 @@ func TestOperator_upgradeableSync(t *testing.T) {
38843883
}
38853884

38863885
if !reflect.DeepEqual(optr.upgradeable, tt.expectedResult) {
3887-
t.Fatalf("unexpected: %s", diff.ObjectReflectDiff(tt.expectedResult, optr.upgradeable))
3886+
t.Fatalf("unexpected: %s", cmp.Diff(tt.expectedResult, optr.upgradeable))
38883887
}
38893888
if (optr.queue.Len() > 0) != (optr.upgradeable != nil) {
38903889
t.Fatalf("unexpected queue")
@@ -4151,7 +4150,7 @@ func expectMutation(t *testing.T, a ktesting.Action, verb string, resource, subr
41514150
}
41524151
if !reflect.DeepEqual(expect, actual) {
41534152
t.Logf("%#v", actual)
4154-
t.Fatalf("unexpected object: %s", diff.ObjectReflectDiff(expect, actual))
4153+
t.Fatalf("unexpected object: %s", cmp.Diff(expect, actual))
41554154
}
41564155
default:
41574156
t.Fatalf("unknown verb %T", a)
@@ -4365,7 +4364,7 @@ func TestOperator_mergeReleaseMetadata(t *testing.T) {
43654364
optr := Operator{availableUpdates: testCase.availableUpdates}
43664365
actual := mergeReleaseMetadata(testCase.input, optr.getAvailableUpdates)
43674366
if !reflect.DeepEqual(actual, testCase.expected) {
4368-
t.Fatalf("unexpected: %s", diff.ObjectReflectDiff(testCase.expected, actual))
4367+
t.Fatalf("unexpected: %s", cmp.Diff(testCase.expected, actual))
43694368
}
43704369
})
43714370
}

pkg/cvo/status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/google/go-cmp/cmp"
1314
"k8s.io/klog/v2"
1415

1516
"k8s.io/apimachinery/pkg/api/equality"
1617
apierrors "k8s.io/apimachinery/pkg/api/errors"
1718
"k8s.io/apimachinery/pkg/api/meta"
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19-
"k8s.io/apimachinery/pkg/util/diff"
2020
"k8s.io/apimachinery/pkg/util/validation/field"
2121

2222
configv1 "github.com/openshift/api/config/v1"
@@ -202,7 +202,7 @@ func (optr *Operator) syncStatus(ctx context.Context, original, config *configv1
202202
updateClusterVersionStatus(&config.Status, status, optr.release, optr.getAvailableUpdates, optr.enabledFeatureGates, validationErrs)
203203

204204
if klog.V(6).Enabled() {
205-
klog.Infof("Apply config: %s", diff.ObjectReflectDiff(original, config))
205+
klog.Infof("Apply config: %s", cmp.Diff(original, config))
206206
}
207207
updated, err := applyClusterVersionStatus(ctx, optr.client.ConfigV1(), config, original)
208208
optr.rememberLastUpdate(updated)

pkg/cvo/status_history_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"reflect"
55
"testing"
66

7-
"k8s.io/apimachinery/pkg/util/diff"
7+
"github.com/google/go-cmp/cmp"
88
"k8s.io/klog/v2"
99

1010
configv1 "github.com/openshift/api/config/v1"
@@ -170,7 +170,7 @@ func Test_prune(t *testing.T) {
170170
dumpHistory(t, h)
171171
}
172172
if !reflect.DeepEqual(tt.want, h) {
173-
t.Fatalf("%s", diff.ObjectReflectDiff(tt.want, h))
173+
t.Fatalf("%s", cmp.Diff(tt.want, h))
174174
}
175175
})
176176
}
@@ -221,7 +221,7 @@ func Test_isTheInitialEntry(t *testing.T) {
221221
t.Run(tt.name, func(t *testing.T) {
222222
isIt := isTheInitialEntry(tt.entryIdx, tt.maxHistory)
223223
if !reflect.DeepEqual(tt.want, isIt) {
224-
t.Fatalf("%s", diff.ObjectReflectDiff(tt.want, isIt))
224+
t.Fatalf("%s", cmp.Diff(tt.want, isIt))
225225
}
226226
})
227227
}
@@ -265,7 +265,7 @@ func Test_isAFinalEntry(t *testing.T) {
265265
t.Run(tt.name, func(t *testing.T) {
266266
isIt := isAFinalEntry(tt.entryIdx)
267267
if !reflect.DeepEqual(tt.want, isIt) {
268-
t.Fatalf("%s", diff.ObjectReflectDiff(tt.want, isIt))
268+
t.Fatalf("%s", cmp.Diff(tt.want, isIt))
269269
}
270270
})
271271
}
@@ -323,7 +323,7 @@ func Test_isTheMostRecentCompletedEntry(t *testing.T) {
323323
mostRecentIdx := getTheMostRecentCompletedEntryIndex(tt.history)
324324
isIt := isTheMostRecentCompletedEntry(tt.entryIdx, mostRecentIdx)
325325
if !reflect.DeepEqual(tt.want, isIt) {
326-
t.Fatalf("%s", diff.ObjectReflectDiff(tt.want, isIt))
326+
t.Fatalf("%s", cmp.Diff(tt.want, isIt))
327327
}
328328
})
329329
}
@@ -439,7 +439,7 @@ func Test_isTheFirstOrLastCompletedInAMinor(t *testing.T) {
439439
t.Run(tt.name, func(t *testing.T) {
440440
isIt := isTheFirstOrLastCompletedInAMinor(tt.entryIdx, tt.history, tt.maxHistory)
441441
if !reflect.DeepEqual(tt.want, isIt) {
442-
t.Fatalf("%s", diff.ObjectReflectDiff(tt.want, isIt))
442+
t.Fatalf("%s", cmp.Diff(tt.want, isIt))
443443
}
444444
})
445445
}
@@ -548,7 +548,7 @@ func Test_isPartialPortionOfMinorTransition(t *testing.T) {
548548
t.Run(tt.name, func(t *testing.T) {
549549
isIt := isPartialPortionOfMinorTransition(tt.entryIdx, tt.history, tt.maxHistory)
550550
if !reflect.DeepEqual(tt.want, isIt) {
551-
t.Fatalf("%s", diff.ObjectReflectDiff(tt.want, isIt))
551+
t.Fatalf("%s", cmp.Diff(tt.want, isIt))
552552
}
553553
})
554554
}
@@ -657,7 +657,7 @@ func Test_isPartialWithinAZStream(t *testing.T) {
657657
t.Run(tt.name, func(t *testing.T) {
658658
isIt := isPartialWithinAZStream(tt.entryIdx, tt.history, tt.maxHistory)
659659
if !reflect.DeepEqual(tt.want, isIt) {
660-
t.Fatalf("%s", diff.ObjectReflectDiff(tt.want, isIt))
660+
t.Fatalf("%s", cmp.Diff(tt.want, isIt))
661661
}
662662
})
663663
}
@@ -711,7 +711,7 @@ func Test_sameMinorVersion(t *testing.T) {
711711
t.Run(tt.name, func(t *testing.T) {
712712
isIt := sameMinorVersion(tt.h1, tt.h2)
713713
if !reflect.DeepEqual(tt.want, isIt) {
714-
t.Fatalf("%s", diff.ObjectReflectDiff(tt.want, isIt))
714+
t.Fatalf("%s", cmp.Diff(tt.want, isIt))
715715
}
716716
})
717717
}
@@ -770,7 +770,7 @@ func Test_sameZStreamVersion(t *testing.T) {
770770
t.Run(tt.name, func(t *testing.T) {
771771
isIt := sameZStreamVersion(tt.h1, tt.h2)
772772
if !reflect.DeepEqual(tt.want, isIt) {
773-
t.Fatalf("%s", diff.ObjectReflectDiff(tt.want, isIt))
773+
t.Fatalf("%s", cmp.Diff(tt.want, isIt))
774774
}
775775
})
776776
}

pkg/cvo/status_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/google/go-cmp/cmp/cmpopts"
1212
"github.com/openshift/cluster-version-operator/pkg/payload"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14-
"k8s.io/apimachinery/pkg/util/diff"
1514
apierrors "k8s.io/apimachinery/pkg/util/errors"
1615
"k8s.io/apimachinery/pkg/util/validation/field"
1716
"k8s.io/client-go/tools/record"
@@ -180,7 +179,7 @@ func TestOperator_syncFailingStatus(t *testing.T) {
180179
err := optr.syncFailingStatus(ctx, tt.original, tt.ierr)
181180

182181
if !reflect.DeepEqual(originalCopy, tt.original) {
183-
t.Fatalf("syncFailingStatus mutated input: %s", diff.ObjectReflectDiff(originalCopy, tt.original))
182+
t.Fatalf("syncFailingStatus mutated input: %s", cmp.Diff(originalCopy, tt.original))
184183
}
185184

186185
if err != nil && tt.wantErr == nil {

pkg/cvo/sync_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sync"
1111
"testing"
1212

13+
"github.com/google/go-cmp/cmp"
1314
"k8s.io/client-go/tools/record"
1415

1516
"github.com/davecgh/go-spew/spew"
@@ -19,7 +20,6 @@ import (
1920
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2021
"k8s.io/apimachinery/pkg/runtime"
2122
"k8s.io/apimachinery/pkg/runtime/schema"
22-
"k8s.io/apimachinery/pkg/util/diff"
2323
dynamicfake "k8s.io/client-go/dynamic/fake"
2424
"k8s.io/client-go/rest"
2525
clientgotesting "k8s.io/client-go/testing"
@@ -82,10 +82,10 @@ func Test_SyncWorker_apply(t *testing.T) {
8282
}
8383

8484
if got, exp := actions[0], (newAction(schema.GroupVersionKind{Group: "test.cvo.io", Version: "v1", Kind: "TestA"}, "default", "testa")); !reflect.DeepEqual(got, exp) {
85-
t.Fatalf("%s", diff.ObjectReflectDiff(exp, got))
85+
t.Fatalf("%s", cmp.Diff(exp, got))
8686
}
8787
if got, exp := actions[1], (newAction(schema.GroupVersionKind{Group: "test.cvo.io", Version: "v1", Kind: "TestB"}, "default", "testb")); !reflect.DeepEqual(got, exp) {
88-
t.Fatalf("%s", diff.ObjectReflectDiff(exp, got))
88+
t.Fatalf("%s", cmp.Diff(exp, got))
8989
}
9090
},
9191
}, {
@@ -128,7 +128,7 @@ func Test_SyncWorker_apply(t *testing.T) {
128128
exp := newAction(schema.GroupVersionKind{Group: "test.cvo.io", Version: "v1", Kind: "TestA"}, "default", "testa")
129129
for i, got := range actions {
130130
if !reflect.DeepEqual(got, exp) {
131-
t.Fatalf("unexpected action %d: %s", i, diff.ObjectReflectDiff(exp, got))
131+
t.Fatalf("unexpected action %d: %s", i, cmp.Diff(exp, got))
132132
}
133133
}
134134
},

pkg/cvo/sync_worker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88
"time"
99

1010
"github.com/davecgh/go-spew/spew"
11+
"github.com/google/go-cmp/cmp"
1112
configv1 "github.com/openshift/api/config/v1"
1213
"github.com/openshift/library-go/pkg/manifest"
1314
apierrors "k8s.io/apimachinery/pkg/api/errors"
1415
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1516
"k8s.io/apimachinery/pkg/runtime/schema"
16-
"k8s.io/apimachinery/pkg/util/diff"
1717
"k8s.io/apimachinery/pkg/util/errors"
1818
"k8s.io/client-go/tools/record"
1919

@@ -376,7 +376,7 @@ func Test_condenseClusterOperators(t *testing.T) {
376376
actual := condenseClusterOperators(test.input)
377377
if !reflect.DeepEqual(test.expected, actual) {
378378
spew.Config.DisableMethods = true
379-
t.Fatalf("Incorrect value returned -\ndiff: %s\nexpected: %s\nreturned: %s", diff.ObjectReflectDiff(test.expected, actual), spew.Sdump(test.expected), spew.Sdump(actual))
379+
t.Fatalf("Incorrect value returned -\ndiff: %s\nexpected: %s\nreturned: %s", cmp.Diff(test.expected, actual), spew.Sdump(test.expected), spew.Sdump(actual))
380380
}
381381
})
382382
}

pkg/start/start_integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import (
1616
"testing"
1717
"time"
1818

19+
"github.com/google/go-cmp/cmp"
1920
"github.com/google/uuid"
2021

2122
v1 "k8s.io/api/core/v1"
2223
"k8s.io/apimachinery/pkg/api/errors"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24-
"k8s.io/apimachinery/pkg/util/diff"
2525
randutil "k8s.io/apimachinery/pkg/util/rand"
2626
"k8s.io/apimachinery/pkg/util/wait"
2727
"k8s.io/client-go/kubernetes"
@@ -241,7 +241,7 @@ func TestIntegrationCVO_initializeAndUpgrade(t *testing.T) {
241241
t.Fatal(err)
242242
}
243243
if !reflect.DeepEqual(cv.Status, lastCV.Status) {
244-
t.Fatalf("unexpected: %s", diff.ObjectReflectDiff(lastCV.Status, cv.Status))
244+
t.Fatalf("unexpected: %s", cmp.Diff(lastCV.Status, cv.Status))
245245
}
246246
verifyReleasePayload(ctx, t, kc, ns, "0.0.1", payloadImage1)
247247
}
@@ -722,7 +722,7 @@ func verifyClusterVersionHistory(t *testing.T, cv *configv1.ClusterVersion) {
722722
t.Fatalf("Invalid history, entry %d had no completion time: %#v", i, history)
723723
}
724724
if history.Image == previous.Image && history.Version == previous.Version {
725-
t.Fatalf("Invalid history, entry %d and %d have identical updates, should be one entry: %s", i-1, i, diff.ObjectReflectDiff(previous, &history))
725+
t.Fatalf("Invalid history, entry %d and %d have identical updates, should be one entry: %s", i-1, i, cmp.Diff(previous, &history))
726726
}
727727
}
728728
}
@@ -750,7 +750,7 @@ func verifyClusterVersionStatus(t *testing.T, cv *configv1.ClusterVersion, expec
750750
CompletionTime: actual.CompletionTime,
751751
}
752752
if !reflect.DeepEqual(expect, actual) {
753-
t.Fatalf("unexpected history: %s", diff.ObjectReflectDiff(expect, actual))
753+
t.Fatalf("unexpected history: %s", cmp.Diff(expect, actual))
754754
}
755755
if len(cv.Status.VersionHash) == 0 {
756756
t.Fatalf("unexpected version hash: %#v", cv.Status.VersionHash)

0 commit comments

Comments
 (0)