diff --git a/cmd/kube-controller-manager/app/options/options_test.go b/cmd/kube-controller-manager/app/options/options_test.go index d281ce1a471..fac8128542a 100644 --- a/cmd/kube-controller-manager/app/options/options_test.go +++ b/cmd/kube-controller-manager/app/options/options_test.go @@ -23,11 +23,11 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "github.com/spf13/pflag" eventv1 "k8s.io/api/events/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" utilerrors "k8s.io/apimachinery/pkg/util/errors" apiserveroptions "k8s.io/apiserver/pkg/server/options" cpconfig "k8s.io/cloud-provider/config" @@ -442,7 +442,7 @@ func TestAddFlags(t *testing.T) { sort.Sort(sortedGCIgnoredResources(expected.GarbageCollectorController.GCIgnoredResources)) if !reflect.DeepEqual(expected, s) { - t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", diff.ObjectReflectDiff(expected, s)) + t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", cmp.Diff(expected, s)) } } @@ -641,7 +641,7 @@ func TestApplyTo(t *testing.T) { s.ApplyTo(c) if !reflect.DeepEqual(expected.ComponentConfig, c.ComponentConfig) { - t.Errorf("Got different configuration than expected.\nDifference detected on:\n%s", diff.ObjectReflectDiff(expected.ComponentConfig, c.ComponentConfig)) + t.Errorf("Got different configuration than expected.\nDifference detected on:\n%s", cmp.Diff(expected.ComponentConfig, c.ComponentConfig)) } } diff --git a/cmd/kubelet/app/options/options_test.go b/cmd/kubelet/app/options/options_test.go index 9abfbd9d06e..bd7a4af4953 100644 --- a/cmd/kubelet/app/options/options_test.go +++ b/cmd/kubelet/app/options/options_test.go @@ -21,9 +21,9 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" "github.com/spf13/pflag" - "k8s.io/apimachinery/pkg/util/diff" cliflag "k8s.io/component-base/cli/flag" "k8s.io/kubernetes/pkg/kubelet/config" ) @@ -101,7 +101,7 @@ func TestRoundTrip(t *testing.T) { continue } if !reflect.DeepEqual(modifiedFlags, outputFlags) { - t.Errorf("%s: flags did not round trip: %s", testCase.name, diff.ObjectReflectDiff(modifiedFlags, outputFlags)) + t.Errorf("%s: flags did not round trip: %s", testCase.name, cmp.Diff(modifiedFlags, outputFlags)) continue } } diff --git a/pkg/api/pod/util.go b/pkg/api/pod/util.go index e7e6ae61482..7370a7b13fd 100644 --- a/pkg/api/pod/util.go +++ b/pkg/api/pod/util.go @@ -19,10 +19,10 @@ package pod import ( "strings" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" - "k8s.io/apimachinery/pkg/util/diff" utilfeature "k8s.io/apiserver/pkg/util/feature" api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/apis/core/helper" @@ -850,7 +850,7 @@ func MarkPodProposedForResize(oldPod, newPod *api.Pod) { if c.Resources.Requests == nil { continue } - if diff.ObjectDiff(oldPod.Spec.Containers[i].Resources, c.Resources) == "" { + if cmp.Equal(oldPod.Spec.Containers[i].Resources, c.Resources) { continue } findContainerStatus := func(css []api.ContainerStatus, cName string) (api.ContainerStatus, bool) { @@ -862,7 +862,7 @@ func MarkPodProposedForResize(oldPod, newPod *api.Pod) { return api.ContainerStatus{}, false } if cs, ok := findContainerStatus(newPod.Status.ContainerStatuses, c.Name); ok { - if diff.ObjectDiff(c.Resources.Requests, cs.AllocatedResources) != "" { + if !cmp.Equal(c.Resources.Requests, cs.AllocatedResources) { newPod.Status.Resize = api.PodResizeStatusProposed break } diff --git a/pkg/api/pod/util_test.go b/pkg/api/pod/util_test.go index e9d0f4a1e39..f63802c5717 100644 --- a/pkg/api/pod/util_test.go +++ b/pkg/api/pod/util_test.go @@ -27,7 +27,6 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/validation/field" utilfeature "k8s.io/apiserver/pkg/util/feature" @@ -2382,14 +2381,14 @@ func TestDropInPlacePodVerticalScaling(t *testing.T) { // old pod should never be changed if !reflect.DeepEqual(oldPod, oldPodInfo.pod()) { - t.Errorf("old pod changed: %v", diff.ObjectReflectDiff(oldPod, oldPodInfo.pod())) + t.Errorf("old pod changed: %v", cmp.Diff(oldPod, oldPodInfo.pod())) } switch { case enabled || oldPodHasInPlaceVerticalScaling: // new pod shouldn't change if feature enabled or if old pod has ResizePolicy set if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } case newPodHasInPlaceVerticalScaling: // new pod should be changed @@ -2398,12 +2397,12 @@ func TestDropInPlacePodVerticalScaling(t *testing.T) { } // new pod should not have ResizePolicy if !reflect.DeepEqual(newPod, podWithoutInPlaceVerticalScaling()) { - t.Errorf("new pod has ResizePolicy: %v", diff.ObjectReflectDiff(newPod, podWithoutInPlaceVerticalScaling())) + t.Errorf("new pod has ResizePolicy: %v", cmp.Diff(newPod, podWithoutInPlaceVerticalScaling())) } default: // new pod should not need to be changed if !reflect.DeepEqual(newPod, newPodInfo.pod()) { - t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod())) + t.Errorf("new pod changed: %v", cmp.Diff(newPod, newPodInfo.pod())) } } }) diff --git a/pkg/api/testing/copy_test.go b/pkg/api/testing/copy_test.go index 1169714e977..8f3acbda0e9 100644 --- a/pkg/api/testing/copy_test.go +++ b/pkg/api/testing/copy_test.go @@ -23,13 +23,12 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/google/gofuzz" + fuzz "github.com/google/gofuzz" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/api/apitesting/roundtrip" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api/legacyscheme" ) @@ -71,7 +70,7 @@ func doDeepCopyTest(t *testing.T, kind schema.GroupVersionKind, f *fuzz.Fuzzer) } if !bytes.Equal(prefuzzData.Bytes(), postfuzzData.Bytes()) { - t.Log(diff.StringDiff(prefuzzData.String(), postfuzzData.String())) + t.Log(cmp.Diff(prefuzzData.String(), postfuzzData.String())) t.Errorf("Fuzzing copy modified original of %#v", kind) return } diff --git a/pkg/apis/autoscaling/v1/defaults_test.go b/pkg/apis/autoscaling/v1/defaults_test.go index 7931d1b8b04..473c22acb97 100644 --- a/pkg/apis/autoscaling/v1/defaults_test.go +++ b/pkg/apis/autoscaling/v1/defaults_test.go @@ -20,10 +20,10 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" autoscalingv1 "k8s.io/api/autoscaling/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/apis/autoscaling" _ "k8s.io/kubernetes/pkg/apis/autoscaling/install" @@ -124,7 +124,7 @@ func TestHorizontalPodAutoscalerAnnotations(t *testing.T) { t.Fatalf("unexpected object: %v", obj) } if !reflect.DeepEqual(*hpa, hpaBeforeMuatate) { - t.Errorf("diff: %v", diff.ObjectDiff(*hpa, hpaBeforeMuatate)) + t.Errorf("diff: %v", cmp.Diff(*hpa, hpaBeforeMuatate)) t.Errorf("expected: %#v\n actual: %#v", *hpa, hpaBeforeMuatate) } diff --git a/pkg/apis/autoscaling/v2/defaults_test.go b/pkg/apis/autoscaling/v2/defaults_test.go index 317adf5b6c3..ad95076d7e5 100644 --- a/pkg/apis/autoscaling/v2/defaults_test.go +++ b/pkg/apis/autoscaling/v2/defaults_test.go @@ -21,9 +21,9 @@ import ( "testing" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api/legacyscheme" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" autoscalingv2 "k8s.io/api/autoscaling/v2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -293,7 +293,7 @@ func TestHorizontalPodAutoscalerAnnotations(t *testing.T) { t.Fatalf("unexpected object: %v", obj) } if !reflect.DeepEqual(*hpa, hpaBeforeMuatate) { - t.Errorf("diff: %v", diff.ObjectDiff(*hpa, hpaBeforeMuatate)) + t.Errorf("diff: %v", cmp.Diff(*hpa, hpaBeforeMuatate)) t.Errorf("expected: %#v\n actual: %#v", *hpa, hpaBeforeMuatate) } diff --git a/pkg/apis/autoscaling/v2beta1/defaults_test.go b/pkg/apis/autoscaling/v2beta1/defaults_test.go index 56335ae1034..8573d2f13d0 100644 --- a/pkg/apis/autoscaling/v2beta1/defaults_test.go +++ b/pkg/apis/autoscaling/v2beta1/defaults_test.go @@ -20,8 +20,7 @@ import ( "reflect" "testing" - "k8s.io/apimachinery/pkg/util/diff" - + "github.com/google/go-cmp/cmp" autoscalingv2beta1 "k8s.io/api/autoscaling/v2beta1" v1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" @@ -163,7 +162,7 @@ func TestHorizontalPodAutoscalerAnnotations(t *testing.T) { t.Fatalf("unexpected object: %v", obj) } if !reflect.DeepEqual(*hpa, hpaBeforeMuatate) { - t.Errorf("diff: %v", diff.ObjectDiff(*hpa, hpaBeforeMuatate)) + t.Errorf("diff: %v", cmp.Diff(*hpa, hpaBeforeMuatate)) t.Errorf("expected: %#v\n actual: %#v", *hpa, hpaBeforeMuatate) } diff --git a/pkg/apis/autoscaling/v2beta2/defaults_test.go b/pkg/apis/autoscaling/v2beta2/defaults_test.go index a3114fa1bb0..86a0c2fee37 100644 --- a/pkg/apis/autoscaling/v2beta2/defaults_test.go +++ b/pkg/apis/autoscaling/v2beta2/defaults_test.go @@ -21,9 +21,9 @@ import ( "testing" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api/legacyscheme" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" autoscalingv2 "k8s.io/api/autoscaling/v2beta2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -293,7 +293,7 @@ func TestHorizontalPodAutoscalerAnnotations(t *testing.T) { t.Fatalf("unexpected object: %v", obj) } if !reflect.DeepEqual(*hpa, hpaBeforeMuatate) { - t.Errorf("diff: %v", diff.ObjectDiff(*hpa, hpaBeforeMuatate)) + t.Errorf("diff: %v", cmp.Diff(*hpa, hpaBeforeMuatate)) t.Errorf("expected: %#v\n actual: %#v", *hpa, hpaBeforeMuatate) } diff --git a/pkg/apis/certificates/validation/validation.go b/pkg/apis/certificates/validation/validation.go index 7f26551b0ae..e277cd74898 100644 --- a/pkg/apis/certificates/validation/validation.go +++ b/pkg/apis/certificates/validation/validation.go @@ -23,10 +23,10 @@ import ( "fmt" "strings" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" utilvalidation "k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation/field" @@ -383,7 +383,7 @@ func validateCertificateSigningRequestUpdate(newCSR, oldCSR *certificates.Certif case len(newConditions) > len(oldConditions): validationErrorList = append(validationErrorList, field.Forbidden(field.NewPath("status", "conditions"), fmt.Sprintf("updates may not add a condition of type %q", t))) case !apiequality.Semantic.DeepEqual(oldConditions, newConditions): - conditionDiff := diff.ObjectDiff(oldConditions, newConditions) + conditionDiff := cmp.Diff(oldConditions, newConditions) validationErrorList = append(validationErrorList, field.Forbidden(field.NewPath("status", "conditions"), fmt.Sprintf("updates may not modify a condition of type %q\n%v", t, conditionDiff))) } } diff --git a/pkg/apis/core/v1/defaults_test.go b/pkg/apis/core/v1/defaults_test.go index feeeb12caec..dee97fe4920 100644 --- a/pkg/apis/core/v1/defaults_test.go +++ b/pkg/apis/core/v1/defaults_test.go @@ -23,11 +23,11 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/intstr" utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" @@ -180,7 +180,7 @@ func testWorkloadDefaults(t *testing.T, featuresEnabled bool) { defaults := detectDefaults(t, rc, reflect.ValueOf(template)) if !reflect.DeepEqual(expectedDefaults, defaults) { t.Errorf("Defaults for PodTemplateSpec changed. This can cause spurious rollouts of workloads on API server upgrade.") - t.Logf(diff.ObjectReflectDiff(expectedDefaults, defaults)) + t.Logf(cmp.Diff(expectedDefaults, defaults)) } } @@ -326,7 +326,7 @@ func testPodDefaults(t *testing.T, featuresEnabled bool) { defaults := detectDefaults(t, pod, reflect.ValueOf(pod)) if !reflect.DeepEqual(expectedDefaults, defaults) { t.Errorf("Defaults for PodSpec changed. This can cause spurious restarts of containers on API server upgrade.") - t.Logf(diff.ObjectReflectDiff(expectedDefaults, defaults)) + t.Logf(cmp.Diff(expectedDefaults, defaults)) } } @@ -2113,7 +2113,7 @@ func TestSetDefaultResizePolicy(t *testing.T) { testPod.Spec.Containers = append(testPod.Spec.Containers, tc.testContainer) output := roundTrip(t, runtime.Object(&testPod)) pod2 := output.(*v1.Pod) - if diff.ObjectDiff(pod2.Spec.Containers[0].ResizePolicy, tc.expectedResizePolicy) != "" { + if !cmp.Equal(pod2.Spec.Containers[0].ResizePolicy, tc.expectedResizePolicy) { t.Errorf("expected resize policy %+v, but got %+v", tc.expectedResizePolicy, pod2.Spec.Containers[0].ResizePolicy) } }) diff --git a/pkg/apis/rbac/helpers_test.go b/pkg/apis/rbac/helpers_test.go index d6e7593bcc7..3771044597c 100644 --- a/pkg/apis/rbac/helpers_test.go +++ b/pkg/apis/rbac/helpers_test.go @@ -20,11 +20,11 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api/legacyscheme" "k8s.io/kubernetes/pkg/apis/rbac" - "k8s.io/kubernetes/pkg/apis/rbac/v1" + v1 "k8s.io/kubernetes/pkg/apis/rbac/v1" // install RBAC types _ "k8s.io/kubernetes/pkg/apis/rbac/install" @@ -65,7 +65,7 @@ func TestHelpersRoundTrip(t *testing.T) { continue } if !reflect.DeepEqual(internalObj, roundTrippedObj) { - t.Errorf("err on %T: got difference:\n%s", internalObj, diff.ObjectDiff(internalObj, roundTrippedObj)) + t.Errorf("err on %T: got difference:\n%s", internalObj, cmp.Diff(internalObj, roundTrippedObj)) continue } } diff --git a/pkg/controller/certificates/rootcacertpublisher/publisher_test.go b/pkg/controller/certificates/rootcacertpublisher/publisher_test.go index cb5fb132e26..67852476a42 100644 --- a/pkg/controller/certificates/rootcacertpublisher/publisher_test.go +++ b/pkg/controller/certificates/rootcacertpublisher/publisher_test.go @@ -21,10 +21,10 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes/fake" corev1listers "k8s.io/client-go/listers/core/v1" @@ -162,7 +162,7 @@ func TestConfigMapCreation(t *testing.T) { actions := client.Actions() if reflect.DeepEqual(actions, tc.ExpectActions) { - t.Errorf("Unexpected actions:\n%s", diff.ObjectGoPrintDiff(actions, tc.ExpectActions)) + t.Errorf("Unexpected actions:\n%s", cmp.Diff(actions, tc.ExpectActions)) } }) } diff --git a/pkg/controller/clusterroleaggregation/clusterroleaggregation_controller_test.go b/pkg/controller/clusterroleaggregation/clusterroleaggregation_controller_test.go index 49687d76fdf..5fb2f890186 100644 --- a/pkg/controller/clusterroleaggregation/clusterroleaggregation_controller_test.go +++ b/pkg/controller/clusterroleaggregation/clusterroleaggregation_controller_test.go @@ -20,12 +20,12 @@ import ( "context" "testing" + "github.com/google/go-cmp/cmp" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/yaml" rbacv1ac "k8s.io/client-go/applyconfigurations/rbac/v1" fakeclient "k8s.io/client-go/kubernetes/fake" @@ -215,7 +215,7 @@ func TestSyncClusterRole(t *testing.T) { t.Fatalf("error unmarshalling apply request: %v", err) } if !equality.Semantic.DeepEqual(ac, test.expectedClusterRoleApply) { - t.Fatalf("%v", diff.ObjectDiff(test.expectedClusterRoleApply, ac)) + t.Fatalf("%v", cmp.Diff(test.expectedClusterRoleApply, ac)) } if expectedActions == 2 { action := fakeClient.Actions()[1] @@ -227,7 +227,7 @@ func TestSyncClusterRole(t *testing.T) { t.Fatalf("unexpected action %#v", action) } if !equality.Semantic.DeepEqual(updateAction.GetObject().(*rbacv1.ClusterRole), test.expectedClusterRole) { - t.Fatalf("%v", diff.ObjectDiff(test.expectedClusterRole, updateAction.GetObject().(*rbacv1.ClusterRole))) + t.Fatalf("%v", cmp.Diff(test.expectedClusterRole, updateAction.GetObject().(*rbacv1.ClusterRole))) } } }) diff --git a/pkg/controller/endpoint/endpoints_controller_test.go b/pkg/controller/endpoint/endpoints_controller_test.go index 1bfe983b6bc..6f6a8a9eb36 100644 --- a/pkg/controller/endpoint/endpoints_controller_test.go +++ b/pkg/controller/endpoint/endpoints_controller_test.go @@ -26,11 +26,11 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/informers" @@ -1070,7 +1070,7 @@ func TestSyncEndpointsHeadlessService(t *testing.T) { }}, }) if !reflect.DeepEqual(originalService, service) { - t.Fatalf("syncing endpoints changed service: %s", diff.ObjectReflectDiff(service, originalService)) + t.Fatalf("syncing endpoints changed service: %s", cmp.Diff(service, originalService)) } endpointsHandler.ValidateRequestCount(t, 1) endpointsHandler.ValidateRequest(t, "/api/v1/namespaces/"+ns+"/endpoints/foo", "PUT", &data) diff --git a/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go b/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go index aa5ab088b1d..e3ea9e7628f 100644 --- a/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go +++ b/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go @@ -33,7 +33,6 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/informers" appsinformers "k8s.io/client-go/informers/apps/v1" coordinformers "k8s.io/client-go/informers/coordination/v1" @@ -1250,10 +1249,10 @@ func TestMonitorNodeHealthUpdateStatus(t *testing.T) { t.Errorf("expected %v call, but got %v.", item.expectedRequestCount, item.fakeNodeHandler.RequestCount) } if len(item.fakeNodeHandler.UpdatedNodes) > 0 && !apiequality.Semantic.DeepEqual(item.expectedNodes, item.fakeNodeHandler.UpdatedNodes) { - t.Errorf("Case[%d] unexpected nodes: %s", i, diff.ObjectDiff(item.expectedNodes[0], item.fakeNodeHandler.UpdatedNodes[0])) + t.Errorf("Case[%d] unexpected nodes: %s", i, cmp.Diff(item.expectedNodes[0], item.fakeNodeHandler.UpdatedNodes[0])) } if len(item.fakeNodeHandler.UpdatedNodeStatuses) > 0 && !apiequality.Semantic.DeepEqual(item.expectedNodes, item.fakeNodeHandler.UpdatedNodeStatuses) { - t.Errorf("Case[%d] unexpected nodes: %s", i, diff.ObjectDiff(item.expectedNodes[0], item.fakeNodeHandler.UpdatedNodeStatuses[0])) + t.Errorf("Case[%d] unexpected nodes: %s", i, cmp.Diff(item.expectedNodes[0], item.fakeNodeHandler.UpdatedNodeStatuses[0])) } podStatusUpdated := false @@ -1800,10 +1799,10 @@ func TestMonitorNodeHealthUpdateNodeAndPodStatusWithLease(t *testing.T) { t.Errorf("expected %v call, but got %v.", item.expectedRequestCount, item.fakeNodeHandler.RequestCount) } if len(item.fakeNodeHandler.UpdatedNodes) > 0 && !apiequality.Semantic.DeepEqual(item.expectedNodes, item.fakeNodeHandler.UpdatedNodes) { - t.Errorf("unexpected nodes: %s", diff.ObjectDiff(item.expectedNodes[0], item.fakeNodeHandler.UpdatedNodes[0])) + t.Errorf("unexpected nodes: %s", cmp.Diff(item.expectedNodes[0], item.fakeNodeHandler.UpdatedNodes[0])) } if len(item.fakeNodeHandler.UpdatedNodeStatuses) > 0 && !apiequality.Semantic.DeepEqual(item.expectedNodes, item.fakeNodeHandler.UpdatedNodeStatuses) { - t.Errorf("unexpected nodes: %s", diff.ObjectDiff(item.expectedNodes[0], item.fakeNodeHandler.UpdatedNodeStatuses[0])) + t.Errorf("unexpected nodes: %s", cmp.Diff(item.expectedNodes[0], item.fakeNodeHandler.UpdatedNodeStatuses[0])) } podStatusUpdated := false diff --git a/pkg/controller/volume/persistentvolume/testing/testing.go b/pkg/controller/volume/persistentvolume/testing/testing.go index 73711e3fed7..c37a18aac47 100644 --- a/pkg/controller/volume/persistentvolume/testing/testing.go +++ b/pkg/controller/volume/persistentvolume/testing/testing.go @@ -20,17 +20,18 @@ import ( "context" "errors" "fmt" - "k8s.io/klog/v2" "reflect" "strconv" "sync" + "github.com/google/go-cmp/cmp" + "k8s.io/klog/v2" + v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/fake" core "k8s.io/client-go/testing" @@ -349,7 +350,7 @@ func (r *VolumeReactor) CheckVolumes(expectedVolumes []*v1.PersistentVolume) err if !reflect.DeepEqual(expectedMap, gotMap) { // Print ugly but useful diff of expected and received objects for // easier debugging. - return fmt.Errorf("Volume check failed [A-expected, B-got]: %s", diff.ObjectDiff(expectedMap, gotMap)) + return fmt.Errorf("Volume check failed [A-expected, B-got]: %s", cmp.Diff(expectedMap, gotMap)) } return nil } @@ -378,7 +379,7 @@ func (r *VolumeReactor) CheckClaims(expectedClaims []*v1.PersistentVolumeClaim) if !reflect.DeepEqual(expectedMap, gotMap) { // Print ugly but useful diff of expected and received objects for // easier debugging. - return fmt.Errorf("Claim check failed [A-expected, B-got result]: %s", diff.ObjectDiff(expectedMap, gotMap)) + return fmt.Errorf("Claim check failed [A-expected, B-got result]: %s", cmp.Diff(expectedMap, gotMap)) } return nil } diff --git a/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller_test.go b/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller_test.go index 50b56816849..7b62af4bde0 100644 --- a/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller_test.go +++ b/pkg/controlplane/controller/clusterauthenticationtrust/cluster_authentication_trust_controller_test.go @@ -21,13 +21,13 @@ import ( "testing" "github.com/davecgh/go-spew/spew" + "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/apiserver/pkg/authentication/request/headerrequest" "k8s.io/apiserver/pkg/server/dynamiccertificates" @@ -298,7 +298,7 @@ func TestWriteClientCAs(t *testing.T) { actualConfigMaps, updated := getFinalConfigMaps(t, client) if !reflect.DeepEqual(test.expectedConfigMaps, actualConfigMaps) { - t.Fatalf("%s: %v", test.name, diff.ObjectReflectDiff(test.expectedConfigMaps, actualConfigMaps)) + t.Fatalf("%s: %v", test.name, cmp.Diff(test.expectedConfigMaps, actualConfigMaps)) } if test.expectCreate != updated { t.Fatalf("%s: expected %v, got %v", test.name, test.expectCreate, updated) diff --git a/pkg/generated/openapi/openapi_test.go b/pkg/generated/openapi/openapi_test.go index 65f26e62f6b..1c9776ea857 100644 --- a/pkg/generated/openapi/openapi_test.go +++ b/pkg/generated/openapi/openapi_test.go @@ -21,7 +21,7 @@ import ( "reflect" "testing" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" "k8s.io/kube-openapi/pkg/common" "k8s.io/kube-openapi/pkg/handler" "k8s.io/kube-openapi/pkg/validation/spec" @@ -52,7 +52,7 @@ func TestOpenAPIRoundtrip(t *testing.T) { delete(value.Schema.Extensions, common.ExtensionV2Schema) if !reflect.DeepEqual(value.Schema, roundTripped) { - t.Errorf("unexpected diff (a=expected,b=roundtripped):\n%s", diff.ObjectReflectDiff(value.Schema, roundTripped)) + t.Errorf("unexpected diff (a=expected,b=roundtripped):\n%s", cmp.Diff(value.Schema, roundTripped)) return } }) diff --git a/pkg/kubelet/certificate/bootstrap/bootstrap_test.go b/pkg/kubelet/certificate/bootstrap/bootstrap_test.go index 81f4c816f77..e5dee33dae0 100644 --- a/pkg/kubelet/certificate/bootstrap/bootstrap_test.go +++ b/pkg/kubelet/certificate/bootstrap/bootstrap_test.go @@ -25,11 +25,11 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" certificatesv1 "k8s.io/api/certificates/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/fake" certificatesclient "k8s.io/client-go/kubernetes/typed/certificates/v1beta1" @@ -278,10 +278,10 @@ users: t.Fatal(err) } if !reflect.DeepEqual(certConfig, test.expectedCertConfig) { - t.Errorf("Unexpected certConfig: %s", diff.ObjectDiff(certConfig, test.expectedCertConfig)) + t.Errorf("Unexpected certConfig: %s", cmp.Diff(certConfig, test.expectedCertConfig)) } if !reflect.DeepEqual(clientConfig, test.expectedClientConfig) { - t.Errorf("Unexpected clientConfig: %s", diff.ObjectDiff(clientConfig, test.expectedClientConfig)) + t.Errorf("Unexpected clientConfig: %s", cmp.Diff(clientConfig, test.expectedClientConfig)) } }) } @@ -341,7 +341,7 @@ users: } if !reflect.DeepEqual(config, expectedConfig) { - t.Errorf("Unexpected config: %s", diff.ObjectDiff(config, expectedConfig)) + t.Errorf("Unexpected config: %s", cmp.Diff(config, expectedConfig)) } } diff --git a/pkg/kubelet/cloudresource/cloud_request_manager_test.go b/pkg/kubelet/cloudresource/cloud_request_manager_test.go index 45cbbad8f5d..f98793380c2 100644 --- a/pkg/kubelet/cloudresource/cloud_request_manager_test.go +++ b/pkg/kubelet/cloudresource/cloud_request_manager_test.go @@ -22,8 +22,8 @@ import ( "testing" "time" - "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" + v1 "k8s.io/api/core/v1" "k8s.io/cloud-provider/fake" ) @@ -54,7 +54,7 @@ func TestNodeAddressesDelay(t *testing.T) { t.Errorf("Unexpected err: %q\n", err) } if !reflect.DeepEqual(nodeAddresses, cloud.Addresses) { - t.Errorf("Unexpected diff of node addresses: %v", diff.ObjectReflectDiff(nodeAddresses, cloud.Addresses)) + t.Errorf("Unexpected diff of node addresses: %v", cmp.Diff(nodeAddresses, cloud.Addresses)) } // Change the IP address @@ -140,7 +140,7 @@ func TestNodeAddressesUsesLastSuccess(t *testing.T) { t.Errorf("unexpected err: %v", err) } if got, want := nodeAddresses, test.wantAddrs; !reflect.DeepEqual(got, want) { - t.Errorf("Unexpected diff of node addresses: %v", diff.ObjectReflectDiff(got, want)) + t.Errorf("Unexpected diff of node addresses: %v", cmp.Diff(got, want)) } }) } diff --git a/pkg/kubelet/eviction/helpers_test.go b/pkg/kubelet/eviction/helpers_test.go index 2b6c5cdd6ed..4bb8ac4cf3f 100644 --- a/pkg/kubelet/eviction/helpers_test.go +++ b/pkg/kubelet/eviction/helpers_test.go @@ -25,8 +25,7 @@ import ( "testing" "time" - "k8s.io/apimachinery/pkg/util/diff" - + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -633,7 +632,7 @@ func TestAddAllocatableThresholds(t *testing.T) { for testName, testCase := range testCases { t.Run(testName, func(t *testing.T) { if !thresholdsEqual(testCase.expected, addAllocatableThresholds(testCase.thresholds)) { - t.Errorf("Err not as expected, test: %v, Unexpected data: %s", testName, diff.ObjectDiff(testCase.expected, addAllocatableThresholds(testCase.thresholds))) + t.Errorf("Err not as expected, test: %v, Unexpected data: %s", testName, cmp.Diff(testCase.expected, addAllocatableThresholds(testCase.thresholds))) } }) } diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index e2902fdb7da..50f973a727b 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -32,6 +32,7 @@ import ( "time" cadvisorapi "github.com/google/cadvisor/info/v1" + "github.com/google/go-cmp/cmp" libcontaineruserns "github.com/opencontainers/runc/libcontainer/userns" "github.com/opencontainers/selinux/go-selinux" "go.opentelemetry.io/otel/attribute" @@ -47,7 +48,6 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" @@ -2602,8 +2602,7 @@ func isPodResizeInProgress(pod *v1.Pod, podStatus *v1.PodStatus) bool { if cs.Resources == nil { continue } - if diff.ObjectDiff(c.Resources.Limits, cs.Resources.Limits) != "" || - diff.ObjectDiff(cs.AllocatedResources, cs.Resources.Requests) != "" { + if !cmp.Equal(c.Resources.Limits, cs.Resources.Limits) || !cmp.Equal(cs.AllocatedResources, cs.Resources.Requests) { return true } } @@ -2673,7 +2672,7 @@ func (kl *Kubelet) handlePodResourcesResize(pod *v1.Pod) *v1.Pod { klog.V(5).InfoS("ContainerStatus.AllocatedResources length mismatch", "pod", pod.Name, "container", container.Name) break } - if len(diff.ObjectDiff(container.Resources.Requests, containerStatus.AllocatedResources)) > 0 { + if !cmp.Equal(container.Resources.Requests, containerStatus.AllocatedResources) { podResized = true break } diff --git a/pkg/kubelet/kubelet_node_status_test.go b/pkg/kubelet/kubelet_node_status_test.go index 61cb729e683..106843e11f4 100644 --- a/pkg/kubelet/kubelet_node_status_test.go +++ b/pkg/kubelet/kubelet_node_status_test.go @@ -33,13 +33,13 @@ import ( "github.com/stretchr/testify/require" cadvisorapi "github.com/google/cadvisor/info/v1" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/rand" "k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/uuid" @@ -310,7 +310,7 @@ func TestUpdateNewNodeStatus(t *testing.T) { assert.Equal(t, v1.NodeReady, updatedNode.Status.Conditions[len(updatedNode.Status.Conditions)-1].Type, "NotReady should be last") assert.Len(t, updatedNode.Status.Images, len(expectedImageList)) - assert.True(t, apiequality.Semantic.DeepEqual(expectedNode, updatedNode), "%s", diff.ObjectDiff(expectedNode, updatedNode)) + assert.True(t, apiequality.Semantic.DeepEqual(expectedNode, updatedNode), "%s", cmp.Diff(expectedNode, updatedNode)) }) } } @@ -504,7 +504,7 @@ func TestUpdateExistingNodeStatus(t *testing.T) { // Version skew workaround. See: https://github.com/kubernetes/kubernetes/issues/16961 assert.Equal(t, v1.NodeReady, updatedNode.Status.Conditions[len(updatedNode.Status.Conditions)-1].Type, "NodeReady should be the last condition") - assert.True(t, apiequality.Semantic.DeepEqual(expectedNode, updatedNode), "%s", diff.ObjectDiff(expectedNode, updatedNode)) + assert.True(t, apiequality.Semantic.DeepEqual(expectedNode, updatedNode), "%s", cmp.Diff(expectedNode, updatedNode)) } func TestUpdateExistingNodeStatusTimeout(t *testing.T) { @@ -714,7 +714,7 @@ func TestUpdateNodeStatusWithRuntimeStateError(t *testing.T) { LastHeartbeatTime: metav1.Time{}, LastTransitionTime: metav1.Time{}, } - assert.True(t, apiequality.Semantic.DeepEqual(expectedNode, updatedNode), "%s", diff.ObjectDiff(expectedNode, updatedNode)) + assert.True(t, apiequality.Semantic.DeepEqual(expectedNode, updatedNode), "%s", cmp.Diff(expectedNode, updatedNode)) } // TODO(random-liu): Refactor the unit test to be table driven test. @@ -931,7 +931,7 @@ func TestUpdateNodeStatusWithLease(t *testing.T) { cond.LastHeartbeatTime = cond.LastHeartbeatTime.Rfc3339Copy() cond.LastTransitionTime = cond.LastTransitionTime.Rfc3339Copy() } - assert.True(t, apiequality.Semantic.DeepEqual(expectedNode, updatedNode), "%s", diff.ObjectDiff(expectedNode, updatedNode)) + assert.True(t, apiequality.Semantic.DeepEqual(expectedNode, updatedNode), "%s", cmp.Diff(expectedNode, updatedNode)) // Version skew workaround. See: https://github.com/kubernetes/kubernetes/issues/16961 assert.Equal(t, v1.NodeReady, updatedNode.Status.Conditions[len(updatedNode.Status.Conditions)-1].Type, @@ -960,7 +960,7 @@ func TestUpdateNodeStatusWithLease(t *testing.T) { for i, cond := range expectedNode.Status.Conditions { expectedNode.Status.Conditions[i].LastHeartbeatTime = metav1.NewTime(cond.LastHeartbeatTime.Time.Add(time.Minute)).Rfc3339Copy() } - assert.True(t, apiequality.Semantic.DeepEqual(expectedNode, updatedNode), "%s", diff.ObjectDiff(expectedNode, updatedNode)) + assert.True(t, apiequality.Semantic.DeepEqual(expectedNode, updatedNode), "%s", cmp.Diff(expectedNode, updatedNode)) // Update node status again when nothing is changed (except heartbeat time). // Do not report node status if it is within the duration of nodeStatusReportFrequency. @@ -1122,14 +1122,14 @@ func TestUpdateNodeStatusAndVolumesInUseWithNodeLease(t *testing.T) { updatedNode, err := applyNodeStatusPatch(tc.existingNode, patchAction.GetPatch()) require.NoError(t, err) - assert.True(t, apiequality.Semantic.DeepEqual(tc.expectedNode, updatedNode), "%s", diff.ObjectDiff(tc.expectedNode, updatedNode)) + assert.True(t, apiequality.Semantic.DeepEqual(tc.expectedNode, updatedNode), "%s", cmp.Diff(tc.expectedNode, updatedNode)) } else { assert.Len(t, actions, 1) assert.IsType(t, core.GetActionImpl{}, actions[0]) } reportedInUse := fakeVolumeManager.GetVolumesReportedInUse() - assert.True(t, apiequality.Semantic.DeepEqual(tc.expectedReportedInUse, reportedInUse), "%s", diff.ObjectDiff(tc.expectedReportedInUse, reportedInUse)) + assert.True(t, apiequality.Semantic.DeepEqual(tc.expectedReportedInUse, reportedInUse), "%s", cmp.Diff(tc.expectedReportedInUse, reportedInUse)) }) } } @@ -1572,7 +1572,7 @@ func TestUpdateNewNodeStatusTooLargeReservation(t *testing.T) { updatedNode, err := applyNodeStatusPatch(&existingNode, actions[1].(core.PatchActionImpl).GetPatch()) assert.NoError(t, err) - assert.True(t, apiequality.Semantic.DeepEqual(expectedNode.Status.Allocatable, updatedNode.Status.Allocatable), "%s", diff.ObjectDiff(expectedNode.Status.Allocatable, updatedNode.Status.Allocatable)) + assert.True(t, apiequality.Semantic.DeepEqual(expectedNode.Status.Allocatable, updatedNode.Status.Allocatable), "%s", cmp.Diff(expectedNode.Status.Allocatable, updatedNode.Status.Allocatable)) } func TestUpdateDefaultLabels(t *testing.T) { @@ -2857,8 +2857,8 @@ func TestNodeStatusHasChanged(t *testing.T) { statusCopy := tc.status.DeepCopy() changed := nodeStatusHasChanged(tc.originalStatus, tc.status) assert.Equal(t, tc.expectChange, changed, "Expect node status change to be %t, but got %t.", tc.expectChange, changed) - assert.True(t, apiequality.Semantic.DeepEqual(originalStatusCopy, tc.originalStatus), "%s", diff.ObjectDiff(originalStatusCopy, tc.originalStatus)) - assert.True(t, apiequality.Semantic.DeepEqual(statusCopy, tc.status), "%s", diff.ObjectDiff(statusCopy, tc.status)) + assert.True(t, apiequality.Semantic.DeepEqual(originalStatusCopy, tc.originalStatus), "%s", cmp.Diff(originalStatusCopy, tc.originalStatus)) + assert.True(t, apiequality.Semantic.DeepEqual(statusCopy, tc.status), "%s", cmp.Diff(statusCopy, tc.status)) }) } } @@ -3012,7 +3012,7 @@ func TestUpdateNodeAddresses(t *testing.T) { updatedNode, err := applyNodeStatusPatch(oldNode, patchAction.GetPatch()) require.NoError(t, err) - assert.True(t, apiequality.Semantic.DeepEqual(updatedNode, expectedNode), "%s", diff.ObjectDiff(expectedNode, updatedNode)) + assert.True(t, apiequality.Semantic.DeepEqual(updatedNode, expectedNode), "%s", cmp.Diff(expectedNode, updatedNode)) }) } } diff --git a/pkg/kubelet/kubelet_pods.go b/pkg/kubelet/kubelet_pods.go index f43a4655da7..7d53bdcf01b 100644 --- a/pkg/kubelet/kubelet_pods.go +++ b/pkg/kubelet/kubelet_pods.go @@ -29,12 +29,12 @@ import ( "sort" "strings" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" utilvalidation "k8s.io/apimachinery/pkg/util/validation" utilfeature "k8s.io/apiserver/pkg/util/feature" @@ -1500,7 +1500,7 @@ func (kl *Kubelet) determinePodResizeStatus(pod *v1.Pod, podStatus *v1.PodStatus specStatusDiffer := false for _, c := range pod.Spec.Containers { if cs, ok := podutil.GetContainerStatus(podStatus.ContainerStatuses, c.Name); ok { - if cs.Resources != nil && diff.ObjectDiff(c.Resources, *cs.Resources) != "" { + if cs.Resources != nil && !cmp.Equal(c.Resources, *cs.Resources) { specStatusDiffer = true break } diff --git a/pkg/kubelet/kubelet_pods_test.go b/pkg/kubelet/kubelet_pods_test.go index b94754553de..753e6959c51 100644 --- a/pkg/kubelet/kubelet_pods_test.go +++ b/pkg/kubelet/kubelet_pods_test.go @@ -40,7 +40,6 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" utilfeature "k8s.io/apiserver/pkg/util/feature" core "k8s.io/client-go/testing" "k8s.io/client-go/tools/record" @@ -3273,7 +3272,7 @@ func Test_generateAPIPodStatus(t *testing.T) { expected.Conditions = append([]v1.PodCondition{test.expectedPodDisruptionCondition}, expected.Conditions...) } if !apiequality.Semantic.DeepEqual(*expected, actual) { - t.Fatalf("Unexpected status: %s", diff.ObjectReflectDiff(*expected, actual)) + t.Fatalf("Unexpected status: %s", cmp.Diff(*expected, actual)) } }) } diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container_linux_test.go b/pkg/kubelet/kuberuntime/kuberuntime_container_linux_test.go index b7bc0ade742..56f1c153951 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container_linux_test.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container_linux_test.go @@ -33,7 +33,6 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" @@ -882,7 +881,7 @@ func TestGenerateLinuxContainerResources(t *testing.T) { } resources := m.generateLinuxContainerResources(pod, &pod.Spec.Containers[0], false) tc.expected.HugepageLimits = resources.HugepageLimits - if diff.ObjectDiff(resources, tc.expected) != "" { + if !cmp.Equal(resources, tc.expected) { t.Errorf("Test %s: expected resources %+v, but got %+v", tc.name, tc.expected, resources) } }) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index 9c9cc56d5ae..16c08f8d2ec 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -26,6 +26,7 @@ import ( "time" cadvisorapi "github.com/google/cadvisor/info/v1" + "github.com/google/go-cmp/cmp" "go.opentelemetry.io/otel/trace" crierror "k8s.io/cri-api/pkg/errors" "k8s.io/klog/v2" @@ -34,7 +35,6 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubetypes "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" utilruntime "k8s.io/apimachinery/pkg/util/runtime" utilversion "k8s.io/apimachinery/pkg/util/version" utilfeature "k8s.io/apiserver/pkg/util/feature" @@ -553,7 +553,7 @@ func (m *kubeGenericRuntimeManager) computePodResizeAction(pod *v1.Pod, containe if !exists || apiContainerStatus.State.Running == nil || apiContainerStatus.Resources == nil || kubeContainerStatus.State != kubecontainer.ContainerStateRunning || kubeContainerStatus.ID.String() != apiContainerStatus.ContainerID || - len(diff.ObjectDiff(container.Resources.Requests, apiContainerStatus.AllocatedResources)) != 0 { + !cmp.Equal(container.Resources.Requests, apiContainerStatus.AllocatedResources) { return true } diff --git a/pkg/kubelet/nodestatus/setters_test.go b/pkg/kubelet/nodestatus/setters_test.go index cc7e70da4f1..2e0a4b68437 100644 --- a/pkg/kubelet/nodestatus/setters_test.go +++ b/pkg/kubelet/nodestatus/setters_test.go @@ -27,12 +27,12 @@ import ( "time" cadvisorapiv1 "github.com/google/cadvisor/info/v1" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/rand" "k8s.io/apimachinery/pkg/util/uuid" cloudprovider "k8s.io/cloud-provider" @@ -579,10 +579,10 @@ func TestNodeAddress(t *testing.T) { } assert.True(t, apiequality.Semantic.DeepEqual(testCase.expectedAddresses, existingNode.Status.Addresses), - "Diff: %s", diff.ObjectDiff(testCase.expectedAddresses, existingNode.Status.Addresses)) + "Diff: %s", cmp.Diff(testCase.expectedAddresses, existingNode.Status.Addresses)) if testCase.expectedAnnotations != nil { assert.True(t, apiequality.Semantic.DeepEqual(testCase.expectedAnnotations, existingNode.Annotations), - "Diff: %s", diff.ObjectDiff(testCase.expectedAnnotations, existingNode.Annotations)) + "Diff: %s", cmp.Diff(testCase.expectedAnnotations, existingNode.Annotations)) } }) } @@ -667,7 +667,7 @@ func TestNodeAddress_NoCloudProvider(t *testing.T) { } assert.True(t, apiequality.Semantic.DeepEqual(testCase.expectedAddresses, existingNode.Status.Addresses), - "Diff: %s", diff.ObjectDiff(testCase.expectedAddresses, existingNode.Status.Addresses)) + "Diff: %s", cmp.Diff(testCase.expectedAddresses, existingNode.Status.Addresses)) }) } } @@ -1149,7 +1149,7 @@ func TestMachineInfo(t *testing.T) { } // check expected node assert.True(t, apiequality.Semantic.DeepEqual(tc.expectNode, tc.node), - "Diff: %s", diff.ObjectDiff(tc.expectNode, tc.node)) + "Diff: %s", cmp.Diff(tc.expectNode, tc.node)) // check expected events require.Equal(t, len(tc.expectEvents), len(events)) for i := range tc.expectEvents { @@ -1239,7 +1239,7 @@ func TestVersionInfo(t *testing.T) { require.Equal(t, tc.expectError, err) // check expected node assert.True(t, apiequality.Semantic.DeepEqual(tc.expectNode, tc.node), - "Diff: %s", diff.ObjectDiff(tc.expectNode, tc.node)) + "Diff: %s", cmp.Diff(tc.expectNode, tc.node)) }) } } @@ -1319,7 +1319,7 @@ func TestImages(t *testing.T) { expectNode.Status.Images = makeExpectedImageList(tc.imageList, tc.maxImages, MaxNamesPerImageInNodeStatus) } assert.True(t, apiequality.Semantic.DeepEqual(expectNode, node), - "Diff: %s", diff.ObjectDiff(expectNode, node)) + "Diff: %s", cmp.Diff(expectNode, node)) }) } @@ -1510,7 +1510,7 @@ func TestReadyCondition(t *testing.T) { } // check expected condition assert.True(t, apiequality.Semantic.DeepEqual(tc.expectConditions, tc.node.Status.Conditions), - "Diff: %s", diff.ObjectDiff(tc.expectConditions, tc.node.Status.Conditions)) + "Diff: %s", cmp.Diff(tc.expectConditions, tc.node.Status.Conditions)) // check expected events require.Equal(t, len(tc.expectEvents), len(events)) for i := range tc.expectEvents { @@ -1632,7 +1632,7 @@ func TestMemoryPressureCondition(t *testing.T) { } // check expected condition assert.True(t, apiequality.Semantic.DeepEqual(tc.expectConditions, tc.node.Status.Conditions), - "Diff: %s", diff.ObjectDiff(tc.expectConditions, tc.node.Status.Conditions)) + "Diff: %s", cmp.Diff(tc.expectConditions, tc.node.Status.Conditions)) // check expected events require.Equal(t, len(tc.expectEvents), len(events)) for i := range tc.expectEvents { @@ -1754,7 +1754,7 @@ func TestPIDPressureCondition(t *testing.T) { } // check expected condition assert.True(t, apiequality.Semantic.DeepEqual(tc.expectConditions, tc.node.Status.Conditions), - "Diff: %s", diff.ObjectDiff(tc.expectConditions, tc.node.Status.Conditions)) + "Diff: %s", cmp.Diff(tc.expectConditions, tc.node.Status.Conditions)) // check expected events require.Equal(t, len(tc.expectEvents), len(events)) for i := range tc.expectEvents { @@ -1876,7 +1876,7 @@ func TestDiskPressureCondition(t *testing.T) { } // check expected condition assert.True(t, apiequality.Semantic.DeepEqual(tc.expectConditions, tc.node.Status.Conditions), - "Diff: %s", diff.ObjectDiff(tc.expectConditions, tc.node.Status.Conditions)) + "Diff: %s", cmp.Diff(tc.expectConditions, tc.node.Status.Conditions)) // check expected events require.Equal(t, len(tc.expectEvents), len(events)) for i := range tc.expectEvents { @@ -1933,7 +1933,7 @@ func TestVolumesInUse(t *testing.T) { } // check expected volumes assert.True(t, apiequality.Semantic.DeepEqual(tc.expectVolumesInUse, tc.node.Status.VolumesInUse), - "Diff: %s", diff.ObjectDiff(tc.expectVolumesInUse, tc.node.Status.VolumesInUse)) + "Diff: %s", cmp.Diff(tc.expectVolumesInUse, tc.node.Status.VolumesInUse)) }) } } @@ -1997,7 +1997,7 @@ func TestVolumeLimits(t *testing.T) { } // check expected node assert.True(t, apiequality.Semantic.DeepEqual(tc.expectNode, node), - "Diff: %s", diff.ObjectDiff(tc.expectNode, node)) + "Diff: %s", cmp.Diff(tc.expectNode, node)) }) } } diff --git a/pkg/kubelet/pleg/generic_test.go b/pkg/kubelet/pleg/generic_test.go index 001e0e426c8..9b7489d73bd 100644 --- a/pkg/kubelet/pleg/generic_test.go +++ b/pkg/kubelet/pleg/generic_test.go @@ -27,10 +27,10 @@ import ( "time" "github.com/golang/mock/gomock" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/component-base/metrics/testutil" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" containertest "k8s.io/kubernetes/pkg/kubelet/container/testing" @@ -101,7 +101,7 @@ func verifyEvents(t *testing.T, expected, actual []*PodLifecycleEvent) { sort.Sort(sortableEvents(expected)) sort.Sort(sortableEvents(actual)) if !reflect.DeepEqual(expected, actual) { - t.Errorf("Actual events differ from the expected; diff:\n %v", diff.ObjectDiff(expected, actual)) + t.Errorf("Actual events differ from the expected; diff:\n %v", cmp.Diff(expected, actual)) } } diff --git a/pkg/kubelet/status/status_manager.go b/pkg/kubelet/status/status_manager.go index 728b438a465..52c93d3db66 100644 --- a/pkg/kubelet/status/status_manager.go +++ b/pkg/kubelet/status/status_manager.go @@ -25,6 +25,7 @@ import ( "sync" "time" + "github.com/google/go-cmp/cmp" clientset "k8s.io/client-go/kubernetes" v1 "k8s.io/api/core/v1" @@ -32,7 +33,6 @@ import ( "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/wait" utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/klog/v2" @@ -937,7 +937,7 @@ func (m *manager) needsReconcile(uid types.UID, status v1.PodStatus) bool { } klog.V(3).InfoS("Pod status is inconsistent with cached status for pod, a reconciliation should be triggered", "pod", klog.KObj(pod), - "statusDiff", diff.ObjectDiff(podStatus, &status)) + "statusDiff", cmp.Diff(podStatus, &status)) return true } diff --git a/pkg/kubelet/status/status_manager_test.go b/pkg/kubelet/status/status_manager_test.go index 443c7d829cc..0110d4c12db 100644 --- a/pkg/kubelet/status/status_manager_test.go +++ b/pkg/kubelet/status/status_manager_test.go @@ -35,7 +35,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" utilfeature "k8s.io/apiserver/pkg/util/feature" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/fake" @@ -613,7 +612,7 @@ func TestTerminatePod(t *testing.T) { expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: "ContainerStatusUnknown", Message: "The container could not be located when the pod was terminated", ExitCode: 137}} if !reflect.DeepEqual(newStatus.InitContainerStatuses[0].State, expectUnknownState) { - t.Errorf("terminated container state not defaulted: %s", diff.ObjectReflectDiff(newStatus.InitContainerStatuses[0].State, expectUnknownState)) + t.Errorf("terminated container state not defaulted: %s", cmp.Diff(newStatus.InitContainerStatuses[0].State, expectUnknownState)) } if !reflect.DeepEqual(newStatus.InitContainerStatuses[1].State, firstStatus.InitContainerStatuses[1].State) { t.Errorf("existing terminated container state not preserved: %#v", newStatus.ContainerStatuses) @@ -622,7 +621,7 @@ func TestTerminatePod(t *testing.T) { t.Errorf("existing terminated container state not preserved: %#v", newStatus.ContainerStatuses) } if !reflect.DeepEqual(newStatus.ContainerStatuses[0].State, expectUnknownState) { - t.Errorf("terminated container state not defaulted: %s", diff.ObjectReflectDiff(newStatus.ContainerStatuses[0].State, expectUnknownState)) + t.Errorf("terminated container state not defaulted: %s", cmp.Diff(newStatus.ContainerStatuses[0].State, expectUnknownState)) } if !reflect.DeepEqual(newStatus.ContainerStatuses[1].State, firstStatus.ContainerStatuses[1].State) { t.Errorf("existing terminated container state not preserved: %#v", newStatus.ContainerStatuses) @@ -674,22 +673,22 @@ func TestTerminatePodWaiting(t *testing.T) { expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: "ContainerStatusUnknown", Message: "The container could not be located when the pod was terminated", ExitCode: 137}} if !reflect.DeepEqual(newStatus.InitContainerStatuses[0].State, expectUnknownState) { - t.Errorf("terminated container state not defaulted: %s", diff.ObjectReflectDiff(newStatus.InitContainerStatuses[0].State, expectUnknownState)) + t.Errorf("terminated container state not defaulted: %s", cmp.Diff(newStatus.InitContainerStatuses[0].State, expectUnknownState)) } if !reflect.DeepEqual(newStatus.InitContainerStatuses[1].State, firstStatus.InitContainerStatuses[1].State) { t.Errorf("existing terminated container state not preserved: %#v", newStatus.ContainerStatuses) } if !reflect.DeepEqual(newStatus.InitContainerStatuses[2].State, firstStatus.InitContainerStatuses[2].State) { - t.Errorf("waiting container state not defaulted: %s", diff.ObjectReflectDiff(newStatus.InitContainerStatuses[2].State, firstStatus.InitContainerStatuses[2].State)) + t.Errorf("waiting container state not defaulted: %s", cmp.Diff(newStatus.InitContainerStatuses[2].State, firstStatus.InitContainerStatuses[2].State)) } if !reflect.DeepEqual(newStatus.ContainerStatuses[0].State, expectUnknownState) { - t.Errorf("terminated container state not defaulted: %s", diff.ObjectReflectDiff(newStatus.ContainerStatuses[0].State, expectUnknownState)) + t.Errorf("terminated container state not defaulted: %s", cmp.Diff(newStatus.ContainerStatuses[0].State, expectUnknownState)) } if !reflect.DeepEqual(newStatus.ContainerStatuses[1].State, firstStatus.ContainerStatuses[1].State) { t.Errorf("existing terminated container state not preserved: %#v", newStatus.ContainerStatuses) } if !reflect.DeepEqual(newStatus.ContainerStatuses[2].State, expectUnknownState) { - t.Errorf("waiting container state not defaulted: %s", diff.ObjectReflectDiff(newStatus.ContainerStatuses[2].State, expectUnknownState)) + t.Errorf("waiting container state not defaulted: %s", cmp.Diff(newStatus.ContainerStatuses[2].State, expectUnknownState)) } t.Logf("we expect the previous status update to be preserved.") diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index f4fa0bf4012..bc9d2be7dc6 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -24,10 +24,10 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/util/certificate/csr" "k8s.io/kubernetes/pkg/apis/admissionregistration" @@ -293,7 +293,7 @@ func TestPrintEvent(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -394,7 +394,7 @@ func TestPrintNamespace(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -442,7 +442,7 @@ func TestPrintSecret(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -490,7 +490,7 @@ func TestPrintServiceAccount(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -590,7 +590,7 @@ func TestPrintNodeStatus(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -639,7 +639,7 @@ func TestPrintNodeRole(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -691,7 +691,7 @@ func TestPrintNodeOSImage(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -743,7 +743,7 @@ func TestPrintNodeKernelVersion(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -795,7 +795,7 @@ func TestPrintNodeContainerRuntimeVersion(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -832,7 +832,7 @@ func TestPrintNodeName(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -893,7 +893,7 @@ func TestPrintNodeExternalIP(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -955,7 +955,7 @@ func TestPrintNodeInternalIP(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -998,7 +998,7 @@ func TestPrintIngress(t *testing.T) { } rows[0].Object.Object = nil if !reflect.DeepEqual(expected, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(expected, rows)) + t.Errorf("mismatch: %s", cmp.Diff(expected, rows)) } } @@ -1061,7 +1061,7 @@ func TestPrintIngressClass(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(testCase.expected, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(testCase.expected, rows)) + t.Errorf("mismatch: %s", cmp.Diff(testCase.expected, rows)) } }) } @@ -1171,7 +1171,7 @@ func TestPrintServiceLoadBalancer(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -1531,7 +1531,7 @@ func TestPrintPod(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expect, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expect, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expect, rows)) } } } @@ -1655,7 +1655,7 @@ func TestPrintPodwide(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expect, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expect, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expect, rows)) } } } @@ -1737,7 +1737,7 @@ func TestPrintPodConditions(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expect, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expect, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expect, rows)) } } } @@ -1788,7 +1788,7 @@ func TestPrintPodList(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expect, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(test.expect, rows)) + t.Errorf("mismatch: %s", cmp.Diff(test.expect, rows)) } } } @@ -1899,7 +1899,7 @@ func TestPrintNonTerminatedPod(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expect, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expect, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expect, rows)) } } } @@ -1981,7 +1981,7 @@ func TestPrintPodTemplate(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -2031,7 +2031,7 @@ func TestPrintPodTemplateList(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(expectedRows, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(expectedRows, rows)) + t.Errorf("mismatch: %s", cmp.Diff(expectedRows, rows)) } } @@ -2148,7 +2148,7 @@ func TestPrintDeployment(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -2216,7 +2216,7 @@ func TestPrintDaemonSet(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -2288,7 +2288,7 @@ func TestPrintDaemonSetList(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(expectedRows, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(expectedRows, rows)) + t.Errorf("mismatch: %s", cmp.Diff(expectedRows, rows)) } } @@ -2437,7 +2437,7 @@ func TestPrintJob(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -2518,7 +2518,7 @@ func TestPrintJobList(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(expectedRows, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(expectedRows, rows)) + t.Errorf("mismatch: %s", cmp.Diff(expectedRows, rows)) } } @@ -3290,7 +3290,7 @@ func TestPrintHPA(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -3490,7 +3490,7 @@ func TestPrintService(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -3541,7 +3541,7 @@ func TestPrintServiceList(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(expectedRows, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(expectedRows, rows)) + t.Errorf("mismatch: %s", cmp.Diff(expectedRows, rows)) } } @@ -3598,7 +3598,7 @@ func TestPrintPodDisruptionBudget(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -3652,7 +3652,7 @@ func TestPrintPodDisruptionBudgetList(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(expectedRows, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(expectedRows, rows)) + t.Errorf("mismatch: %s", cmp.Diff(expectedRows, rows)) } } @@ -3729,7 +3729,7 @@ func TestPrintControllerRevision(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -3796,7 +3796,7 @@ func TestPrintConfigMap(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -3843,7 +3843,7 @@ func TestPrintNetworkPolicy(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -3918,7 +3918,7 @@ func TestPrintRoleBinding(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -3993,7 +3993,7 @@ func TestPrintClusterRoleBinding(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -4135,7 +4135,7 @@ func TestPrintCertificateSigningRequest(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -4262,7 +4262,7 @@ func TestPrintReplicationController(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -4352,7 +4352,7 @@ func TestPrintReplicaSet(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -4420,7 +4420,7 @@ func TestPrintReplicaSetList(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(expectedRows, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(expectedRows, rows)) + t.Errorf("mismatch: %s", cmp.Diff(expectedRows, rows)) } } @@ -4507,7 +4507,7 @@ func TestPrintStatefulSet(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -4651,7 +4651,7 @@ func TestPrintPersistentVolume(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -4774,7 +4774,7 @@ func TestPrintPersistentVolumeClaim(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -4842,7 +4842,7 @@ func TestPrintComponentStatus(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -4980,7 +4980,7 @@ func TestPrintCronJob(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -5046,7 +5046,7 @@ func TestPrintCronJobList(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(expectedRows, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(expectedRows, rows)) + t.Errorf("mismatch: %s", cmp.Diff(expectedRows, rows)) } } @@ -5144,7 +5144,7 @@ func TestPrintStorageClass(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -5191,7 +5191,7 @@ func TestPrintLease(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -5233,7 +5233,7 @@ func TestPrintPriorityClass(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -5274,7 +5274,7 @@ func TestPrintRuntimeClass(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -5394,7 +5394,7 @@ func TestPrintEndpoint(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } @@ -5493,7 +5493,7 @@ func TestPrintEndpointSlice(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -5641,7 +5641,7 @@ func TestPrintFlowSchema(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -5718,7 +5718,7 @@ func TestPrintPriorityLevelConfiguration(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -5840,7 +5840,7 @@ func TestPrintStorageVersion(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -5877,7 +5877,7 @@ func TestPrintScale(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -6399,7 +6399,7 @@ func TestPrintClusterCIDR(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("%d mismatch: %s", i, diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("%d mismatch: %s", i, cmp.Diff(test.expected, rows)) } } } @@ -6478,7 +6478,7 @@ func TestPrintClusterCIDRList(t *testing.T) { rows[i].Object.Object = nil } if !reflect.DeepEqual(test.expected, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(test.expected, rows)) + t.Errorf("mismatch: %s", cmp.Diff(test.expected, rows)) } } } @@ -6507,7 +6507,7 @@ func TestPrintIPAddress(t *testing.T) { } rows[0].Object.Object = nil if !reflect.DeepEqual(expected, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(expected, rows)) + t.Errorf("mismatch: %s", cmp.Diff(expected, rows)) } } @@ -6558,7 +6558,7 @@ func TestPrintIPAddressList(t *testing.T) { } if !reflect.DeepEqual(expected, rows) { - t.Errorf("mismatch: %s", diff.ObjectReflectDiff(expected, rows)) + t.Errorf("mismatch: %s", cmp.Diff(expected, rows)) } } diff --git a/pkg/registry/apps/deployment/storage/storage_test.go b/pkg/registry/apps/deployment/storage/storage_test.go index d7b371040d2..460abc155e2 100644 --- a/pkg/registry/apps/deployment/storage/storage_test.go +++ b/pkg/registry/apps/deployment/storage/storage_test.go @@ -25,13 +25,13 @@ import ( "sync" "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/intstr" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" @@ -242,7 +242,7 @@ func TestScaleGet(t *testing.T) { } got := obj.(*autoscaling.Scale) if !apiequality.Semantic.DeepEqual(want, got) { - t.Errorf("unexpected scale: %s", diff.ObjectDiff(want, got)) + t.Errorf("unexpected scale: %s", cmp.Diff(want, got)) } } diff --git a/pkg/registry/apps/replicaset/storage/storage_test.go b/pkg/registry/apps/replicaset/storage/storage_test.go index 392c1f95b21..d1ee204745e 100644 --- a/pkg/registry/apps/replicaset/storage/storage_test.go +++ b/pkg/registry/apps/replicaset/storage/storage_test.go @@ -22,13 +22,13 @@ import ( "sync" "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" @@ -297,7 +297,7 @@ func TestScaleGet(t *testing.T) { t.Fatalf("error fetching scale for %s: %v", name, err) } if !apiequality.Semantic.DeepEqual(got, want) { - t.Errorf("unexpected scale: %s", diff.ObjectDiff(got, want)) + t.Errorf("unexpected scale: %s", cmp.Diff(got, want)) } } diff --git a/pkg/registry/apps/statefulset/storage/storage_test.go b/pkg/registry/apps/statefulset/storage/storage_test.go index cdce909bd77..d19db00fe44 100644 --- a/pkg/registry/apps/statefulset/storage/storage_test.go +++ b/pkg/registry/apps/statefulset/storage/storage_test.go @@ -22,13 +22,13 @@ import ( "sync" "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" @@ -247,7 +247,7 @@ func TestScaleGet(t *testing.T) { t.Fatalf("error fetching scale for %s: %v", name, err) } if !apiequality.Semantic.DeepEqual(got, want) { - t.Errorf("unexpected scale: %s", diff.ObjectDiff(got, want)) + t.Errorf("unexpected scale: %s", cmp.Diff(got, want)) } } diff --git a/pkg/registry/autoscaling/horizontalpodautoscaler/storage/storage_test.go b/pkg/registry/autoscaling/horizontalpodautoscaler/storage/storage_test.go index 589932db37f..2f35e1328c8 100644 --- a/pkg/registry/autoscaling/horizontalpodautoscaler/storage/storage_test.go +++ b/pkg/registry/autoscaling/horizontalpodautoscaler/storage/storage_test.go @@ -19,16 +19,17 @@ package storage import ( "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/apis/autoscaling" api "k8s.io/kubernetes/pkg/apis/core" + // Ensure that autoscaling/v1 package is initialized. _ "k8s.io/api/autoscaling/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" @@ -211,6 +212,6 @@ func TestUpdateStatus(t *testing.T) { autoscalerOut := obj.(*autoscaling.HorizontalPodAutoscaler) // only compare the meaningful update b/c we can't compare due to metadata if !apiequality.Semantic.DeepEqual(autoscalerIn.Status, autoscalerOut.Status) { - t.Errorf("unexpected object: %s", diff.ObjectDiff(autoscalerIn, autoscalerOut)) + t.Errorf("unexpected object: %s", cmp.Diff(autoscalerIn, autoscalerOut)) } } diff --git a/pkg/registry/certificates/certificates/strategy_test.go b/pkg/registry/certificates/certificates/strategy_test.go index 454295d3319..746427eb7bd 100644 --- a/pkg/registry/certificates/certificates/strategy_test.go +++ b/pkg/registry/certificates/certificates/strategy_test.go @@ -22,9 +22,9 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apiserver/pkg/authentication/user" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" certapi "k8s.io/kubernetes/pkg/apis/certificates" @@ -137,7 +137,7 @@ func TestStrategyCreate(t *testing.T) { obj := tc.obj Strategy.PrepareForCreate(tc.ctx, obj) if !reflect.DeepEqual(obj, tc.expectedObj) { - t.Errorf("object diff: %s", diff.ObjectDiff(obj, tc.expectedObj)) + t.Errorf("object diff: %s", cmp.Diff(obj, tc.expectedObj)) } }) } @@ -225,7 +225,7 @@ func TestStatusUpdate(t *testing.T) { obj := tt.newObj.DeepCopy() StatusStrategy.PrepareForUpdate(context.TODO(), obj, tt.oldObj.DeepCopy()) if !reflect.DeepEqual(obj, tt.expectedObj) { - t.Errorf("object diff: %s", diff.ObjectDiff(obj, tt.expectedObj)) + t.Errorf("object diff: %s", cmp.Diff(obj, tt.expectedObj)) } }) } diff --git a/pkg/registry/core/componentstatus/rest_test.go b/pkg/registry/core/componentstatus/rest_test.go index 7215a31a091..d5fdb1ac306 100644 --- a/pkg/registry/core/componentstatus/rest_test.go +++ b/pkg/registry/core/componentstatus/rest_test.go @@ -22,6 +22,7 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" @@ -30,7 +31,6 @@ import ( "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/probe" @@ -87,7 +87,7 @@ func TestList_NoError(t *testing.T) { Items: []api.ComponentStatus{*(createTestStatus("test1", api.ConditionTrue, "ok", ""))}, } if e, a := expect, got; !reflect.DeepEqual(e, a) { - t.Errorf("Got unexpected object. Diff: %s", diff.ObjectDiff(e, a)) + t.Errorf("Got unexpected object. Diff: %s", cmp.Diff(e, a)) } } @@ -106,7 +106,7 @@ func TestList_WithLabelSelectors(t *testing.T) { Items: []api.ComponentStatus{}, } if e, a := expect, got; !reflect.DeepEqual(e, a) { - t.Errorf("Got unexpected object. Diff: %s", diff.ObjectDiff(e, a)) + t.Errorf("Got unexpected object. Diff: %s", cmp.Diff(e, a)) } } @@ -125,7 +125,7 @@ func TestList_WithFieldSelectors(t *testing.T) { Items: []api.ComponentStatus{}, } if e, a := expect, got; !reflect.DeepEqual(e, a) { - t.Errorf("Got unexpected object. Diff: %s", diff.ObjectDiff(e, a)) + t.Errorf("Got unexpected object. Diff: %s", cmp.Diff(e, a)) } } @@ -140,7 +140,7 @@ func TestList_FailedCheck(t *testing.T) { *(createTestStatus("test1", api.ConditionFalse, "", ""))}, } if e, a := expect, got; !reflect.DeepEqual(e, a) { - t.Errorf("Got unexpected object. Diff: %s", diff.ObjectDiff(e, a)) + t.Errorf("Got unexpected object. Diff: %s", cmp.Diff(e, a)) } } @@ -155,7 +155,7 @@ func TestList_UnknownError(t *testing.T) { *(createTestStatus("test1", api.ConditionUnknown, "", "fizzbuzz error"))}, } if e, a := expect, got; !reflect.DeepEqual(e, a) { - t.Errorf("Got unexpected object. Diff: %s", diff.ObjectDiff(e, a)) + t.Errorf("Got unexpected object. Diff: %s", cmp.Diff(e, a)) } } @@ -167,7 +167,7 @@ func TestGet_NoError(t *testing.T) { } expect := createTestStatus("test1", api.ConditionTrue, "ok", "") if e, a := expect, got; !reflect.DeepEqual(e, a) { - t.Errorf("Got unexpected object. Diff: %s", diff.ObjectDiff(e, a)) + t.Errorf("Got unexpected object. Diff: %s", cmp.Diff(e, a)) } } diff --git a/pkg/registry/core/event/strategy_test.go b/pkg/registry/core/event/strategy_test.go index dc1dbb7e8bd..592fa253ef5 100644 --- a/pkg/registry/core/event/strategy_test.go +++ b/pkg/registry/core/event/strategy_test.go @@ -21,9 +21,9 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/util/diff" apitesting "k8s.io/kubernetes/pkg/api/testing" api "k8s.io/kubernetes/pkg/apis/core" @@ -67,7 +67,7 @@ func TestGetAttrs(t *testing.T) { "type": api.EventTypeNormal, } if e, a := expectA, field; !reflect.DeepEqual(e, a) { - t.Errorf("diff: %s", diff.ObjectDiff(e, a)) + t.Errorf("diff: %s", cmp.Diff(e, a)) } eventB := &api.Event{ @@ -105,7 +105,7 @@ func TestGetAttrs(t *testing.T) { "type": api.EventTypeNormal, } if e, a := expectB, field; !reflect.DeepEqual(e, a) { - t.Errorf("diff: %s", diff.ObjectDiff(e, a)) + t.Errorf("diff: %s", cmp.Diff(e, a)) } } diff --git a/pkg/registry/core/node/strategy_test.go b/pkg/registry/core/node/strategy_test.go index a6c2428807c..bf5aa74bf1b 100644 --- a/pkg/registry/core/node/strategy_test.go +++ b/pkg/registry/core/node/strategy_test.go @@ -22,11 +22,11 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/util/diff" apitesting "k8s.io/kubernetes/pkg/api/testing" api "k8s.io/kubernetes/pkg/apis/core" @@ -167,11 +167,11 @@ func TestDropFields(t *testing.T) { old := tc.oldNode.DeepCopy() // old node should never be changed if !reflect.DeepEqual(tc.oldNode, old) { - t.Errorf("%v: old node changed: %v", tc.name, diff.ObjectReflectDiff(tc.oldNode, old)) + t.Errorf("%v: old node changed: %v", tc.name, cmp.Diff(tc.oldNode, old)) } if !reflect.DeepEqual(tc.node, tc.compareNode) { - t.Errorf("%v: unexpected node spec: %v", tc.name, diff.ObjectReflectDiff(tc.node, tc.compareNode)) + t.Errorf("%v: unexpected node spec: %v", tc.name, cmp.Diff(tc.node, tc.compareNode)) } }() } diff --git a/pkg/registry/core/persistentvolume/storage/storage_test.go b/pkg/registry/core/persistentvolume/storage/storage_test.go index c03fa3248a9..271a459d2a1 100644 --- a/pkg/registry/core/persistentvolume/storage/storage_test.go +++ b/pkg/registry/core/persistentvolume/storage/storage_test.go @@ -19,13 +19,13 @@ package storage import ( "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" @@ -197,7 +197,7 @@ func TestUpdateStatus(t *testing.T) { pvOut := obj.(*api.PersistentVolume) // only compare the relevant change b/c metadata will differ if !apiequality.Semantic.DeepEqual(pvIn.Status, pvOut.Status) { - t.Errorf("unexpected object: %s", diff.ObjectDiff(pvIn.Status, pvOut.Status)) + t.Errorf("unexpected object: %s", cmp.Diff(pvIn.Status, pvOut.Status)) } } diff --git a/pkg/registry/core/persistentvolumeclaim/storage/storage_test.go b/pkg/registry/core/persistentvolumeclaim/storage/storage_test.go index 54c0ca625f5..21b2d4fd55b 100644 --- a/pkg/registry/core/persistentvolumeclaim/storage/storage_test.go +++ b/pkg/registry/core/persistentvolumeclaim/storage/storage_test.go @@ -20,13 +20,13 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" @@ -200,7 +200,7 @@ func TestUpdateStatus(t *testing.T) { pvcOut := obj.(*api.PersistentVolumeClaim) // only compare relevant changes b/c of difference in metadata if !apiequality.Semantic.DeepEqual(pvc.Status, pvcOut.Status) { - t.Errorf("unexpected object: %s", diff.ObjectDiff(pvc.Status, pvcOut.Status)) + t.Errorf("unexpected object: %s", cmp.Diff(pvc.Status, pvcOut.Status)) } } diff --git a/pkg/registry/core/persistentvolumeclaim/strategy_test.go b/pkg/registry/core/persistentvolumeclaim/strategy_test.go index a868b8bb922..6b7cc0eee5b 100644 --- a/pkg/registry/core/persistentvolumeclaim/strategy_test.go +++ b/pkg/registry/core/persistentvolumeclaim/strategy_test.go @@ -21,7 +21,7 @@ import ( "reflect" "testing" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" utilfeature "k8s.io/apiserver/pkg/util/feature" featuregatetesting "k8s.io/component-base/featuregate/testing" @@ -86,19 +86,19 @@ func TestDropConditions(t *testing.T) { // old pvc should never be changed if !reflect.DeepEqual(oldPvc, oldPvcInfo.pvc()) { - t.Errorf("old pvc changed: %v", diff.ObjectReflectDiff(oldPvc, oldPvcInfo.pvc())) + t.Errorf("old pvc changed: %v", cmp.Diff(oldPvc, oldPvcInfo.pvc())) } switch { case oldPvcHasConditins || newPvcHasConditions: // new pvc should not be changed if the feature is enabled, or if the old pvc had Conditions if !reflect.DeepEqual(newPvc, newPvcInfo.pvc()) { - t.Errorf("new pvc changed: %v", diff.ObjectReflectDiff(newPvc, newPvcInfo.pvc())) + t.Errorf("new pvc changed: %v", cmp.Diff(newPvc, newPvcInfo.pvc())) } default: // new pvc should not need to be changed if !reflect.DeepEqual(newPvc, newPvcInfo.pvc()) { - t.Errorf("new pvc changed: %v", diff.ObjectReflectDiff(newPvc, newPvcInfo.pvc())) + t.Errorf("new pvc changed: %v", cmp.Diff(newPvc, newPvcInfo.pvc())) } } }) diff --git a/pkg/registry/core/pod/storage/storage_test.go b/pkg/registry/core/pod/storage/storage_test.go index 24d1e9de8fc..03c6de35372 100644 --- a/pkg/registry/core/pod/storage/storage_test.go +++ b/pkg/registry/core/pod/storage/storage_test.go @@ -25,6 +25,7 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" @@ -33,7 +34,6 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" @@ -609,7 +609,7 @@ func TestConvertToTableList(t *testing.T) { continue } if !apiequality.Semantic.DeepEqual(test.out, out) { - t.Errorf("%d: mismatch: %s", i, diff.ObjectReflectDiff(test.out, out)) + t.Errorf("%d: mismatch: %s", i, cmp.Diff(test.out, out)) } } } @@ -1074,7 +1074,7 @@ func TestEtcdUpdateNotScheduled(t *testing.T) { podOut := obj.(*api.Pod) // validChangedPod only changes the Labels, so were checking the update was valid if !apiequality.Semantic.DeepEqual(podIn.Labels, podOut.Labels) { - t.Errorf("objects differ: %v", diff.ObjectDiff(podOut, podIn)) + t.Errorf("objects differ: %v", cmp.Diff(podOut, podIn)) } } @@ -1147,7 +1147,7 @@ func TestEtcdUpdateScheduled(t *testing.T) { podOut := obj.(*api.Pod) // Check to verify the Spec and Label updates match from change above. Those are the fields changed. if !apiequality.Semantic.DeepEqual(podOut.Spec, podIn.Spec) || !apiequality.Semantic.DeepEqual(podOut.Labels, podIn.Labels) { - t.Errorf("objects differ: %v", diff.ObjectDiff(podOut, podIn)) + t.Errorf("objects differ: %v", cmp.Diff(podOut, podIn)) } } @@ -1262,7 +1262,7 @@ func TestEtcdUpdateStatus(t *testing.T) { if !apiequality.Semantic.DeepEqual(podOut.Spec, expected.Spec) || !apiequality.Semantic.DeepEqual(podOut.Labels, expected.Labels) || !apiequality.Semantic.DeepEqual(podOut.Status, expected.Status) { - t.Errorf("objects differ: %v", diff.ObjectDiff(podOut, expected)) + t.Errorf("objects differ: %v", cmp.Diff(podOut, expected)) } } } diff --git a/pkg/registry/core/replicationcontroller/storage/storage_test.go b/pkg/registry/core/replicationcontroller/storage/storage_test.go index 009fed33b1a..e6b3934537d 100644 --- a/pkg/registry/core/replicationcontroller/storage/storage_test.go +++ b/pkg/registry/core/replicationcontroller/storage/storage_test.go @@ -22,13 +22,13 @@ import ( "sync" "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" @@ -294,7 +294,7 @@ func TestScaleGet(t *testing.T) { } got := obj.(*autoscaling.Scale) if !apiequality.Semantic.DeepEqual(want, got) { - t.Errorf("unexpected scale: %s", diff.ObjectDiff(want, got)) + t.Errorf("unexpected scale: %s", cmp.Diff(want, got)) } } diff --git a/pkg/registry/core/resourcequota/storage/storage_test.go b/pkg/registry/core/resourcequota/storage/storage_test.go index 9b750553f83..a15066a427e 100644 --- a/pkg/registry/core/resourcequota/storage/storage_test.go +++ b/pkg/registry/core/resourcequota/storage/storage_test.go @@ -19,12 +19,12 @@ package storage import ( "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" @@ -206,7 +206,7 @@ func TestUpdateStatus(t *testing.T) { rqOut := obj.(*api.ResourceQuota) // only compare the meaningful update b/c we can't compare due to metadata if !apiequality.Semantic.DeepEqual(resourcequotaIn.Status, rqOut.Status) { - t.Errorf("unexpected object: %s", diff.ObjectDiff(resourcequotaIn, rqOut)) + t.Errorf("unexpected object: %s", cmp.Diff(resourcequotaIn, rqOut)) } } diff --git a/pkg/registry/core/service/strategy_test.go b/pkg/registry/core/service/strategy_test.go index 97f98eac3d7..a9d123cb0b0 100644 --- a/pkg/registry/core/service/strategy_test.go +++ b/pkg/registry/core/service/strategy_test.go @@ -20,9 +20,9 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/intstr" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/rest" @@ -218,11 +218,11 @@ func TestDropDisabledField(t *testing.T) { // old node should never be changed if !reflect.DeepEqual(tc.oldSvc, old) { - t.Errorf("%v: old svc changed: %v", tc.name, diff.ObjectReflectDiff(tc.oldSvc, old)) + t.Errorf("%v: old svc changed: %v", tc.name, cmp.Diff(tc.oldSvc, old)) } if !reflect.DeepEqual(tc.svc, tc.compareSvc) { - t.Errorf("%v: unexpected svc spec: %v", tc.name, diff.ObjectReflectDiff(tc.svc, tc.compareSvc)) + t.Errorf("%v: unexpected svc spec: %v", tc.name, cmp.Diff(tc.svc, tc.compareSvc)) } }() } diff --git a/pkg/registry/rbac/validation/rule_test.go b/pkg/registry/rbac/validation/rule_test.go index b892f501a36..01c24c6b734 100644 --- a/pkg/registry/rbac/validation/rule_test.go +++ b/pkg/registry/rbac/validation/rule_test.go @@ -23,9 +23,9 @@ import ( "sort" "testing" + "github.com/google/go-cmp/cmp" rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apiserver/pkg/authentication/user" ) @@ -156,7 +156,7 @@ func TestDefaultRuleResolver(t *testing.T) { sort.Sort(byHash(tc.effectiveRules)) if !reflect.DeepEqual(rules, tc.effectiveRules) { - ruleDiff := diff.ObjectDiff(rules, tc.effectiveRules) + ruleDiff := cmp.Diff(rules, tc.effectiveRules) t.Errorf("case %d: %s", i, ruleDiff) } } diff --git a/pkg/registry/resource/podschedulingcontext/storage/storage_test.go b/pkg/registry/resource/podschedulingcontext/storage/storage_test.go index 2f8c3009e18..98f1840aef0 100644 --- a/pkg/registry/resource/podschedulingcontext/storage/storage_test.go +++ b/pkg/registry/resource/podschedulingcontext/storage/storage_test.go @@ -19,12 +19,12 @@ package storage import ( "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" @@ -179,6 +179,6 @@ func TestUpdateStatus(t *testing.T) { schedulingOut := obj.(*resource.PodSchedulingContext) // only compare relevant changes b/c of difference in metadata if !apiequality.Semantic.DeepEqual(schedulingCtx.Status, schedulingOut.Status) { - t.Errorf("unexpected object: %s", diff.ObjectDiff(schedulingCtx.Status, schedulingOut.Status)) + t.Errorf("unexpected object: %s", cmp.Diff(schedulingCtx.Status, schedulingOut.Status)) } } diff --git a/pkg/registry/resource/resourceclaim/storage/storage_test.go b/pkg/registry/resource/resourceclaim/storage/storage_test.go index cc2e1594a45..613d3c80467 100644 --- a/pkg/registry/resource/resourceclaim/storage/storage_test.go +++ b/pkg/registry/resource/resourceclaim/storage/storage_test.go @@ -19,12 +19,12 @@ package storage import ( "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" @@ -177,6 +177,6 @@ func TestUpdateStatus(t *testing.T) { claimOut := obj.(*resource.ResourceClaim) // only compare relevant changes b/c of difference in metadata if !apiequality.Semantic.DeepEqual(claim.Status, claimOut.Status) { - t.Errorf("unexpected object: %s", diff.ObjectDiff(claim.Status, claimOut.Status)) + t.Errorf("unexpected object: %s", cmp.Diff(claim.Status, claimOut.Status)) } } diff --git a/pkg/registry/storage/csistoragecapacity/strategy_test.go b/pkg/registry/storage/csistoragecapacity/strategy_test.go index 04e4cc88510..bcca2f2fb37 100644 --- a/pkg/registry/storage/csistoragecapacity/strategy_test.go +++ b/pkg/registry/storage/csistoragecapacity/strategy_test.go @@ -19,10 +19,10 @@ package csistoragecapacity import ( "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/kubernetes/pkg/apis/storage" ) @@ -80,7 +80,7 @@ func TestCSIStorageCapacityStrategy(t *testing.T) { // Create with status should have kept status and all other fields. if !apiequality.Semantic.DeepEqual(capacity, original) { - t.Errorf("unexpected objects difference after creation: %v", diff.ObjectDiff(original, capacity)) + t.Errorf("unexpected objects difference after creation: %v", cmp.Diff(original, capacity)) } // Update of immutable fields is disallowed diff --git a/pkg/registry/storage/volumeattachment/storage/storage_test.go b/pkg/registry/storage/volumeattachment/storage/storage_test.go index 6ff5c9f749a..44d97acd1b4 100644 --- a/pkg/registry/storage/volumeattachment/storage/storage_test.go +++ b/pkg/registry/storage/volumeattachment/storage/storage_test.go @@ -19,12 +19,12 @@ package storage import ( "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" "k8s.io/apiserver/pkg/registry/generic" genericregistrytest "k8s.io/apiserver/pkg/registry/generic/testing" @@ -194,9 +194,9 @@ func TestEtcdStatusUpdate(t *testing.T) { } attachmentOut := obj.(*storageapi.VolumeAttachment) if !apiequality.Semantic.DeepEqual(attachmentIn.Spec, attachmentOut.Spec) { - t.Errorf("objects differ: %v", diff.ObjectDiff(attachmentOut.Spec, attachmentIn.Spec)) + t.Errorf("objects differ: %v", cmp.Diff(attachmentOut.Spec, attachmentIn.Spec)) } if !apiequality.Semantic.DeepEqual(attachmentIn.Status, attachmentOut.Status) { - t.Errorf("objects differ: %v", diff.ObjectDiff(attachmentOut.Status, attachmentIn.Status)) + t.Errorf("objects differ: %v", cmp.Diff(attachmentOut.Status, attachmentIn.Status)) } } diff --git a/pkg/registry/storage/volumeattachment/strategy_test.go b/pkg/registry/storage/volumeattachment/strategy_test.go index cf3d5e657ba..ae60f8adfdf 100644 --- a/pkg/registry/storage/volumeattachment/strategy_test.go +++ b/pkg/registry/storage/volumeattachment/strategy_test.go @@ -20,10 +20,10 @@ import ( "context" "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" genericapirequest "k8s.io/apiserver/pkg/endpoints/request" api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/pkg/apis/storage" @@ -90,7 +90,7 @@ func TestVolumeAttachmentStrategy(t *testing.T) { statusVolumeAttachment.Status = storage.VolumeAttachmentStatus{Attached: true} Strategy.PrepareForCreate(ctx, statusVolumeAttachment) if !apiequality.Semantic.DeepEqual(statusVolumeAttachment, volumeAttachment) { - t.Errorf("unexpected objects difference after creating with status: %v", diff.ObjectDiff(statusVolumeAttachment, volumeAttachment)) + t.Errorf("unexpected objects difference after creating with status: %v", cmp.Diff(statusVolumeAttachment, volumeAttachment)) } // Update of spec is disallowed @@ -111,7 +111,7 @@ func TestVolumeAttachmentStrategy(t *testing.T) { Strategy.PrepareForUpdate(ctx, statusVolumeAttachment, volumeAttachment) if !apiequality.Semantic.DeepEqual(statusVolumeAttachment, volumeAttachment) { - t.Errorf("unexpected objects difference after modifying status: %v", diff.ObjectDiff(statusVolumeAttachment, volumeAttachment)) + t.Errorf("unexpected objects difference after modifying status: %v", cmp.Diff(statusVolumeAttachment, volumeAttachment)) } } @@ -129,7 +129,7 @@ func TestVolumeAttachmentStrategySourceInlineSpec(t *testing.T) { t.Errorf("InlineVolumeSpec unexpectedly set to nil during PrepareForCreate") } if !apiequality.Semantic.DeepEqual(volumeAttachmentSaved, volumeAttachment) { - t.Errorf("unexpected difference in object after creation: %v", diff.ObjectDiff(volumeAttachment, volumeAttachmentSaved)) + t.Errorf("unexpected difference in object after creation: %v", cmp.Diff(volumeAttachment, volumeAttachmentSaved)) } Strategy.PrepareForUpdate(ctx, volumeAttachmentSaved, volumeAttachment) if volumeAttachmentSaved.Spec.Source.InlineVolumeSpec == nil { @@ -157,7 +157,7 @@ func TestVolumeAttachmentStatusStrategy(t *testing.T) { expectedVolumeAttachment := statusVolumeAttachment.DeepCopy() StatusStrategy.PrepareForUpdate(ctx, statusVolumeAttachment, volumeAttachment) if !apiequality.Semantic.DeepEqual(statusVolumeAttachment, expectedVolumeAttachment) { - t.Errorf("unexpected objects difference after modifying status: %v", diff.ObjectDiff(statusVolumeAttachment, expectedVolumeAttachment)) + t.Errorf("unexpected objects difference after modifying status: %v", cmp.Diff(statusVolumeAttachment, expectedVolumeAttachment)) } // spec and metadata modifications should be dropped @@ -175,7 +175,7 @@ func TestVolumeAttachmentStatusStrategy(t *testing.T) { StatusStrategy.PrepareForUpdate(ctx, newVolumeAttachment, volumeAttachment) if !apiequality.Semantic.DeepEqual(newVolumeAttachment, volumeAttachment) { - t.Errorf("unexpected objects difference after modifying spec: %v", diff.ObjectDiff(newVolumeAttachment, volumeAttachment)) + t.Errorf("unexpected objects difference after modifying spec: %v", cmp.Diff(newVolumeAttachment, volumeAttachment)) } } diff --git a/plugin/pkg/admission/noderestriction/admission.go b/plugin/pkg/admission/noderestriction/admission.go index ee12bce0c26..cb21f2360f4 100644 --- a/plugin/pkg/admission/noderestriction/admission.go +++ b/plugin/pkg/admission/noderestriction/admission.go @@ -22,12 +22,12 @@ import ( "io" "strings" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apiserver/pkg/admission" apiserveradmission "k8s.io/apiserver/pkg/admission/initializer" @@ -375,7 +375,7 @@ func (p *Plugin) admitPVCStatus(nodeName string, a admission.Attributes) error { // ensure no metadata changed. nodes should not be able to relabel, add finalizers/owners, etc if !apiequality.Semantic.DeepEqual(oldPVC, newPVC) { - return admission.NewForbidden(a, fmt.Errorf("node %q is not allowed to update fields other than status.capacity and status.conditions: %v", nodeName, diff.ObjectReflectDiff(oldPVC, newPVC))) + return admission.NewForbidden(a, fmt.Errorf("node %q is not allowed to update fields other than status.capacity and status.conditions: %v", nodeName, cmp.Diff(oldPVC, newPVC))) } return nil diff --git a/plugin/pkg/admission/serviceaccount/admission_test.go b/plugin/pkg/admission/serviceaccount/admission_test.go index d50f321a8be..0d81b8a68a9 100644 --- a/plugin/pkg/admission/serviceaccount/admission_test.go +++ b/plugin/pkg/admission/serviceaccount/admission_test.go @@ -27,7 +27,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apiserver/pkg/admission" admissiontesting "k8s.io/apiserver/pkg/admission/testing" "k8s.io/client-go/informers" @@ -224,10 +223,10 @@ func TestAssignsDefaultServiceAccountAndBoundTokenWithNoSecretTokens(t *testing. } if !reflect.DeepEqual(expectedVolumes, pod.Spec.Volumes) { - t.Errorf("unexpected volumes: %s", diff.ObjectReflectDiff(expectedVolumes, pod.Spec.Volumes)) + t.Errorf("unexpected volumes: %s", cmp.Diff(expectedVolumes, pod.Spec.Volumes)) } if !reflect.DeepEqual(expectedVolumeMounts, pod.Spec.Containers[0].VolumeMounts) { - t.Errorf("unexpected volumes: %s", diff.ObjectReflectDiff(expectedVolumeMounts, pod.Spec.Containers[0].VolumeMounts)) + t.Errorf("unexpected volumes: %s", cmp.Diff(expectedVolumeMounts, pod.Spec.Containers[0].VolumeMounts)) } // ensure result converted to v1 matches defaulted object diff --git a/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy_test.go b/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy_test.go index 836756e3c17..235b9f32e4e 100644 --- a/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy_test.go +++ b/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/policy_test.go @@ -22,13 +22,13 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" "sigs.k8s.io/yaml" v1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/component-helpers/auth/rbac/validation" "k8s.io/kubernetes/pkg/api/legacyscheme" @@ -253,7 +253,7 @@ func testObjects(t *testing.T, list *api.List, fixtureFilename string) { t.Logf("Could not update data in %s: %v", filename, err) } } else { - t.Logf("Diff between bootstrap data and fixture data in %s:\n-------------\n%s", filename, diff.StringDiff(string(yamlData), string(expectedYAML))) + t.Logf("Diff between bootstrap data and fixture data in %s:\n-------------\n%s", filename, cmp.Diff(string(yamlData), string(expectedYAML))) t.Logf("If the change is expected, re-run with %s=true to update the fixtures", updateEnvVar) } } diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/kubeopenapi_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/kubeopenapi_test.go index 84266bdc314..fef89bb8f5e 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/kubeopenapi_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/kubeopenapi_test.go @@ -22,11 +22,11 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/json" ) @@ -96,7 +96,7 @@ func TestStructuralKubeOpenAPIRoundtrip(t *testing.T) { } if !reflect.DeepEqual(orig, s) { - t.Fatalf("original and result differ: %v", diff.ObjectGoPrintDiff(orig, s)) + t.Fatalf("original and result differ: %v", cmp.Diff(orig, s)) } } } diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/objectmeta/coerce_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/objectmeta/coerce_test.go index 526156c2b28..fe34a03d406 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/objectmeta/coerce_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/objectmeta/coerce_test.go @@ -21,6 +21,7 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/api/equality" @@ -30,7 +31,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/runtime/serializer/json" - "k8s.io/apimachinery/pkg/util/diff" utiljson "k8s.io/apimachinery/pkg/util/json" clientgoscheme "k8s.io/client-go/kubernetes/scheme" ) @@ -56,7 +56,7 @@ func TestRoundtripObjectMeta(t *testing.T) { } if !equality.Semantic.DeepEqual(original, o) { - t.Errorf("diff: %v\nCodec: %#v", diff.ObjectReflectDiff(original, o), codec) + t.Errorf("diff: %v\nCodec: %#v", cmp.Diff(original, o), codec) } } } @@ -153,7 +153,7 @@ func TestMalformedObjectMetaFields(t *testing.T) { } if !equality.Semantic.DeepEqual(expectedObjectMeta, actualObjectMeta) { - t.Errorf("%v=%#v, diff: %v\n", pth, v, diff.ObjectReflectDiff(expectedObjectMeta, actualObjectMeta)) + t.Errorf("%v=%#v, diff: %v\n", pth, v, cmp.Diff(expectedObjectMeta, actualObjectMeta)) t.Errorf("expectedObjectMeta %#v", expectedObjectMeta) } } diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/controller/openapi/builder/builder_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/controller/openapi/builder/builder_test.go index ead09e2fadb..497df29c38d 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/controller/openapi/builder/builder_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/controller/openapi/builder/builder_test.go @@ -21,13 +21,13 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" apiextensionsinternal "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" structuralschema "k8s.io/apiextensions-apiserver/pkg/apiserver/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apiserver/pkg/endpoints" @@ -438,7 +438,7 @@ func TestNewBuilder(t *testing.T) { gotListSchema := got.listSchema.Properties["items"].Items.Schema if !reflect.DeepEqual(&wantedItemsSchema, gotListSchema) { - t.Errorf("unexpected list schema: %s (want/got)", schemaDiff(&wantedItemsSchema, gotListSchema)) + t.Errorf("unexpected list schema:\n%s", schemaDiff(&wantedItemsSchema, gotListSchema)) } }) } @@ -560,15 +560,8 @@ func properties(p map[string]spec.Schema) sets.String { } func schemaDiff(a, b *spec.Schema) string { - as, err := json.Marshal(a) - if err != nil { - panic(err) - } - bs, err := json.Marshal(b) - if err != nil { - panic(err) - } - return diff.StringDiff(string(as), string(bs)) + // This option construct allows diffing all fields, even unexported ones. + return cmp.Diff(a, b, cmp.Exporter(func(reflect.Type) bool { return true })) } func TestBuildOpenAPIV2(t *testing.T) { diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/tableconvertor/tableconvertor_test.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/tableconvertor/tableconvertor_test.go index 36b93e75d1e..0a0f9873e3f 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/tableconvertor/tableconvertor_test.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/tableconvertor/tableconvertor_test.go @@ -23,11 +23,11 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/util/jsonpath" ) @@ -434,7 +434,7 @@ func Test_convertor_ConvertToTable(t *testing.T) { return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("convertor.ConvertToTable() = %s", diff.ObjectReflectDiff(tt.want, got)) + t.Errorf("convertor.ConvertToTable() = %s", cmp.Diff(tt.want, got)) } }) } diff --git a/staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/roundtrip.go b/staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/roundtrip.go index 2edd86f101b..eb6c7cfa81c 100644 --- a/staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/roundtrip.go +++ b/staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/roundtrip.go @@ -26,6 +26,7 @@ import ( //nolint:staticcheck //iccheck // SA1019 Keep using deprecated module; it still seems to be maintained and the api of the recommended replacement differs "github.com/golang/protobuf/proto" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" flag "github.com/spf13/pflag" @@ -39,7 +40,6 @@ import ( runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/runtime/serializer/json" "k8s.io/apimachinery/pkg/runtime/serializer/protobuf" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/dump" "k8s.io/apimachinery/pkg/util/sets" ) @@ -305,7 +305,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object object = object.DeepCopyObject() name := reflect.TypeOf(object).Elem().Name() if !apiequality.Semantic.DeepEqual(original, object) { - t.Errorf("%v: DeepCopy altered the object, diff: %v", name, diff.ObjectReflectDiff(original, object)) + t.Errorf("%v: DeepCopy altered the object, diff: %v", name, cmp.Diff(original, object)) t.Errorf("%s", dump.Pretty(original)) t.Errorf("%s", dump.Pretty(object)) return @@ -326,7 +326,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object // copy or conversion should alter the object // TODO eliminate this global if !apiequality.Semantic.DeepEqual(original, object) { - t.Errorf("%v: encode altered the object, diff: %v", name, diff.ObjectReflectDiff(original, object)) + t.Errorf("%v: encode altered the object, diff: %v", name, cmp.Diff(original, object)) return } @@ -357,7 +357,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object // ensure that the object produced from decoding the encoded data is equal // to the original object if !apiequality.Semantic.DeepEqual(original, obj2) { - t.Errorf("%v: diff: %v\nCodec: %#v\nSource:\n\n%#v\n\nEncoded:\n\n%s\n\nFinal:\n\n%#v", name, diff.ObjectReflectDiff(original, obj2), codec, dump.Pretty(original), dataAsString(data), dump.Pretty(obj2)) + t.Errorf("%v: diff: %v\nCodec: %#v\nSource:\n\n%#v\n\nEncoded:\n\n%s\n\nFinal:\n\n%#v", name, cmp.Diff(original, obj2), codec, dump.Pretty(original), dataAsString(data), dump.Pretty(obj2)) return } @@ -395,7 +395,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object // ensure that the new runtime object is equal to the original after being // decoded into if !apiequality.Semantic.DeepEqual(object, obj3) { - t.Errorf("%v: diff: %v\nCodec: %#v", name, diff.ObjectReflectDiff(object, obj3), codec) + t.Errorf("%v: diff: %v\nCodec: %#v", name, cmp.Diff(object, obj3), codec) return } @@ -404,7 +404,7 @@ func roundTrip(t *testing.T, scheme *runtime.Scheme, codec runtime.Codec, object // NOTE: we use the encoding+decoding here as an alternative, guaranteed deep-copy to compare against. fuzzer.ValueFuzz(object) if !apiequality.Semantic.DeepEqual(original, obj3) { - t.Errorf("%v: fuzzing a copy altered the original, diff: %v", name, diff.ObjectReflectDiff(original, obj3)) + t.Errorf("%v: fuzzing a copy altered the original, diff: %v", name, cmp.Diff(original, obj3)) return } } diff --git a/staging/src/k8s.io/apimachinery/pkg/api/meta/meta_test.go b/staging/src/k8s.io/apimachinery/pkg/api/meta/meta_test.go index 4680bae9a87..f3cf634f4df 100644 --- a/staging/src/k8s.io/apimachinery/pkg/api/meta/meta_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/api/meta/meta_test.go @@ -23,8 +23,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" ) @@ -36,7 +36,7 @@ func TestAsPartialObjectMetadata(t *testing.T) { f.Fuzz(m) partial := AsPartialObjectMetadata(m) if !reflect.DeepEqual(&partial.ObjectMeta, m) { - t.Fatalf("incomplete partial object metadata: %s", diff.ObjectReflectDiff(&partial.ObjectMeta, m)) + t.Fatalf("incomplete partial object metadata: %s", cmp.Diff(&partial.ObjectMeta, m)) } } @@ -45,7 +45,7 @@ func TestAsPartialObjectMetadata(t *testing.T) { f.Fuzz(&m.ObjectMeta) partial := AsPartialObjectMetadata(m) if !reflect.DeepEqual(&partial.ObjectMeta, &m.ObjectMeta) { - t.Fatalf("incomplete partial object metadata: %s", diff.ObjectReflectDiff(&partial.ObjectMeta, &m.ObjectMeta)) + t.Fatalf("incomplete partial object metadata: %s", cmp.Diff(&partial.ObjectMeta, &m.ObjectMeta)) } } } diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme/register_test.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme/register_test.go index fe666d6db30..da6982c90bf 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme/register_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme/register_test.go @@ -21,9 +21,9 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" ) func TestListOptions(t *testing.T) { @@ -45,7 +45,7 @@ func TestListOptions(t *testing.T) { t.Fatal(err) } if !reflect.DeepEqual(in, actual) { - t.Errorf("unexpected: %s", diff.ObjectReflectDiff(in, actual)) + t.Errorf("unexpected: %s", cmp.Diff(in, actual)) } // verify failing conversion @@ -85,6 +85,6 @@ func TestListOptions(t *testing.T) { t.Fatal(err) } if !reflect.DeepEqual(in, actual) { - t.Errorf("unexpected: %s", diff.ObjectReflectDiff(in, actual)) + t.Errorf("unexpected: %s", cmp.Diff(in, actual)) } } diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go index af6d9cf7d55..8ae538e09b8 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/helpers_test.go @@ -22,10 +22,10 @@ import ( "strings" "testing" - "github.com/google/gofuzz" + "github.com/google/go-cmp/cmp" + fuzz "github.com/google/gofuzz" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" ) func TestLabelSelectorAsSelector(t *testing.T) { @@ -211,7 +211,7 @@ func TestResetObjectMetaForStatus(t *testing.T) { existingMeta.SetManagedFields(nil) if !reflect.DeepEqual(meta, existingMeta) { - t.Error(diff.ObjectDiff(meta, existingMeta)) + t.Error(cmp.Diff(meta, existingMeta)) } } diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_test.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_test.go index be9a48f7141..54e14ed63b6 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured_test.go @@ -21,6 +21,7 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/api/equality" @@ -29,7 +30,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" - "k8s.io/apimachinery/pkg/util/diff" ) func TestNilUnstructuredContent(t *testing.T) { @@ -65,7 +65,7 @@ func TestUnstructuredMetadataRoundTrip(t *testing.T) { setObjectMetaUsingAccessors(u, uCopy) if !equality.Semantic.DeepEqual(u, uCopy) { - t.Errorf("diff: %v", diff.ObjectReflectDiff(u, uCopy)) + t.Errorf("diff: %v", cmp.Diff(u, uCopy)) } } } diff --git a/staging/src/k8s.io/apimachinery/pkg/runtime/converter_test.go b/staging/src/k8s.io/apimachinery/pkg/runtime/converter_test.go index 620eeef2013..7d418132de5 100644 --- a/staging/src/k8s.io/apimachinery/pkg/runtime/converter_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/runtime/converter_test.go @@ -33,9 +33,9 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/conversion" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/json" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -194,7 +194,7 @@ func doRoundTrip(t *testing.T, item interface{}) { return } if !reflect.DeepEqual(item, unmarshalledObj) { - t.Errorf("Object changed during JSON operations, diff: %v", diff.ObjectReflectDiff(item, unmarshalledObj)) + t.Errorf("Object changed during JSON operations, diff: %v", cmp.Diff(item, unmarshalledObj)) return } @@ -213,7 +213,7 @@ func doRoundTrip(t *testing.T, item interface{}) { } if !reflect.DeepEqual(item, newObj) { - t.Errorf("Object changed, diff: %v", diff.ObjectReflectDiff(item, newObj)) + t.Errorf("Object changed, diff: %v", cmp.Diff(item, newObj)) } } @@ -687,7 +687,7 @@ func doUnrecognized(t *testing.T, jsonData string, item interface{}, expectedErr } if expectedErr == nil && !reflect.DeepEqual(unmarshalledObj, newObj) { - t.Errorf("Object changed, diff: %v", diff.ObjectReflectDiff(unmarshalledObj, newObj)) + t.Errorf("Object changed, diff: %v", cmp.Diff(unmarshalledObj, newObj)) } } @@ -916,7 +916,7 @@ func TestFloatIntConversion(t *testing.T) { } if !reflect.DeepEqual(obj, unmarshalled) { - t.Errorf("Incorrect conversion, diff: %v", diff.ObjectReflectDiff(obj, unmarshalled)) + t.Errorf("Incorrect conversion, diff: %v", cmp.Diff(obj, unmarshalled)) } } @@ -938,7 +938,7 @@ func TestIntFloatConversion(t *testing.T) { } if !reflect.DeepEqual(obj, unmarshalled) { - t.Errorf("Incorrect conversion, diff: %v", diff.ObjectReflectDiff(obj, unmarshalled)) + t.Errorf("Incorrect conversion, diff: %v", cmp.Diff(obj, unmarshalled)) } } diff --git a/staging/src/k8s.io/apimachinery/pkg/runtime/local_scheme_test.go b/staging/src/k8s.io/apimachinery/pkg/runtime/local_scheme_test.go index 45a0dde5e70..9b90a71800e 100644 --- a/staging/src/k8s.io/apimachinery/pkg/runtime/local_scheme_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/runtime/local_scheme_test.go @@ -21,8 +21,8 @@ import ( "reflect" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" ) func TestPreferredVersionsAllGroups(t *testing.T) { @@ -124,7 +124,7 @@ func TestPreferredVersionsAllGroups(t *testing.T) { for group, expected := range test.expectedPrioritized { actual := scheme.PrioritizedVersionsForGroup(group) if !reflect.DeepEqual(expected, actual) { - t.Error(diff.ObjectDiff(expected, actual)) + t.Error(cmp.Diff(expected, actual)) } } @@ -134,7 +134,7 @@ func TestPreferredVersionsAllGroups(t *testing.T) { actualPrioritizedAll[actual.Group] = append(actualPrioritizedAll[actual.Group], actual) } if !reflect.DeepEqual(test.expectedPrioritized, actualPrioritizedAll) { - t.Error(diff.ObjectDiff(test.expectedPrioritized, actualPrioritizedAll)) + t.Error(cmp.Diff(test.expectedPrioritized, actualPrioritizedAll)) } preferredAll := scheme.PreferredVersionAllGroups() @@ -143,7 +143,7 @@ func TestPreferredVersionsAllGroups(t *testing.T) { actualPreferredAll[actual] = true } if !reflect.DeepEqual(test.expectedPreferred, actualPreferredAll) { - t.Error(diff.ObjectDiff(test.expectedPreferred, actualPreferredAll)) + t.Error(cmp.Diff(test.expectedPreferred, actualPreferredAll)) } }) } diff --git a/staging/src/k8s.io/apimachinery/pkg/runtime/mapper_test.go b/staging/src/k8s.io/apimachinery/pkg/runtime/mapper_test.go index c880d1bf928..d8423e0e31b 100644 --- a/staging/src/k8s.io/apimachinery/pkg/runtime/mapper_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/runtime/mapper_test.go @@ -20,8 +20,8 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" ) func TestResourceMapper(t *testing.T) { @@ -122,14 +122,14 @@ func TestResourceMapper(t *testing.T) { // Verify equivalents to primary resource if resources := mapper.EquivalentResourcesFor(gvr("apps", "v1", "deployments"), ""); !reflect.DeepEqual(resources, tc.ResourcesForV1Deployment) { - t.Errorf("diff:\n%s", diff.ObjectReflectDiff(tc.ResourcesForV1Deployment, resources)) + t.Errorf("diff:\n%s", cmp.Diff(tc.ResourcesForV1Deployment, resources)) } // Verify equivalents to subresources if resources := mapper.EquivalentResourcesFor(gvr("apps", "v1", "deployments"), "scale"); !reflect.DeepEqual(resources, tc.ResourcesForV1DeploymentScale) { - t.Errorf("diff:\n%s", diff.ObjectReflectDiff(tc.ResourcesForV1DeploymentScale, resources)) + t.Errorf("diff:\n%s", cmp.Diff(tc.ResourcesForV1DeploymentScale, resources)) } if resources := mapper.EquivalentResourcesFor(gvr("apps", "v1", "deployments"), "status"); !reflect.DeepEqual(resources, tc.ResourcesForV1DeploymentStatus) { - t.Errorf("diff:\n%s", diff.ObjectReflectDiff(tc.ResourcesForV1DeploymentStatus, resources)) + t.Errorf("diff:\n%s", cmp.Diff(tc.ResourcesForV1DeploymentStatus, resources)) } }) } diff --git a/staging/src/k8s.io/apimachinery/pkg/runtime/scheme_test.go b/staging/src/k8s.io/apimachinery/pkg/runtime/scheme_test.go index d2a0d4f7a99..ff61024c960 100644 --- a/staging/src/k8s.io/apimachinery/pkg/runtime/scheme_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/runtime/scheme_test.go @@ -22,6 +22,7 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/conversion" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -856,17 +857,17 @@ func TestConvertToVersion(t *testing.T) { if test.same { if !reflect.DeepEqual(original, test.in) { - t.Fatalf("unexpected mutation of input: %s", diff.ObjectReflectDiff(original, test.in)) + t.Fatalf("unexpected mutation of input: %s", cmp.Diff(original, test.in)) } if !reflect.DeepEqual(out, test.out) { - t.Fatalf("unexpected out: %s", diff.ObjectReflectDiff(out, test.out)) + t.Fatalf("unexpected out: %s", cmp.Diff(out, test.out)) } unsafe, err := test.scheme.UnsafeConvertToVersion(test.in, test.gv) if err != nil { t.Fatalf("unexpected error: %v", err) } if !reflect.DeepEqual(unsafe, test.out) { - t.Fatalf("unexpected unsafe: %s", diff.ObjectReflectDiff(unsafe, test.out)) + t.Fatalf("unexpected unsafe: %s", cmp.Diff(unsafe, test.out)) } if unsafe != test.in { t.Fatalf("UnsafeConvertToVersion should return same object: %#v", unsafe) @@ -874,7 +875,7 @@ func TestConvertToVersion(t *testing.T) { return } if !reflect.DeepEqual(out, test.out) { - t.Fatalf("unexpected out: %s", diff.ObjectReflectDiff(out, test.out)) + t.Fatalf("unexpected out: %s", cmp.Diff(out, test.out)) } }) } @@ -917,7 +918,7 @@ func TestConvert(t *testing.T) { } if !reflect.DeepEqual(test.into, test.out) { - t.Fatalf("unexpected out: %s", diff.ObjectReflectDiff(test.into, test.out)) + t.Fatalf("unexpected out: %s", cmp.Diff(test.into, test.out)) } }) } diff --git a/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/codec_test.go b/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/codec_test.go index 9625739f300..d4bfb69b3c7 100644 --- a/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/codec_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/codec_test.go @@ -33,6 +33,7 @@ import ( "k8s.io/apimachinery/pkg/util/diff" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" flag "github.com/spf13/pflag" "sigs.k8s.io/yaml" @@ -128,7 +129,7 @@ func runTest(t *testing.T, source interface{}) { return } if !semantic.DeepEqual(source, obj3) { - t.Errorf("3: %v: diff: %v", name, diff.ObjectDiff(source, obj3)) + t.Errorf("3: %v: diff: %v", name, cmp.Diff(source, obj3)) return } } diff --git a/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/sparse_test.go b/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/sparse_test.go index 3bc9d13bb89..406bc3615d4 100644 --- a/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/sparse_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/runtime/serializer/sparse_test.go @@ -19,11 +19,11 @@ package serializer import ( "testing" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" ) type FakeV1Obj struct { @@ -83,9 +83,9 @@ func TestSparse(t *testing.T) { uncastDstObj2.(*FakeV2DifferentObj).TypeMeta = metav1.TypeMeta{} if !equality.Semantic.DeepEqual(srcObj1, uncastDstObj1) { - t.Fatal(diff.ObjectDiff(srcObj1, uncastDstObj1)) + t.Fatal(cmp.Diff(srcObj1, uncastDstObj1)) } if !equality.Semantic.DeepEqual(srcObj2, uncastDstObj2) { - t.Fatal(diff.ObjectDiff(srcObj2, uncastDstObj2)) + t.Fatal(cmp.Diff(srcObj2, uncastDstObj2)) } } diff --git a/staging/src/k8s.io/apimachinery/pkg/test/api_meta_help_test.go b/staging/src/k8s.io/apimachinery/pkg/test/api_meta_help_test.go index b5e28cb0cab..4214c1b3ee6 100644 --- a/staging/src/k8s.io/apimachinery/pkg/test/api_meta_help_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/test/api_meta_help_test.go @@ -20,6 +20,7 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" "k8s.io/apimachinery/pkg/api/meta" @@ -27,11 +28,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/testapigroup" - "k8s.io/apimachinery/pkg/apis/testapigroup/v1" + v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" - "k8s.io/apimachinery/pkg/util/diff" ) func TestIsList(t *testing.T) { @@ -283,7 +283,7 @@ func TestSetListToRuntimeObjectArray(t *testing.T) { } for i := range list { if e, a := list[i], pl.Items[i]; e != a { - t.Fatalf("%d: unmatched: %s", i, diff.ObjectDiff(e, a)) + t.Fatalf("%d: unmatched: %s", i, cmp.Diff(e, a)) } } } @@ -304,7 +304,7 @@ func TestSetListToMatchingType(t *testing.T) { } for i := range list { if e, a := list[i], &pl.Items[i]; !reflect.DeepEqual(e, a) { - t.Fatalf("%d: unmatched: %s", i, diff.ObjectDiff(e, a)) + t.Fatalf("%d: unmatched: %s", i, cmp.Diff(e, a)) } } } diff --git a/staging/src/k8s.io/apimachinery/pkg/test/runtime_serializer_protobuf_protobuf_test.go b/staging/src/k8s.io/apimachinery/pkg/test/runtime_serializer_protobuf_protobuf_test.go index 17bcfc17a8a..75c26ca8cb7 100644 --- a/staging/src/k8s.io/apimachinery/pkg/test/runtime_serializer_protobuf_protobuf_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/test/runtime_serializer_protobuf_protobuf_test.go @@ -24,15 +24,15 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/testapigroup/v1" + v1 "k8s.io/apimachinery/pkg/apis/testapigroup/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer/protobuf" - "k8s.io/apimachinery/pkg/util/diff" ) type testObject struct { @@ -355,7 +355,7 @@ func TestDecodeObjects(t *testing.T) { } if !apiequality.Semantic.DeepEqual(obj, test.obj) { - t.Errorf("%d: unexpected object:\n%s", i, diff.ObjectGoPrintDiff(test.obj, obj)) + t.Errorf("%d: unexpected object:\n%s", i, cmp.Diff(test.obj, obj)) continue } } diff --git a/staging/src/k8s.io/apimachinery/pkg/util/diff/diff.go b/staging/src/k8s.io/apimachinery/pkg/util/diff/diff.go index 85066aea8e9..fc030184490 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/diff/diff.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/diff/diff.go @@ -27,30 +27,16 @@ import ( "k8s.io/apimachinery/pkg/util/dump" ) -// StringDiff diffs a and b and returns a human readable diff. -func StringDiff(a, b string) string { - ba := []byte(a) - bb := []byte(b) - out := []byte{} - i := 0 - for ; i < len(ba) && i < len(bb); i++ { - if ba[i] != bb[i] { - break - } - out = append(out, ba[i]) - } - out = append(out, []byte("\n\nA: ")...) - out = append(out, ba[i:]...) - out = append(out, []byte("\n\nB: ")...) - out = append(out, bb[i:]...) - out = append(out, []byte("\n\n")...) - return string(out) -} - func legacyDiff(a, b interface{}) string { return cmp.Diff(a, b) } +// StringDiff diffs a and b and returns a human readable diff. +// DEPRECATED: use github.com/google/go-cmp/cmp.Diff +func StringDiff(a, b string) string { + return legacyDiff(a, b) +} + // ObjectDiff prints the diff of two go objects and fails if the objects // contain unhandled unexported fields. // DEPRECATED: use github.com/google/go-cmp/cmp.Diff diff --git a/staging/src/k8s.io/apimachinery/pkg/util/diff/diff_test.go b/staging/src/k8s.io/apimachinery/pkg/util/diff/diff_test.go deleted file mode 100644 index eb61a11d779..00000000000 --- a/staging/src/k8s.io/apimachinery/pkg/util/diff/diff_test.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package diff - -import ( - "testing" -) - -func TestStringDiff(t *testing.T) { - diff := StringDiff("aaabb", "aaacc") - expect := "aaa\n\nA: bb\n\nB: cc\n\n" - if diff != expect { - t.Errorf("diff returned %v", diff) - } -} diff --git a/staging/src/k8s.io/apimachinery/pkg/util/proxy/dial_test.go b/staging/src/k8s.io/apimachinery/pkg/util/proxy/dial_test.go index 705aea8ff0c..32e951e61ca 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/proxy/dial_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/proxy/dial_test.go @@ -29,7 +29,7 @@ import ( "regexp" "testing" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" utilnet "k8s.io/apimachinery/pkg/util/net" ) @@ -147,7 +147,7 @@ func TestDialURL(t *testing.T) { // Make sure dialing doesn't mutate the transport's TLSConfig if !reflect.DeepEqual(tc.TLSConfig, tlsConfigCopy) { - t.Errorf("%s: transport's copy of TLSConfig was mutated\n%s", k, diff.ObjectReflectDiff(tc.TLSConfig, tlsConfigCopy)) + t.Errorf("%s: transport's copy of TLSConfig was mutated\n%s", k, cmp.Diff(tc.TLSConfig, tlsConfigCopy)) } if err != nil { diff --git a/staging/src/k8s.io/apiserver/pkg/admission/conversion_test.go b/staging/src/k8s.io/apiserver/pkg/admission/conversion_test.go index 720512ff0bc..32d43c5d686 100644 --- a/staging/src/k8s.io/apiserver/pkg/admission/conversion_test.go +++ b/staging/src/k8s.io/apiserver/pkg/admission/conversion_test.go @@ -21,13 +21,13 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apiserver/pkg/apis/example" examplev1 "k8s.io/apiserver/pkg/apis/example/v1" example2v1 "k8s.io/apiserver/pkg/apis/example2/v1" @@ -341,22 +341,22 @@ func TestConvertVersionedAttributes(t *testing.T) { t.Fatal(err) } if e, a := tc.ExpectedAttrs.Attributes.GetObject(), tc.Attrs.Attributes.GetObject(); !reflect.DeepEqual(e, a) { - t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a)) + t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a)) } if e, a := tc.ExpectedAttrs.Attributes.GetOldObject(), tc.Attrs.Attributes.GetOldObject(); !reflect.DeepEqual(e, a) { - t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a)) + t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a)) } if e, a := tc.ExpectedAttrs.VersionedKind, tc.Attrs.VersionedKind; !reflect.DeepEqual(e, a) { - t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a)) + t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a)) } if e, a := tc.ExpectedAttrs.VersionedObject, tc.Attrs.VersionedObject; !reflect.DeepEqual(e, a) { - t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a)) + t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a)) } if e, a := tc.ExpectedAttrs.VersionedOldObject, tc.Attrs.VersionedOldObject; !reflect.DeepEqual(e, a) { - t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a)) + t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a)) } if e, a := tc.ExpectedAttrs.Dirty, tc.Attrs.Dirty; !reflect.DeepEqual(e, a) { - t.Errorf("unexpected diff:\n%s", diff.ObjectReflectDiff(e, a)) + t.Errorf("unexpected diff:\n%s", cmp.Diff(e, a)) } }) } diff --git a/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission_test.go b/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission_test.go index b98c8860daf..d712028eee7 100644 --- a/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission_test.go +++ b/staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle/admission_test.go @@ -23,12 +23,12 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apiserver/pkg/admission" @@ -202,7 +202,7 @@ func TestAdmissionNamespaceTerminating(t *testing.T) { Field: "metadata.namespace", } if cause, ok := errors.StatusCause(err, v1.NamespaceTerminatingCause); !ok || !reflect.DeepEqual(expectedCause, cause) { - t.Errorf("Expected status cause indicating the namespace is terminating: %t %s", ok, diff.ObjectReflectDiff(expectedCause, cause)) + t.Errorf("Expected status cause indicating the namespace is terminating: %t %s", ok, cmp.Diff(expectedCause, cause)) } // verify update operations in the namespace can proceed diff --git a/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/accessors_test.go b/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/accessors_test.go index 943dec1144e..7469d4eb678 100644 --- a/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/accessors_test.go +++ b/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/accessors_test.go @@ -21,9 +21,9 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" - "k8s.io/api/admissionregistration/v1" - "k8s.io/apimachinery/pkg/util/diff" + v1 "k8s.io/api/admissionregistration/v1" ) func TestMutatingWebhookAccessor(t *testing.T) { @@ -46,7 +46,7 @@ func TestMutatingWebhookAccessor(t *testing.T) { t.Errorf("expected GetMutatingWebhook to return ok for mutating webhook accessor") } if !reflect.DeepEqual(orig, m) { - t.Errorf("expected GetMutatingWebhook to return original webhook, diff:\n%s", diff.ObjectReflectDiff(orig, m)) + t.Errorf("expected GetMutatingWebhook to return original webhook, diff:\n%s", cmp.Diff(orig, m)) } if _, ok := accessor.GetValidatingWebhook(); ok { t.Errorf("expected GetValidatingWebhook to be nil for mutating webhook accessor") @@ -65,7 +65,7 @@ func TestMutatingWebhookAccessor(t *testing.T) { MatchConditions: accessor.GetMatchConditions(), } if !reflect.DeepEqual(orig, copy) { - t.Errorf("expected mutatingWebhook to round trip through WebhookAccessor, diff:\n%s", diff.ObjectReflectDiff(orig, copy)) + t.Errorf("expected mutatingWebhook to round trip through WebhookAccessor, diff:\n%s", cmp.Diff(orig, copy)) } }) } @@ -87,7 +87,7 @@ func TestValidatingWebhookAccessor(t *testing.T) { t.Errorf("expected GetValidatingWebhook to return ok for validating webhook accessor") } if !reflect.DeepEqual(orig, m) { - t.Errorf("expected GetValidatingWebhook to return original webhook, diff:\n%s", diff.ObjectReflectDiff(orig, m)) + t.Errorf("expected GetValidatingWebhook to return original webhook, diff:\n%s", cmp.Diff(orig, m)) } if _, ok := accessor.GetMutatingWebhook(); ok { t.Errorf("expected GetMutatingWebhook to be nil for validating webhook accessor") @@ -106,7 +106,7 @@ func TestValidatingWebhookAccessor(t *testing.T) { MatchConditions: accessor.GetMatchConditions(), } if !reflect.DeepEqual(orig, copy) { - t.Errorf("expected validatingWebhook to round trip through WebhookAccessor, diff:\n%s", diff.ObjectReflectDiff(orig, copy)) + t.Errorf("expected validatingWebhook to round trip through WebhookAccessor, diff:\n%s", cmp.Diff(orig, copy)) } }) } diff --git a/staging/src/k8s.io/apiserver/pkg/admission/testing/helpers.go b/staging/src/k8s.io/apiserver/pkg/admission/testing/helpers.go index 45e126dabf6..76dea6d5c61 100644 --- a/staging/src/k8s.io/apiserver/pkg/admission/testing/helpers.go +++ b/staging/src/k8s.io/apiserver/pkg/admission/testing/helpers.go @@ -21,9 +21,9 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apiserver/pkg/admission" ) @@ -63,7 +63,7 @@ func (r *reinvoker) Admit(ctx context.Context, a admission.Attributes, o admissi } for i := 1; i < len(outputs); i++ { if !apiequality.Semantic.DeepEqual(outputs[0], outputs[i]) { - r.t.Errorf("expected mutating admission plugin to be idempontent, but got different results on reinvocation, diff:\n%s", diff.ObjectReflectDiff(outputs[0], outputs[i])) + r.t.Errorf("expected mutating admission plugin to be idempontent, but got different results on reinvocation, diff:\n%s", cmp.Diff(outputs[0], outputs[i])) } } return nil diff --git a/staging/src/k8s.io/apiserver/pkg/audit/policy/reader_test.go b/staging/src/k8s.io/apiserver/pkg/audit/policy/reader_test.go index 32bcdfde7a5..4df0c9f9ce7 100644 --- a/staging/src/k8s.io/apiserver/pkg/audit/policy/reader_test.go +++ b/staging/src/k8s.io/apiserver/pkg/audit/policy/reader_test.go @@ -23,12 +23,12 @@ import ( "strings" "testing" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apiserver/pkg/apis/audit" // import to call webhook's init() function to register audit.Policy to schema _ "k8s.io/apiserver/plugin/pkg/audit/webhook" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -113,7 +113,7 @@ func TestParser(t *testing.T) { assert.Len(t, policy.Rules, 3) // Sanity check. if !reflect.DeepEqual(policy, expectedPolicy) { - t.Errorf("Unexpected policy! Diff:\n%s", diff.ObjectDiff(policy, expectedPolicy)) + t.Errorf("Unexpected policy! Diff:\n%s", cmp.Diff(policy, expectedPolicy)) } } diff --git a/staging/src/k8s.io/apiserver/pkg/authentication/authenticator/audagnostic_test.go b/staging/src/k8s.io/apiserver/pkg/authentication/authenticator/audagnostic_test.go index 0152b9a6e38..bc8c0cfa833 100644 --- a/staging/src/k8s.io/apiserver/pkg/authentication/authenticator/audagnostic_test.go +++ b/staging/src/k8s.io/apiserver/pkg/authentication/authenticator/audagnostic_test.go @@ -23,7 +23,7 @@ import ( "reflect" "testing" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" "k8s.io/apiserver/pkg/authentication/user" ) @@ -219,7 +219,7 @@ func TestAuthenticate(t *testing.T) { t.Errorf("Unexpected authentication. got=%v, want=%v", got, want) } if got, want := resp, treq.wantResp; !reflect.DeepEqual(got, want) { - t.Errorf("Unexpected response. diff:\n%v", diff.ObjectGoPrintDiff(got, want)) + t.Errorf("Unexpected response. diff:\n%v", cmp.Diff(got, want)) } }) } diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go index 11d8123754b..0923b0d0388 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go @@ -38,6 +38,7 @@ import ( "time" "github.com/emicklei/go-restful/v3" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" apiequality "k8s.io/apimachinery/pkg/api/equality" @@ -55,7 +56,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/runtime/serializer/streaming" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/net" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" @@ -1832,7 +1832,7 @@ func TestGetTable(t *testing.T) { } if !reflect.DeepEqual(test.expected, &itemOut) { t.Log(body) - t.Errorf("%d: did not match: %s", i, diff.ObjectReflectDiff(test.expected, &itemOut)) + t.Errorf("%d: did not match: %s", i, cmp.Diff(test.expected, &itemOut)) } }) } @@ -2061,13 +2061,7 @@ func TestWatchTable(t *testing.T) { actual = append(actual, &event) } if !reflect.DeepEqual(test.expected, actual) { - for i := range test.expected { - if i >= len(actual) { - break - } - t.Logf("%s", diff.StringDiff(string(test.expected[i].Object.Raw), string(actual[i].Object.Raw))) - } - t.Fatalf("unexpected: %s", diff.ObjectReflectDiff(test.expected, actual)) + t.Fatalf("unexpected: %s", cmp.Diff(test.expected, actual)) } }) } @@ -2245,7 +2239,7 @@ func TestGetPartialObjectMetadata(t *testing.T) { t.Fatal(err) } if !reflect.DeepEqual(test.expected, itemOut) { - t.Errorf("%d: did not match: %s", i, diff.ObjectReflectDiff(test.expected, itemOut)) + t.Errorf("%d: did not match: %s", i, cmp.Diff(test.expected, itemOut)) } body = d } else { @@ -2829,7 +2823,7 @@ func TestDeleteWithOptions(t *testing.T) { } simpleStorage.deleteOptions.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{}) if !apiequality.Semantic.DeepEqual(simpleStorage.deleteOptions, item) { - t.Errorf("unexpected delete options: %s", diff.ObjectDiff(simpleStorage.deleteOptions, item)) + t.Errorf("unexpected delete options: %s", cmp.Diff(simpleStorage.deleteOptions, item)) } } @@ -2869,7 +2863,7 @@ func TestDeleteWithOptionsQuery(t *testing.T) { } simpleStorage.deleteOptions.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{}) if !apiequality.Semantic.DeepEqual(simpleStorage.deleteOptions, item) { - t.Errorf("unexpected delete options: %s", diff.ObjectDiff(simpleStorage.deleteOptions, item)) + t.Errorf("unexpected delete options: %s", cmp.Diff(simpleStorage.deleteOptions, item)) } } @@ -2912,7 +2906,7 @@ func TestDeleteWithOptionsQueryAndBody(t *testing.T) { } simpleStorage.deleteOptions.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{}) if !apiequality.Semantic.DeepEqual(simpleStorage.deleteOptions, item) { - t.Errorf("unexpected delete options: %s", diff.ObjectDiff(simpleStorage.deleteOptions, item)) + t.Errorf("unexpected delete options: %s", cmp.Diff(simpleStorage.deleteOptions, item)) } } diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/writers_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/writers_test.go index febb88a7da2..7a6ca546e40 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/writers_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/writers_test.go @@ -35,11 +35,11 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apiserver/pkg/features" utilfeature "k8s.io/apiserver/pkg/util/feature" @@ -114,7 +114,7 @@ func TestSerializeObjectParallel(t *testing.T) { t.Fatalf("unexpected code: %v", result.StatusCode) } if !reflect.DeepEqual(result.Header, ctt.wantHeaders) { - t.Fatal(diff.ObjectReflectDiff(ctt.wantHeaders, result.Header)) + t.Fatal(cmp.Diff(ctt.wantHeaders, result.Header)) } }) } @@ -364,7 +364,7 @@ func TestSerializeObject(t *testing.T) { t.Fatalf("unexpected code: %v", result.StatusCode) } if !reflect.DeepEqual(result.Header, tt.wantHeaders) { - t.Fatal(diff.ObjectReflectDiff(tt.wantHeaders, result.Header)) + t.Fatal(cmp.Diff(tt.wantHeaders, result.Header)) } body, _ := ioutil.ReadAll(result.Body) if !bytes.Equal(tt.wantBody, body) { diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest_test.go index 5c13c26b667..ff5f0dc47b1 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest_test.go @@ -28,6 +28,7 @@ import ( "time" jsonpatch "github.com/evanphx/json-patch" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" apiequality "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -38,7 +39,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/json" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/strategicpatch" @@ -583,7 +583,7 @@ func (tc *patchTestCase) Run(t *testing.T) { reallyExpectedPod := expectedObj.(*example.Pod) if !reflect.DeepEqual(*reallyExpectedPod, *resultPod) { - t.Errorf("%s mismatch: %v\n", tc.name, diff.ObjectGoPrintDiff(reallyExpectedPod, resultPod)) + t.Errorf("%s mismatch: %v\n", tc.name, cmp.Diff(reallyExpectedPod, resultPod)) continue } } @@ -1279,7 +1279,7 @@ func TestDedupOwnerReferences(t *testing.T) { t.Run(tc.name, func(t *testing.T) { deduped, _ := dedupOwnerReferences(tc.ownerReferences) if !apiequality.Semantic.DeepEqual(deduped, tc.expected) { - t.Errorf("diff: %v", diff.ObjectReflectDiff(deduped, tc.expected)) + t.Errorf("diff: %v", cmp.Diff(deduped, tc.expected)) } }) } diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/watch_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/watch_test.go index c85d207eab8..e3d650a94a0 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/watch_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/watch_test.go @@ -32,6 +32,7 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "golang.org/x/net/websocket" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" @@ -41,7 +42,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer/streaming" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" example "k8s.io/apiserver/pkg/apis/example" @@ -397,7 +397,7 @@ func TestWatchRead(t *testing.T) { t.Fatalf("%s: Decode error: %v", name, err) } if e, a := object, gotObj; !apiequality.Semantic.DeepEqual(e, a) { - t.Errorf("%s: different: %s", name, diff.ObjectDiff(e, a)) + t.Errorf("%s: different: %s", name, cmp.Diff(e, a)) } } w.Stop() diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cache_watcher_test.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cache_watcher_test.go index d408c7ae865..76b1dfd195c 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cache_watcher_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cache_watcher_test.go @@ -24,13 +24,13 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" "k8s.io/apiserver/pkg/storage" @@ -189,7 +189,7 @@ TestCase: for j, event := range testCase.expected { e := <-ch if !reflect.DeepEqual(event, e) { - t.Errorf("%d: unexpected event %d: %s", i, j, diff.ObjectReflectDiff(event, e)) + t.Errorf("%d: unexpected event %d: %s", i, j, cmp.Diff(event, e)) break TestCase } } diff --git a/staging/src/k8s.io/apiserver/pkg/util/webhook/authentication_test.go b/staging/src/k8s.io/apiserver/pkg/util/webhook/authentication_test.go index bdac3a49f82..7ab9218ee9d 100644 --- a/staging/src/k8s.io/apiserver/pkg/util/webhook/authentication_test.go +++ b/staging/src/k8s.io/apiserver/pkg/util/webhook/authentication_test.go @@ -19,8 +19,8 @@ package webhook import ( "testing" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/rest" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" ) @@ -230,7 +230,7 @@ func TestAuthenticationDetection(t *testing.T) { actual.Timeout = 0 if !equality.Semantic.DeepEqual(*actual, tc.expected) { - t.Errorf("%v", diff.ObjectReflectDiff(tc.expected, *actual)) + t.Errorf("%v", cmp.Diff(tc.expected, *actual)) } }) } diff --git a/staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook/round_trip_test.go b/staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook/round_trip_test.go index c85196fd319..75c9dbf9282 100644 --- a/staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook/round_trip_test.go +++ b/staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/webhook/round_trip_test.go @@ -23,11 +23,11 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" authenticationv1 "k8s.io/api/authentication/v1" authenticationv1beta1 "k8s.io/api/authentication/v1beta1" - "k8s.io/apimachinery/pkg/util/diff" ) func TestRoundTrip(t *testing.T) { @@ -49,7 +49,7 @@ func TestRoundTrip(t *testing.T) { Status: v1beta1StatusToV1Status(&converted.Status), } if !reflect.DeepEqual(original, roundtripped) { - t.Errorf("diff %s", diff.ObjectReflectDiff(original, roundtripped)) + t.Errorf("diff %s", cmp.Diff(original, roundtripped)) } } } diff --git a/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/round_trip_test.go b/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/round_trip_test.go index 885aa0e71aa..7b5ea4cf220 100644 --- a/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/round_trip_test.go +++ b/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/round_trip_test.go @@ -23,11 +23,11 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" authorizationv1 "k8s.io/api/authorization/v1" authorizationv1beta1 "k8s.io/api/authorization/v1beta1" - "k8s.io/apimachinery/pkg/util/diff" ) func TestRoundTrip(t *testing.T) { @@ -49,7 +49,7 @@ func TestRoundTrip(t *testing.T) { Status: v1beta1StatusToV1Status(&converted.Status), } if !reflect.DeepEqual(original, roundtripped) { - t.Errorf("diff %s", diff.ObjectReflectDiff(original, roundtripped)) + t.Errorf("diff %s", cmp.Diff(original, roundtripped)) } } } diff --git a/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1_test.go b/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1_test.go index 07b3d4148f0..6d21e40a2a1 100644 --- a/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1_test.go +++ b/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1_test.go @@ -34,9 +34,9 @@ import ( "text/template" "time" + "github.com/google/go-cmp/cmp" authorizationv1 "k8s.io/api/authorization/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/authorization/authorizer" @@ -556,7 +556,7 @@ func TestV1Webhook(t *testing.T) { continue } if !reflect.DeepEqual(gotAttr, tt.want) { - t.Errorf("case %d: got != want:\n%s", i, diff.ObjectGoPrintDiff(gotAttr, tt.want)) + t.Errorf("case %d: got != want:\n%s", i, cmp.Diff(gotAttr, tt.want)) } } } diff --git a/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1beta1_test.go b/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1beta1_test.go index d3ba93db435..8023a57afe9 100644 --- a/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1beta1_test.go +++ b/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1beta1_test.go @@ -34,9 +34,9 @@ import ( "text/template" "time" + "github.com/google/go-cmp/cmp" authorizationv1beta1 "k8s.io/api/authorization/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/authorization/authorizer" webhookutil "k8s.io/apiserver/pkg/util/webhook" @@ -548,7 +548,7 @@ func TestV1beta1Webhook(t *testing.T) { continue } if !reflect.DeepEqual(gotAttr, tt.want) { - t.Errorf("case %d: got != want:\n%s", i, diff.ObjectGoPrintDiff(gotAttr, tt.want)) + t.Errorf("case %d: got != want:\n%s", i, cmp.Diff(gotAttr, tt.want)) } } } diff --git a/staging/src/k8s.io/cli-runtime/go.mod b/staging/src/k8s.io/cli-runtime/go.mod index 8c23e32e89f..c389ce3c1bb 100644 --- a/staging/src/k8s.io/cli-runtime/go.mod +++ b/staging/src/k8s.io/cli-runtime/go.mod @@ -8,6 +8,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/evanphx/json-patch v4.12.0+incompatible github.com/google/gnostic v0.5.7-v3refs + github.com/google/go-cmp v0.5.9 github.com/google/uuid v1.3.0 github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de github.com/spf13/cobra v1.6.0 @@ -36,7 +37,6 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/btree v1.0.1 // indirect - github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.1.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect diff --git a/staging/src/k8s.io/cli-runtime/pkg/printers/json_test.go b/staging/src/k8s.io/cli-runtime/pkg/printers/json_test.go index 902ef3f66eb..df14d0037e2 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/printers/json_test.go +++ b/staging/src/k8s.io/cli-runtime/pkg/printers/json_test.go @@ -21,10 +21,10 @@ import ( "reflect" "testing" - "k8s.io/api/core/v1" + "github.com/google/go-cmp/cmp" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/json" "k8s.io/client-go/kubernetes/scheme" ) @@ -74,7 +74,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data t.Fatal(err) } if !reflect.DeepEqual(testData, poutput) { - t.Errorf("Test data and unmarshaled data are not equal: %v", diff.ObjectDiff(poutput, testData)) + t.Errorf("Test data and unmarshaled data are not equal: %v", cmp.Diff(poutput, testData)) } obj := &v1.Pod{ @@ -97,7 +97,7 @@ func testPrinter(t *testing.T, printer ResourcePrinter, unmarshalFunc func(data t.Fatal(err) } if !reflect.DeepEqual(obj, &objOut) { - t.Errorf("Unexpected inequality:\n%v", diff.ObjectDiff(obj, &objOut)) + t.Errorf("Unexpected inequality:\n%v", cmp.Diff(obj, &objOut)) } } diff --git a/staging/src/k8s.io/client-go/discovery/discovery_client_test.go b/staging/src/k8s.io/client-go/discovery/discovery_client_test.go index dc9a4ffe75f..7ed6948a3c4 100644 --- a/staging/src/k8s.io/client-go/discovery/discovery_client_test.go +++ b/staging/src/k8s.io/client-go/discovery/discovery_client_test.go @@ -36,7 +36,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/version" "k8s.io/client-go/openapi" @@ -437,7 +436,7 @@ func TestGetServerResourcesForGroupVersion(t *testing.T) { "extensions/v1beta10", } if !reflect.DeepEqual(expectedGroupVersions, serverGroupVersions) { - t.Errorf("unexpected group versions: %v", diff.ObjectReflectDiff(expectedGroupVersions, serverGroupVersions)) + t.Errorf("unexpected group versions: %v", cmp.Diff(expectedGroupVersions, serverGroupVersions)) } } diff --git a/staging/src/k8s.io/client-go/dynamic/dynamicinformer/informer_test.go b/staging/src/k8s.io/client-go/dynamic/dynamicinformer/informer_test.go index 98acdb40fc0..dac032ed699 100644 --- a/staging/src/k8s.io/client-go/dynamic/dynamicinformer/informer_test.go +++ b/staging/src/k8s.io/client-go/dynamic/dynamicinformer/informer_test.go @@ -21,12 +21,12 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/dynamic/dynamicinformer" "k8s.io/client-go/dynamic/fake" "k8s.io/client-go/tools/cache" @@ -118,7 +118,7 @@ func TestFilteredDynamicSharedInformerFactory(t *testing.T) { t.Errorf("informer received an object for namespace %s when watching namespace %s", ts.ns, ts.informNS) } if !equality.Semantic.DeepEqual(testObject, objFromInformer) { - t.Fatalf("%v", diff.ObjectDiff(testObject, objFromInformer)) + t.Fatalf("%v", cmp.Diff(testObject, objFromInformer)) } case <-ctx.Done(): if ts.ns == ts.informNS { @@ -239,7 +239,7 @@ func TestDynamicSharedInformerFactory(t *testing.T) { select { case objFromInformer := <-informerReciveObjectCh: if !equality.Semantic.DeepEqual(testObject, objFromInformer) { - t.Fatalf("%v", diff.ObjectDiff(testObject, objFromInformer)) + t.Fatalf("%v", cmp.Diff(testObject, objFromInformer)) } case <-ctx.Done(): t.Errorf("tested informer haven't received an object, waited %v", timeout) diff --git a/staging/src/k8s.io/client-go/dynamic/dynamiclister/lister_test.go b/staging/src/k8s.io/client-go/dynamic/dynamiclister/lister_test.go index 9ebc4794664..660b43afb4d 100644 --- a/staging/src/k8s.io/client-go/dynamic/dynamiclister/lister_test.go +++ b/staging/src/k8s.io/client-go/dynamic/dynamiclister/lister_test.go @@ -20,11 +20,11 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/dynamic/dynamiclister" "k8s.io/client-go/tools/cache" ) @@ -90,7 +90,7 @@ func TestNamespaceGetMethod(t *testing.T) { t.Fatal(err) } if !reflect.DeepEqual(test.expectedObject, actualObject) { - t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, diff.ObjectDiff(test.expectedObject, actualObject)) + t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, cmp.Diff(test.expectedObject, actualObject)) } }) } @@ -188,7 +188,7 @@ func TestListerGetMethod(t *testing.T) { t.Fatal(err) } if !reflect.DeepEqual(test.expectedObject, actualObject) { - t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, diff.ObjectDiff(test.expectedObject, actualObject)) + t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, cmp.Diff(test.expectedObject, actualObject)) } }) } @@ -245,7 +245,7 @@ func assertListOrDie(expected, actual []*unstructured.Unstructured, t *testing.T for _, actualObject := range actual { if actualObject.GetName() == expectedObject.GetName() { if !reflect.DeepEqual(expectedObject, actualObject) { - t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", expectedObject, actualObject, diff.ObjectDiff(expectedObject, actualObject)) + t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", expectedObject, actualObject, cmp.Diff(expectedObject, actualObject)) } found = true } diff --git a/staging/src/k8s.io/client-go/dynamic/fake/simple_test.go b/staging/src/k8s.io/client-go/dynamic/fake/simple_test.go index e74b6ff0414..7e487616355 100644 --- a/staging/src/k8s.io/client-go/dynamic/fake/simple_test.go +++ b/staging/src/k8s.io/client-go/dynamic/fake/simple_test.go @@ -28,7 +28,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" ) const ( @@ -80,7 +79,7 @@ func TestGet(t *testing.T) { }, } if !equality.Semantic.DeepEqual(get, expected) { - t.Fatal(diff.ObjectGoPrintDiff(expected, get)) + t.Fatal(cmp.Diff(expected, get)) } } @@ -99,7 +98,7 @@ func TestListDecoding(t *testing.T) { Items: []unstructured.Unstructured{}, } if !equality.Semantic.DeepEqual(list, expectedList) { - t.Fatal(diff.ObjectGoPrintDiff(expectedList, list)) + t.Fatal(cmp.Diff(expectedList, list)) } } @@ -117,7 +116,7 @@ func TestGetDecoding(t *testing.T) { }, } if !equality.Semantic.DeepEqual(get, expectedObj) { - t.Fatal(diff.ObjectGoPrintDiff(expectedObj, get)) + t.Fatal(cmp.Diff(expectedObj, get)) } } @@ -145,7 +144,7 @@ func TestList(t *testing.T) { *newUnstructured("group/version", "TheKind", "ns-foo", "name-foo"), } if !equality.Semantic.DeepEqual(listFirst.Items, expected) { - t.Fatal(diff.ObjectGoPrintDiff(expected, listFirst.Items)) + t.Fatal(cmp.Diff(expected, listFirst.Items)) } } @@ -189,7 +188,7 @@ func Test_ListKind(t *testing.T) { }, } if !equality.Semantic.DeepEqual(listFirst, expectedList) { - t.Fatal(diff.ObjectGoPrintDiff(expectedList, listFirst)) + t.Fatal(cmp.Diff(expectedList, listFirst)) } } @@ -242,7 +241,7 @@ func (tc *patchTestCase) verifyResult(result *unstructured.Unstructured) error { return nil } if !equality.Semantic.DeepEqual(result, tc.expectedPatchedObject) { - return fmt.Errorf("unexpected diff in received object: %s", diff.ObjectGoPrintDiff(tc.expectedPatchedObject, result)) + return fmt.Errorf("unexpected diff in received object: %s", cmp.Diff(tc.expectedPatchedObject, result)) } return nil } diff --git a/staging/src/k8s.io/client-go/metadata/fake/simple_test.go b/staging/src/k8s.io/client-go/metadata/fake/simple_test.go index 219be4e7ea4..a8369f9f1fb 100644 --- a/staging/src/k8s.io/client-go/metadata/fake/simple_test.go +++ b/staging/src/k8s.io/client-go/metadata/fake/simple_test.go @@ -21,12 +21,12 @@ import ( "fmt" "testing" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" ) const ( @@ -79,7 +79,7 @@ func TestList(t *testing.T) { *newPartialObjectMetadata("group/version", "TheKind", "ns-foo", "name-foo"), } if !equality.Semantic.DeepEqual(listFirst.Items, expected) { - t.Fatal(diff.ObjectGoPrintDiff(expected, listFirst.Items)) + t.Fatal(cmp.Diff(expected, listFirst.Items)) } } @@ -134,7 +134,7 @@ func (tc *patchTestCase) verifyResult(result *metav1.PartialObjectMetadata) erro return nil } if !equality.Semantic.DeepEqual(result, tc.expectedPatchedObject) { - return fmt.Errorf("unexpected diff in received object: %s", diff.ObjectGoPrintDiff(tc.expectedPatchedObject, result)) + return fmt.Errorf("unexpected diff in received object: %s", cmp.Diff(tc.expectedPatchedObject, result)) } return nil } diff --git a/staging/src/k8s.io/client-go/metadata/metadata_test.go b/staging/src/k8s.io/client-go/metadata/metadata_test.go index 5e34f008619..ff52b5a129d 100644 --- a/staging/src/k8s.io/client-go/metadata/metadata_test.go +++ b/staging/src/k8s.io/client-go/metadata/metadata_test.go @@ -26,11 +26,11 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/rest" ) @@ -89,7 +89,7 @@ func TestClient(t *testing.T) { }, } if !reflect.DeepEqual(expect, obj) { - t.Fatal(diff.ObjectReflectDiff(expect, obj)) + t.Fatal(cmp.Diff(expect, obj)) } }, }, @@ -146,7 +146,7 @@ func TestClient(t *testing.T) { }, } if !reflect.DeepEqual(expect, objs.Items) { - t.Fatal(diff.ObjectReflectDiff(expect, objs.Items)) + t.Fatal(cmp.Diff(expect, objs.Items)) } }, }, diff --git a/staging/src/k8s.io/client-go/metadata/metadatainformer/informer_test.go b/staging/src/k8s.io/client-go/metadata/metadatainformer/informer_test.go index 2c7b9ab420a..f52dbf06165 100644 --- a/staging/src/k8s.io/client-go/metadata/metadatainformer/informer_test.go +++ b/staging/src/k8s.io/client-go/metadata/metadatainformer/informer_test.go @@ -22,13 +22,13 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "k8s.io/klog/v2" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/metadata/fake" "k8s.io/client-go/tools/cache" ) @@ -147,7 +147,7 @@ func TestMetadataSharedInformerFactory(t *testing.T) { select { case objFromInformer := <-informerReciveObjectCh: if !equality.Semantic.DeepEqual(testObject, objFromInformer) { - t.Fatalf("%v", diff.ObjectDiff(testObject, objFromInformer)) + t.Fatalf("%v", cmp.Diff(testObject, objFromInformer)) } case <-ctx.Done(): t.Errorf("tested informer haven't received an object, waited %v", timeout) diff --git a/staging/src/k8s.io/client-go/metadata/metadatalister/lister_test.go b/staging/src/k8s.io/client-go/metadata/metadatalister/lister_test.go index 7c32c1e7f38..a0e8e05818e 100644 --- a/staging/src/k8s.io/client-go/metadata/metadatalister/lister_test.go +++ b/staging/src/k8s.io/client-go/metadata/metadatalister/lister_test.go @@ -20,11 +20,11 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/tools/cache" ) @@ -89,7 +89,7 @@ func TestNamespaceGetMethod(t *testing.T) { t.Fatal(err) } if !reflect.DeepEqual(test.expectedObject, actualObject) { - t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, diff.ObjectDiff(test.expectedObject, actualObject)) + t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, cmp.Diff(test.expectedObject, actualObject)) } }) } @@ -187,7 +187,7 @@ func TestListerGetMethod(t *testing.T) { t.Fatal(err) } if !reflect.DeepEqual(test.expectedObject, actualObject) { - t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, diff.ObjectDiff(test.expectedObject, actualObject)) + t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", test.expectedObject, actualObject, cmp.Diff(test.expectedObject, actualObject)) } }) } @@ -231,7 +231,7 @@ func assertListOrDie(expected, actual []*metav1.PartialObjectMetadata, t *testin for _, actualObject := range actual { if actualObject.GetName() == expectedObject.GetName() { if !reflect.DeepEqual(expectedObject, actualObject) { - t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", expectedObject, actualObject, diff.ObjectDiff(expectedObject, actualObject)) + t.Fatalf("unexpected object has been returned expected = %v actual = %v, diff = %v", expectedObject, actualObject, cmp.Diff(expectedObject, actualObject)) } found = true } diff --git a/staging/src/k8s.io/client-go/rest/request_test.go b/staging/src/k8s.io/client-go/rest/request_test.go index 9c36c0de30c..c833c555604 100644 --- a/staging/src/k8s.io/client-go/rest/request_test.go +++ b/staging/src/k8s.io/client-go/rest/request_test.go @@ -45,7 +45,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/runtime/serializer/streaming" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/intstr" utilnet "k8s.io/apimachinery/pkg/util/net" "k8s.io/apimachinery/pkg/watch" @@ -925,22 +924,22 @@ func TestTransformUnstructuredError(t *testing.T) { expect = err } if !reflect.DeepEqual(expect, transformed) { - t.Errorf("unexpected Error(): %s", diff.ObjectReflectDiff(expect, transformed)) + t.Errorf("unexpected Error(): %s", cmp.Diff(expect, transformed)) } // verify result.Get properly transforms the error if _, err := result.Get(); !reflect.DeepEqual(expect, err) { - t.Errorf("unexpected error on Get(): %s", diff.ObjectReflectDiff(expect, err)) + t.Errorf("unexpected error on Get(): %s", cmp.Diff(expect, err)) } // verify result.Into properly handles the error if err := result.Into(&v1.Pod{}); !reflect.DeepEqual(expect, err) { - t.Errorf("unexpected error on Into(): %s", diff.ObjectReflectDiff(expect, err)) + t.Errorf("unexpected error on Into(): %s", cmp.Diff(expect, err)) } // verify result.Raw leaves the error in the untransformed state if _, err := result.Raw(); !reflect.DeepEqual(result.err, err) { - t.Errorf("unexpected error on Raw(): %s", diff.ObjectReflectDiff(expect, err)) + t.Errorf("unexpected error on Raw(): %s", cmp.Diff(expect, err)) } }) } @@ -1220,7 +1219,7 @@ func TestRequestWatch(t *testing.T) { t.Fatalf("Watch closed early, %d/%d read", i, len(testCase.Expect)) } if !reflect.DeepEqual(evt, out) { - t.Fatalf("Event %d does not match: %s", i, diff.ObjectReflectDiff(evt, out)) + t.Fatalf("Event %d does not match: %s", i, cmp.Diff(evt, out)) } } } diff --git a/staging/src/k8s.io/client-go/tools/clientcmd/loader_test.go b/staging/src/k8s.io/client-go/tools/clientcmd/loader_test.go index b641d1a2b79..ba42e56f76f 100644 --- a/staging/src/k8s.io/client-go/tools/clientcmd/loader_test.go +++ b/staging/src/k8s.io/client-go/tools/clientcmd/loader_test.go @@ -26,10 +26,10 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" "sigs.k8s.io/yaml" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" clientcmdlatest "k8s.io/client-go/tools/clientcmd/api/latest" ) @@ -248,7 +248,7 @@ preferences: {} users: null `) if !bytes.Equal(expected, data) { - t.Error(diff.ObjectReflectDiff(string(expected), string(data))) + t.Error(cmp.Diff(string(expected), string(data))) } } diff --git a/staging/src/k8s.io/client-go/tools/events/event_broadcaster_test.go b/staging/src/k8s.io/client-go/tools/events/event_broadcaster_test.go index 23685b7919a..ac7f7abe80f 100644 --- a/staging/src/k8s.io/client-go/tools/events/event_broadcaster_test.go +++ b/staging/src/k8s.io/client-go/tools/events/event_broadcaster_test.go @@ -21,9 +21,9 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" eventsv1 "k8s.io/api/events/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/client-go/kubernetes/fake" ) @@ -96,7 +96,7 @@ func TestRecordEventToSink(t *testing.T) { recordedEvent := recordedEvents.Items[0] if !reflect.DeepEqual(recordedEvent, tc.expectedRecordedEvent) { - t.Errorf("expected to have recorded Event: %#+v, got: %#+v\n diff: %s", tc.expectedRecordedEvent, recordedEvent, diff.ObjectReflectDiff(tc.expectedRecordedEvent, recordedEvent)) + t.Errorf("expected to have recorded Event: %#+v, got: %#+v\n diff: %s", tc.expectedRecordedEvent, recordedEvent, cmp.Diff(tc.expectedRecordedEvent, recordedEvent)) } }) } diff --git a/staging/src/k8s.io/client-go/tools/leaderelection/leaderelection_test.go b/staging/src/k8s.io/client-go/tools/leaderelection/leaderelection_test.go index ed4e89ae76a..b3e8bea7aa4 100644 --- a/staging/src/k8s.io/client-go/tools/leaderelection/leaderelection_test.go +++ b/staging/src/k8s.io/client-go/tools/leaderelection/leaderelection_test.go @@ -24,13 +24,13 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" coordinationv1 "k8s.io/api/coordination/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes/fake" fakeclient "k8s.io/client-go/testing" @@ -371,13 +371,13 @@ func TestLeaseSpecToLeaderElectionRecordRoundTrip(t *testing.T) { newSpec := rl.LeaderElectionRecordToLeaseSpec(oldRecord) if !equality.Semantic.DeepEqual(oldSpec, newSpec) { - t.Errorf("diff: %v", diff.ObjectReflectDiff(oldSpec, newSpec)) + t.Errorf("diff: %v", cmp.Diff(oldSpec, newSpec)) } newRecord := rl.LeaseSpecToLeaderElectionRecord(&newSpec) if !equality.Semantic.DeepEqual(oldRecord, newRecord) { - t.Errorf("diff: %v", diff.ObjectReflectDiff(oldRecord, newRecord)) + t.Errorf("diff: %v", cmp.Diff(oldRecord, newRecord)) } } diff --git a/staging/src/k8s.io/client-go/tools/record/events_cache_test.go b/staging/src/k8s.io/client-go/tools/record/events_cache_test.go index 2ede35508c9..7c9c931604c 100644 --- a/staging/src/k8s.io/client-go/tools/record/events_cache_test.go +++ b/staging/src/k8s.io/client-go/tools/record/events_cache_test.go @@ -23,9 +23,9 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" testclocks "k8s.io/utils/clock/testing" ) @@ -121,7 +121,7 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v } recvEvent.Name = expectedEvent.Name if e, a := expectedEvent, &recvEvent; !reflect.DeepEqual(e, a) { - t.Errorf("%v - diff: %s", messagePrefix, diff.ObjectGoPrintDiff(e, a)) + t.Errorf("%v - diff: %s", messagePrefix, cmp.Diff(e, a)) } recvEvent.FirstTimestamp = actualFirstTimestamp recvEvent.LastTimestamp = actualLastTimestamp diff --git a/staging/src/k8s.io/client-go/tools/watch/informerwatcher_test.go b/staging/src/k8s.io/client-go/tools/watch/informerwatcher_test.go index ce029b464d1..138502c889e 100644 --- a/staging/src/k8s.io/client-go/tools/watch/informerwatcher_test.go +++ b/staging/src/k8s.io/client-go/tools/watch/informerwatcher_test.go @@ -25,13 +25,13 @@ import ( "time" "github.com/davecgh/go-spew/spew" + "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/watch" fakeclientset "k8s.io/client-go/kubernetes/fake" testcore "k8s.io/client-go/testing" @@ -260,7 +260,7 @@ func TestNewInformerWatcher(t *testing.T) { sort.Sort(byEventTypeAndName(result)) if !reflect.DeepEqual(expected, result) { - t.Error(spew.Errorf("\nexpected: %#v,\ngot: %#v,\ndiff: %s", expected, result, diff.ObjectReflectDiff(expected, result))) + t.Error(spew.Errorf("\nexpected: %#v,\ngot: %#v,\ndiff: %s", expected, result, cmp.Diff(expected, result))) return } diff --git a/staging/src/k8s.io/client-go/tools/watch/retrywatcher_test.go b/staging/src/k8s.io/client-go/tools/watch/retrywatcher_test.go index 8adaa4b834e..3871d98b468 100644 --- a/staging/src/k8s.io/client-go/tools/watch/retrywatcher_test.go +++ b/staging/src/k8s.io/client-go/tools/watch/retrywatcher_test.go @@ -27,12 +27,12 @@ import ( "time" "github.com/davecgh/go-spew/spew" + "github.com/google/go-cmp/cmp" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/tools/cache" @@ -564,7 +564,7 @@ func TestRetryWatcher(t *testing.T) { } if !reflect.DeepEqual(tc.expected, got) { - t.Fatal(spew.Errorf("expected %#+v, got %#+v;\ndiff: %s", tc.expected, got, diff.ObjectReflectDiff(tc.expected, got))) + t.Fatal(spew.Errorf("expected %#+v, got %#+v;\ndiff: %s", tc.expected, got, cmp.Diff(tc.expected, got))) } }) } diff --git a/staging/src/k8s.io/cloud-provider/options/options_test.go b/staging/src/k8s.io/cloud-provider/options/options_test.go index ea3a1bb09b7..9f750dc9dc0 100644 --- a/staging/src/k8s.io/cloud-provider/options/options_test.go +++ b/staging/src/k8s.io/cloud-provider/options/options_test.go @@ -23,9 +23,9 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "github.com/spf13/pflag" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" apiserver "k8s.io/apiserver/pkg/server" apiserveroptions "k8s.io/apiserver/pkg/server/options" appconfig "k8s.io/cloud-provider/app/config" @@ -150,7 +150,7 @@ func TestDefaultFlags(t *testing.T) { NodeStatusUpdateFrequency: metav1.Duration{Duration: 5 * time.Minute}, } if !reflect.DeepEqual(expected, s) { - t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", diff.ObjectReflectDiff(expected, s)) + t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", cmp.Diff(expected, s)) } } @@ -309,7 +309,7 @@ func TestAddFlags(t *testing.T) { NodeStatusUpdateFrequency: metav1.Duration{Duration: 10 * time.Minute}, } if !reflect.DeepEqual(expected, s) { - t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", diff.ObjectReflectDiff(expected, s)) + t.Errorf("Got different run options than expected.\nDifference detected on:\n%s", cmp.Diff(expected, s)) } } @@ -444,6 +444,6 @@ func TestCreateConfig(t *testing.T) { c.LoopbackClientConfig = nil if !reflect.DeepEqual(expected, c) { - t.Errorf("Got different config than expected.\nDifference detected on:\n%s", diff.ObjectReflectDiff(expected, c)) + t.Errorf("Got different config than expected.\nDifference detected on:\n%s", cmp.Diff(expected, c)) } } diff --git a/staging/src/k8s.io/component-helpers/apimachinery/lease/controller_test.go b/staging/src/k8s.io/component-helpers/apimachinery/lease/controller_test.go index 0efcd6bbd15..42ab50efe5e 100644 --- a/staging/src/k8s.io/component-helpers/apimachinery/lease/controller_test.go +++ b/staging/src/k8s.io/component-helpers/apimachinery/lease/controller_test.go @@ -23,6 +23,7 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" coordinationv1 "k8s.io/api/coordination/v1" corev1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" @@ -31,7 +32,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/fake" clienttesting "k8s.io/client-go/testing" @@ -205,7 +205,7 @@ func TestNewNodeLease(t *testing.T) { t.Fatalf("the new lease must be newly allocated, but got same address as base") } if !apiequality.Semantic.DeepEqual(tc.expect, newLease) { - t.Errorf("unexpected result from newLease: %s", diff.ObjectDiff(tc.expect, newLease)) + t.Errorf("unexpected result from newLease: %s", cmp.Diff(tc.expect, newLease)) } }) } diff --git a/staging/src/k8s.io/component-helpers/auth/rbac/reconciliation/reconcile_role_test.go b/staging/src/k8s.io/component-helpers/auth/rbac/reconciliation/reconcile_role_test.go index fe50ecccfb2..328e1c720f6 100644 --- a/staging/src/k8s.io/component-helpers/auth/rbac/reconciliation/reconcile_role_test.go +++ b/staging/src/k8s.io/component-helpers/auth/rbac/reconciliation/reconcile_role_test.go @@ -19,10 +19,10 @@ package reconciliation import ( "testing" + "github.com/google/go-cmp/cmp" rbacv1 "k8s.io/api/rbac/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" ) func role(rules []rbacv1.PolicyRule, labels map[string]string, annotations map[string]string) *rbacv1.ClusterRole { @@ -392,7 +392,7 @@ func TestComputeReconciledRoleAggregationRules(t *testing.T) { continue } if reconciliationNeeded && !apiequality.Semantic.DeepEqual(result.Role.(ClusterRoleRuleOwner).ClusterRole, tc.expectedReconciledRole) { - t.Errorf("%s: %v", k, diff.ObjectDiff(tc.expectedReconciledRole, result.Role.(ClusterRoleRuleOwner).ClusterRole)) + t.Errorf("%s: %v", k, cmp.Diff(tc.expectedReconciledRole, result.Role.(ClusterRoleRuleOwner).ClusterRole)) } } } diff --git a/staging/src/k8s.io/kube-aggregator/go.mod b/staging/src/k8s.io/kube-aggregator/go.mod index b73b93b10ad..e926f110fe9 100644 --- a/staging/src/k8s.io/kube-aggregator/go.mod +++ b/staging/src/k8s.io/kube-aggregator/go.mod @@ -8,6 +8,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/emicklei/go-restful/v3 v3.9.0 github.com/gogo/protobuf v1.3.2 + github.com/google/go-cmp v0.5.9 github.com/google/gofuzz v1.1.0 github.com/spf13/cobra v1.6.0 github.com/spf13/pflag v1.0.5 @@ -47,7 +48,6 @@ require ( github.com/golang/protobuf v1.5.3 // indirect github.com/google/cel-go v0.12.6 // indirect github.com/google/gnostic v0.5.7-v3refs // indirect - github.com/google/go-cmp v0.5.9 // indirect github.com/google/uuid v1.3.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_apis_test.go b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_apis_test.go index 9da23acf12c..600b2070e93 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_apis_test.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_apis_test.go @@ -23,10 +23,10 @@ import ( "net/http/httputil" "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/tools/cache" @@ -327,7 +327,7 @@ func TestAPIs(t *testing.T) { continue } if !apiequality.Semantic.DeepEqual(tc.expected, actual) { - t.Errorf("%s: %v", tc.name, diff.ObjectDiff(tc.expected, actual)) + t.Errorf("%s: %v", tc.name, cmp.Diff(tc.expected, actual)) continue } } @@ -514,7 +514,7 @@ func TestAPIGroup(t *testing.T) { continue } if !apiequality.Semantic.DeepEqual(tc.expected, actual) { - t.Errorf("%s: %v", tc.name, diff.ObjectDiff(tc.expected, actual)) + t.Errorf("%s: %v", tc.name, cmp.Diff(tc.expected, actual)) continue } } diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/config/config_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/config/config_test.go index 95fabbcb799..9f5cc01c774 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/config/config_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/config/config_test.go @@ -24,8 +24,8 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" apiequality "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/cli-runtime/pkg/genericiooptions" "k8s.io/client-go/tools/clientcmd" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" @@ -896,7 +896,7 @@ func (test configCommandTest) run(t *testing.T) string { testClearLocationOfOrigin(&actualConfig) if !apiequality.Semantic.DeepEqual(test.expectedConfig, actualConfig) { - t.Errorf("diff: %v", diff.ObjectDiff(test.expectedConfig, actualConfig)) + t.Errorf("diff: %v", cmp.Diff(test.expectedConfig, actualConfig)) t.Errorf("expected: %#v\n actual: %#v", test.expectedConfig, actualConfig) } diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/config/navigation_step_parser_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/config/navigation_step_parser_test.go index 2ce0892cd2a..b73d6ac024a 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/config/navigation_step_parser_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/config/navigation_step_parser_test.go @@ -21,7 +21,7 @@ import ( "strings" "testing" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" ) @@ -102,7 +102,7 @@ func (test stepParserTest) run(t *testing.T) { } if !reflect.DeepEqual(test.expectedNavigationSteps, *actualSteps) { - t.Errorf("diff: %v", diff.ObjectDiff(test.expectedNavigationSteps, *actualSteps)) + t.Errorf("diff: %v", cmp.Diff(test.expectedNavigationSteps, *actualSteps)) t.Errorf("expected: %#v\n actual: %#v", test.expectedNavigationSteps, *actualSteps) } } diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_role_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_role_test.go index d3116b425f6..a9e1d65f59d 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_role_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_role_test.go @@ -20,12 +20,12 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" rbac "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions" "k8s.io/client-go/rest/fake" @@ -150,7 +150,7 @@ func TestCreateRole(t *testing.T) { t.Fatal(err) } if !equality.Semantic.DeepEqual(test.expectedRole, actual) { - t.Errorf("%s", diff.ObjectReflectDiff(test.expectedRole, actual)) + t.Errorf("%s", cmp.Diff(test.expectedRole, actual)) } }) } diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/edit/edit_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/edit/edit_test.go index 42acf702407..c4746f4ebd6 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/edit/edit_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/edit/edit_test.go @@ -27,12 +27,12 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" "github.com/spf13/cobra" yaml "gopkg.in/yaml.v2" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/cli-runtime/pkg/genericiooptions" "k8s.io/cli-runtime/pkg/resource" @@ -124,7 +124,7 @@ func TestEdit(t *testing.T) { // Convenience to allow recapturing the input and persisting it here os.WriteFile(inputFile, body, os.FileMode(0644)) } else { - t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput))) + t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, cmp.Diff(string(body), string(expectedInput))) t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar) } } @@ -147,7 +147,7 @@ func TestEdit(t *testing.T) { // Convenience to allow recapturing the input and persisting it here os.WriteFile(inputFile, body, os.FileMode(0644)) } else { - t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, diff.StringDiff(string(body), string(expectedInput))) + t.Errorf("%s, step %d: diff in edit content:\n%s", name, i, cmp.Diff(string(body), string(expectedInput))) t.Logf("If the change in input is expected, rerun tests with %s=true to update input fixtures", updateEnvVar) } } diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/get/get_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/get/get_test.go index c73bd15a3e0..0776b6740be 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/get/get_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/get/get_test.go @@ -26,6 +26,7 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" appsv1 "k8s.io/api/apps/v1" autoscalingv1 "k8s.io/api/autoscaling/v1" batchv1 "k8s.io/api/batch/v1" @@ -36,7 +37,6 @@ import ( metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer/streaming" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/watch" "k8s.io/cli-runtime/pkg/genericiooptions" "k8s.io/cli-runtime/pkg/resource" @@ -1497,7 +1497,7 @@ func TestGetMultipleTypeObjectsAsList(t *testing.T) { } ` if e, a := expected, buf.String(); e != a { - t.Errorf("did not match: %v", diff.StringDiff(e, a)) + t.Errorf("did not match:\n%v", cmp.Diff(e, a)) } } diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/get/sorter_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/get/sorter_test.go index f0ddace35f7..fd412a5740c 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/get/sorter_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/get/sorter_test.go @@ -22,6 +22,7 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/resource" @@ -29,7 +30,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubectl/pkg/scheme" ) @@ -677,7 +677,7 @@ func TestSortingPrinter(t *testing.T) { t.Fatalf("%s: expected error containing: %q, got none", tt.name, tt.expectedErr) } if !reflect.DeepEqual(table, expectedTable) { - t.Errorf("[%s]\nexpected/saw:\n%s", tt.name, diff.ObjectReflectDiff(expectedTable, table)) + t.Errorf("[%s]\nexpected/saw:\n%s", tt.name, cmp.Diff(expectedTable, table)) } }) t.Run(tt.name, func(t *testing.T) { diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/util/helpers_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/util/helpers_test.go index 98ffe8cc792..7cf0d70832b 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/util/helpers_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/util/helpers_test.go @@ -36,7 +36,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/kubectl/pkg/scheme" "k8s.io/utils/exec" @@ -155,7 +154,7 @@ func TestMerge(t *testing.T) { if err != nil { t.Errorf("testcase[%d], unexpected error: %v", i, err) } else if !apiequality.Semantic.DeepEqual(test.expected, out) { - t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, diff.ObjectReflectDiff(test.expected, out)) + t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, cmp.Diff(test.expected, out)) } } if test.expectErr && err == nil { @@ -238,7 +237,7 @@ func TestStrategicMerge(t *testing.T) { if err != nil { t.Errorf("testcase[%d], unexpected error: %v", i, err) } else if !apiequality.Semantic.DeepEqual(test.expected, out) { - t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, diff.ObjectReflectDiff(test.expected, out)) + t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, cmp.Diff(test.expected, out)) } } if test.expectErr && err == nil { @@ -300,7 +299,7 @@ func TestJSONPatch(t *testing.T) { if err != nil { t.Errorf("testcase[%d], unexpected error: %v", i, err) } else if !apiequality.Semantic.DeepEqual(test.expected, out) { - t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, diff.ObjectReflectDiff(test.expected, out)) + t.Errorf("\n\ntestcase[%d]\nexpected:\n%s", i, cmp.Diff(test.expected, out)) } } if test.expectErr && err == nil { diff --git a/staging/src/k8s.io/kubectl/pkg/explain/formatter_test.go b/staging/src/k8s.io/kubectl/pkg/explain/formatter_test.go index 41db9f55e60..1cf68a090af 100644 --- a/staging/src/k8s.io/kubectl/pkg/explain/formatter_test.go +++ b/staging/src/k8s.io/kubectl/pkg/explain/formatter_test.go @@ -20,7 +20,7 @@ import ( "bytes" "testing" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" ) func TestFormatterWrite(t *testing.T) { @@ -113,7 +113,7 @@ fringilla velit. ` if buf.String() != want { - t.Errorf("Diff:\n%s", diff.StringDiff(buf.String(), want)) + t.Errorf("Diff:\n%s", cmp.Diff(buf.String(), want)) } } diff --git a/staging/src/k8s.io/kubectl/pkg/polymorphichelpers/logsforobject_test.go b/staging/src/k8s.io/kubectl/pkg/polymorphichelpers/logsforobject_test.go index 0d002dc2905..123d78db2ac 100644 --- a/staging/src/k8s.io/kubectl/pkg/polymorphichelpers/logsforobject_test.go +++ b/staging/src/k8s.io/kubectl/pkg/polymorphichelpers/logsforobject_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" @@ -29,7 +30,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" fakeexternal "k8s.io/client-go/kubernetes/fake" testclient "k8s.io/client-go/testing" "k8s.io/kubectl/pkg/cmd/util/podcmd" @@ -422,7 +422,7 @@ func TestLogsForObject(t *testing.T) { got := fakeClientset.Actions()[i] want := test.actions[i] if !reflect.DeepEqual(got, want) { - t.Errorf("%s: unexpected diff for action: %s", test.name, diff.ObjectDiff(got, want)) + t.Errorf("%s: unexpected diff for action: %s", test.name, cmp.Diff(got, want)) } } for i++; i < len(fakeClientset.Actions()); i++ { diff --git a/staging/src/k8s.io/kubectl/pkg/scheme/sparse_test.go b/staging/src/k8s.io/kubectl/pkg/scheme/sparse_test.go index 0ebca6f909a..552a5683ef6 100644 --- a/staging/src/k8s.io/kubectl/pkg/scheme/sparse_test.go +++ b/staging/src/k8s.io/kubectl/pkg/scheme/sparse_test.go @@ -19,11 +19,11 @@ package scheme import ( "testing" - "k8s.io/api/batch/v1" + "github.com/google/go-cmp/cmp" + v1 "k8s.io/api/batch/v1" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" ) func TestCronJob(t *testing.T) { @@ -48,6 +48,6 @@ func TestCronJob(t *testing.T) { uncastDst.(*v1.CronJob).TypeMeta = metav1.TypeMeta{} if !equality.Semantic.DeepEqual(src, uncastDst) { - t.Fatal(diff.ObjectDiff(src, uncastDst)) + t.Fatal(cmp.Diff(src, uncastDst)) } } diff --git a/staging/src/k8s.io/pod-security-admission/test/fixtures_test.go b/staging/src/k8s.io/pod-security-admission/test/fixtures_test.go index 481436baec3..bd386b61183 100644 --- a/staging/src/k8s.io/pod-security-admission/test/fixtures_test.go +++ b/staging/src/k8s.io/pod-security-admission/test/fixtures_test.go @@ -24,9 +24,9 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/kubernetes/scheme" "k8s.io/pod-security-admission/api" @@ -167,7 +167,7 @@ func testFixtureFile(t *testing.T, dir, name string, pod *corev1.Pod) string { t.Logf("Could not update data in %s: %v", filename, err) } } else { - t.Logf("Diff between generated data and fixture data in %s:\n-------------\n%s", filename, diff.StringDiff(string(yamlData), string(expectedYAML))) + t.Logf("Diff between generated data and fixture data in %s:\n-------------\n%s", filename, cmp.Diff(string(yamlData), string(expectedYAML))) t.Logf("If the change is expected, re-run with %s=true to update the fixtures", updateEnvVar) } } diff --git a/test/e2e/apimachinery/custom_resource_definition.go b/test/e2e/apimachinery/custom_resource_definition.go index f4454a05bb9..c1922ea21e0 100644 --- a/test/e2e/apimachinery/custom_resource_definition.go +++ b/test/e2e/apimachinery/custom_resource_definition.go @@ -21,6 +21,7 @@ import ( "fmt" "time" + "github.com/google/go-cmp/cmp" "github.com/onsi/ginkgo/v2" v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" @@ -32,7 +33,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apiserver/pkg/storage/names" @@ -125,7 +125,7 @@ var _ = SIGDescribe("CustomResourceDefinition resources [Privileged:ClusterAdmin framework.ExpectNotEqual(expected, nil) if !equality.Semantic.DeepEqual(actual.Spec, expected.Spec) { framework.Failf("Expected CustomResourceDefinition in list with name %s to match crd created with same name, but got different specs:\n%s", - actual.Name, diff.ObjectReflectDiff(expected.Spec, actual.Spec)) + actual.Name, cmp.Diff(expected.Spec, actual.Spec)) } } @@ -169,7 +169,7 @@ var _ = SIGDescribe("CustomResourceDefinition resources [Privileged:ClusterAdmin framework.ExpectNoError(err, "getting CustomResourceDefinition status") status := unstructuredToCRD(u) if !equality.Semantic.DeepEqual(status.Spec, crd.Spec) { - framework.Failf("Expected CustomResourceDefinition Spec to match status sub-resource Spec, but got:\n%s", diff.ObjectReflectDiff(status.Spec, crd.Spec)) + framework.Failf("Expected CustomResourceDefinition Spec to match status sub-resource Spec, but got:\n%s", cmp.Diff(status.Spec, crd.Spec)) } status.Status.Conditions = append(status.Status.Conditions, updateCondition) updated, err = apiExtensionClient.ApiextensionsV1().CustomResourceDefinitions().UpdateStatus(ctx, status, metav1.UpdateOptions{}) diff --git a/test/e2e/common/node/node_lease.go b/test/e2e/common/node/node_lease.go index 28aa9b64672..20fe25f26ea 100644 --- a/test/e2e/common/node/node_lease.go +++ b/test/e2e/common/node/node_lease.go @@ -25,7 +25,6 @@ import ( v1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/wait" clientset "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/test/e2e/framework" @@ -33,6 +32,7 @@ import ( testutils "k8s.io/kubernetes/test/utils" admissionapi "k8s.io/pod-security-admission/api" + "github.com/google/go-cmp/cmp" "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" ) @@ -159,7 +159,7 @@ var _ = SIGDescribe("NodeLease", func() { if !apiequality.Semantic.DeepEqual(lastStatus, currentStatus) { // heartbeat time changed, but there were relevant changes in the status, keep waiting framework.Logf("node status heartbeat changed in %s (with other status changes), waiting for %s", currentHeartbeatTime.Sub(lastHeartbeatTime), leaseDuration) - framework.Logf("%s", diff.ObjectReflectDiff(lastStatus, currentStatus)) + framework.Logf("%s", cmp.Diff(lastStatus, currentStatus)) lastHeartbeatTime = currentHeartbeatTime lastObserved = currentObserved lastStatus = currentStatus diff --git a/test/e2e/instrumentation/core_events.go b/test/e2e/instrumentation/core_events.go index a4e64c18dd2..31a0c08c812 100644 --- a/test/e2e/instrumentation/core_events.go +++ b/test/e2e/instrumentation/core_events.go @@ -24,12 +24,12 @@ import ( v1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/instrumentation/common" admissionapi "k8s.io/pod-security-admission/api" + "github.com/google/go-cmp/cmp" "github.com/onsi/ginkgo/v2" "k8s.io/apimachinery/pkg/types" ) @@ -140,7 +140,7 @@ var _ = common.SIGDescribe("Events", func() { event.ObjectMeta.ResourceVersion = "" event.ObjectMeta.ManagedFields = nil if !apiequality.Semantic.DeepEqual(testEvent, event) { - framework.Failf("test event wasn't properly updated: %v", diff.ObjectReflectDiff(testEvent, event)) + framework.Failf("test event wasn't properly updated: %v", cmp.Diff(testEvent, event)) } ginkgo.By("deleting the test event") diff --git a/test/e2e/instrumentation/events.go b/test/e2e/instrumentation/events.go index 493feae1140..2c5d95f8436 100644 --- a/test/e2e/instrumentation/events.go +++ b/test/e2e/instrumentation/events.go @@ -26,7 +26,6 @@ import ( eventsv1 "k8s.io/api/events/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/strategicpatch" corev1 "k8s.io/client-go/kubernetes/typed/core/v1" typedeventsv1 "k8s.io/client-go/kubernetes/typed/events/v1" @@ -34,6 +33,7 @@ import ( "k8s.io/kubernetes/test/e2e/instrumentation/common" admissionapi "k8s.io/pod-security-admission/api" + "github.com/google/go-cmp/cmp" "github.com/onsi/ginkgo/v2" "k8s.io/apimachinery/pkg/types" ) @@ -160,7 +160,7 @@ var _ = common.SIGDescribe("Events API", func() { testEvent.Series = eventSeries if !apiequality.Semantic.DeepEqual(testEvent, event) { - framework.Failf("test event wasn't properly patched: %v", diff.ObjectReflectDiff(testEvent, event)) + framework.Failf("test event wasn't properly patched: %v", cmp.Diff(testEvent, event)) } ginkgo.By("updating the test event") @@ -178,7 +178,7 @@ var _ = common.SIGDescribe("Events API", func() { event.ObjectMeta.ResourceVersion = "" event.ObjectMeta.ManagedFields = nil if !apiequality.Semantic.DeepEqual(testEvent, event) { - framework.Failf("test event wasn't properly updated: %v", diff.ObjectReflectDiff(testEvent, event)) + framework.Failf("test event wasn't properly updated: %v", cmp.Diff(testEvent, event)) } ginkgo.By("deleting the test event") diff --git a/test/e2e/node/pod_resize.go b/test/e2e/node/pod_resize.go index 5a37f4075dd..3f805c2a9ca 100644 --- a/test/e2e/node/pod_resize.go +++ b/test/e2e/node/pod_resize.go @@ -29,7 +29,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/diff" clientset "k8s.io/client-go/kubernetes" podutil "k8s.io/kubernetes/pkg/api/v1/pod" resourceapi "k8s.io/kubernetes/pkg/api/v1/resource" @@ -43,6 +42,7 @@ import ( imageutils "k8s.io/kubernetes/test/utils/image" semver "github.com/blang/semver/v4" + "github.com/google/go-cmp/cmp" "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" ) @@ -281,7 +281,7 @@ func verifyPodAllocations(pod *v1.Pod, tcInfo []TestContainerInfo, flagError boo if flagError { framework.ExpectEqual(tcStatus.AllocatedResources, cStatus.AllocatedResources) } - if diff.ObjectDiff(cStatus.AllocatedResources, tcStatus.AllocatedResources) != "" { + if !cmp.Equal(cStatus.AllocatedResources, tcStatus.AllocatedResources) { return false } } @@ -453,7 +453,7 @@ func waitForPodResizeActuation(c clientset.Interface, podClient *e2epod.PodClien } differs := false for idx, c := range pod.Spec.Containers { - if diff.ObjectDiff(c.Resources, *pod.Status.ContainerStatuses[idx].Resources) != "" { + if !cmp.Equal(c.Resources, *pod.Status.ContainerStatuses[idx].Resources) { differs = true break } diff --git a/test/images/agnhost/webhook/convert_test.go b/test/images/agnhost/webhook/convert_test.go index d1b9dba55d3..9c8143d41f6 100644 --- a/test/images/agnhost/webhook/convert_test.go +++ b/test/images/agnhost/webhook/convert_test.go @@ -22,6 +22,7 @@ import ( "reflect" "testing" + "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" v1 "k8s.io/api/admission/v1" @@ -29,7 +30,6 @@ import ( "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" - "k8s.io/apimachinery/pkg/util/diff" admissionfuzzer "k8s.io/kubernetes/pkg/apis/admission/fuzzer" ) @@ -42,7 +42,7 @@ func TestConvertAdmissionRequestToV1(t *testing.T) { converted := convertAdmissionRequestToV1(orig) rt := convertAdmissionRequestToV1beta1(converted) if !reflect.DeepEqual(orig, rt) { - t.Errorf("expected all request fields to be in converted object but found unaccounted for differences, diff:\n%s", diff.ObjectReflectDiff(orig, converted)) + t.Errorf("expected all request fields to be in converted object but found unaccounted for differences, diff:\n%s", cmp.Diff(orig, converted)) } }) } @@ -57,7 +57,7 @@ func TestConvertAdmissionResponseToV1beta1(t *testing.T) { converted := convertAdmissionResponseToV1beta1(orig) rt := convertAdmissionResponseToV1(converted) if !reflect.DeepEqual(orig, rt) { - t.Errorf("expected all fields to be in converted object but found unaccounted for differences, diff:\n%s", diff.ObjectReflectDiff(orig, converted)) + t.Errorf("expected all fields to be in converted object but found unaccounted for differences, diff:\n%s", cmp.Diff(orig, converted)) } }) } diff --git a/test/integration/etcd/etcd_storage_path_test.go b/test/integration/etcd/etcd_storage_path_test.go index c5ecbe42816..53c24eb37c6 100644 --- a/test/integration/etcd/etcd_storage_path_test.go +++ b/test/integration/etcd/etcd_storage_path_test.go @@ -25,6 +25,7 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" clientv3 "go.etcd.io/etcd/client/v3" v1 "k8s.io/api/core/v1" @@ -33,7 +34,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apiserver/pkg/util/feature" "k8s.io/client-go/dynamic" @@ -203,7 +203,7 @@ func TestEtcdStoragePath(t *testing.T) { } if !apiequality.Semantic.DeepDerivative(input, output) { - t.Errorf("Test stub for %s does not match: %s", kind, diff.ObjectGoPrintDiff(input, output)) + t.Errorf("Test stub for %s does not match: %s", kind, cmp.Diff(input, output)) } addGVKToEtcdBucket(cohabitatingResources, actualGVK, getEtcdBucket(testData.ExpectedEtcdPath)) diff --git a/test/utils/image/manifest_test.go b/test/utils/image/manifest_test.go index 700bb97881c..7ac5f96c967 100644 --- a/test/utils/image/manifest_test.go +++ b/test/utils/image/manifest_test.go @@ -21,7 +21,7 @@ import ( "reflect" "testing" - "k8s.io/apimachinery/pkg/util/diff" + "github.com/google/go-cmp/cmp" ) func BenchmarkReplaceRegistryInImageURL(b *testing.B) { @@ -177,6 +177,6 @@ func TestGetMappedImageConfigs(t *testing.T) { "docker.io/source/repo:1.0": "quay.io/repo/for-test:e2e-10-docker-io-source-repo-1-0-72R4aXm7YnxQ4_ek", } if !reflect.DeepEqual(expected, actual) { - t.Fatal(diff.ObjectReflectDiff(expected, actual)) + t.Fatal(cmp.Diff(expected, actual)) } }