From ea529dda84c085a2e629b24671a951a75c940698 Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Fri, 12 Jan 2024 18:47:52 -0500 Subject: [PATCH] :bug: Don't truncate large int64s in MergePatch This change bumps https://github.com/evanphx/json-patch in order to pick up a bugfix that made it truncate large int64s because it internally treated them as float64s. --- examples/scratch-env/go.mod | 2 +- examples/scratch-env/go.sum | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- pkg/client/patch_test.go | 27 +++++++++++++++++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/examples/scratch-env/go.mod b/examples/scratch-env/go.mod index 3a9db0cb2a..2b5b1fed17 100644 --- a/examples/scratch-env/go.mod +++ b/examples/scratch-env/go.mod @@ -15,7 +15,7 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect - github.com/evanphx/json-patch/v5 v5.7.0 // indirect + github.com/evanphx/json-patch/v5 v5.8.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/zapr v1.3.0 // indirect diff --git a/examples/scratch-env/go.sum b/examples/scratch-env/go.sum index 6db6c30146..4e28962e5f 100644 --- a/examples/scratch-env/go.sum +++ b/examples/scratch-env/go.sum @@ -10,8 +10,8 @@ github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxER github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/evanphx/json-patch/v5 v5.7.0 h1:nJqP7uwL84RJInrohHfW0Fx3awjbm8qZeFv0nW9SYGc= -github.com/evanphx/json-patch/v5 v5.7.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= +github.com/evanphx/json-patch/v5 v5.8.0 h1:lRj6N9Nci7MvzrXuX6HFzU8XjmhPiXPlsKEy1u0KQro= +github.com/evanphx/json-patch/v5 v5.8.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= diff --git a/go.mod b/go.mod index ac8cffed9e..2eb33bb7e1 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.21.0 require ( github.com/evanphx/json-patch v4.12.0+incompatible // Using v4 to match upstream - github.com/evanphx/json-patch/v5 v5.7.0 + github.com/evanphx/json-patch/v5 v5.8.0 github.com/fsnotify/fsnotify v1.7.0 github.com/go-logr/logr v1.4.1 github.com/go-logr/zapr v1.3.0 diff --git a/go.sum b/go.sum index 9769f50786..245fb1cdb1 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,8 @@ github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxER github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/evanphx/json-patch/v5 v5.7.0 h1:nJqP7uwL84RJInrohHfW0Fx3awjbm8qZeFv0nW9SYGc= -github.com/evanphx/json-patch/v5 v5.7.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= +github.com/evanphx/json-patch/v5 v5.8.0 h1:lRj6N9Nci7MvzrXuX6HFzU8XjmhPiXPlsKEy1u0KQro= +github.com/evanphx/json-patch/v5 v5.8.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= diff --git a/pkg/client/patch_test.go b/pkg/client/patch_test.go index 2910ef56bf..c9e105ae51 100644 --- a/pkg/client/patch_test.go +++ b/pkg/client/patch_test.go @@ -19,9 +19,13 @@ package client import ( "testing" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" + batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func BenchmarkMergeFrom(b *testing.B) { @@ -93,3 +97,26 @@ func BenchmarkMergeFrom(b *testing.B) { } }) } + +var _ = Describe("MergeFrom", func() { + It("should successfully create a patch for two large and similar in64s", func() { + var largeInt64 int64 = 9223372036854775807 + var similarLargeInt64 int64 = 9223372036854775800 + j := batchv1.Job{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "test", + Name: "test", + }, + Spec: batchv1.JobSpec{ + ActiveDeadlineSeconds: &largeInt64, + }, + } + patch := MergeFrom(j.DeepCopy()) + + j.Spec.ActiveDeadlineSeconds = &similarLargeInt64 + + data, err := patch.Data(&j) + Expect(err).NotTo(HaveOccurred()) + Expect(data).To(Equal([]byte(`{"spec":{"activeDeadlineSeconds":9223372036854775800}}`))) + }) +})