From 2ca4ffe6532f70f9836cf48d271cd27b2144baa8 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Wed, 5 Feb 2025 09:43:17 +0100 Subject: [PATCH 1/2] Add evanphx/json-patch/v5 to unwanted dependencies This comes up periodically; bumping to v5 introduces issues with replace operations in JSON patches. k/k relies on non-RFC-compliant operations which v5 no longer allows. Signed-off-by: Stephen Kitt --- hack/unwanted-dependencies.json | 1 + 1 file changed, 1 insertion(+) diff --git a/hack/unwanted-dependencies.json b/hack/unwanted-dependencies.json index 47a37ed5b86..f6ae0813e7e 100644 --- a/hack/unwanted-dependencies.json +++ b/hack/unwanted-dependencies.json @@ -14,6 +14,7 @@ "github.com/bketelsen/crypt": "unused, crypto", "github.com/containerd/cgroups": "standardize on single cgroups library from runc, refer #128157", "github.com/davecgh/go-spew": "refer to #103942", + "github.com/evanphx/json-patch/v5": "refer to https://github.com/kubernetes/kubernetes/pull/91622#issuecomment-637087847", "github.com/form3tech-oss/jwt-go": "unmaintained, archive mode", "github.com/getsentry/raven-go": "unmaintained, archive mode", "github.com/go-bindata/go-bindata": "refer to #99829", From d180fe28ad5154eae7930a518640a8860e5a96d8 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Tue, 24 Jun 2025 09:23:39 -0400 Subject: [PATCH 2/2] Add json-patch v4 compatibility test --- .../apiserver/pkg/endpoints/handlers/rest_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 995063e5cd9..49606577548 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 @@ -30,6 +30,7 @@ import ( "github.com/google/go-cmp/cmp" fuzz "github.com/google/gofuzz" jsonpatch "gopkg.in/evanphx/json-patch.v4" + apiequality "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -248,6 +249,15 @@ func TestJSONPatch(t *testing.T) { name: "valid-negative-index-patch", patch: `[{"op": "test", "value": "foo", "path": "/metadata/finalizers/-1"}]`, }, + // This demonstrates out-of-spec behavior json-patch v4 allows, + // which Kubernetes clients may depend on, and which updating to json-patch v5 currently breaks + { + name: "replace-missing-path-allowed", + patch: `[ + {"op":"replace", "path":"/metadata/path", "value":"foo"}, + {"op":"test", "path":"/metadata/path", "value":"foo"} + ]`, + }, } { p := &patcher{ patchType: types.JSONPatchType,