Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
upgrade to latest dependencies (#397)
Browse files Browse the repository at this point in the history
bumping gomodules.xyz/jsonpatch/v2 93a4daf...13a9e4a:
  > 13a9e4a Merge pull request # 36 from howardjohn/v2/improvements
  > 62e0c90 Update repository config (# 33)
  > 6d5c3df Fully remove dead code
  > 0c26413 Update repository config (# 32)
  > 45186ed (hackily) remove inefficient optimization
  > e0f6c24 Fix known broken case
  > c616a48 Fix marshaling invalid chars
  > 2c05a51 Fix inputs with empty keys
  > 1f7eb13 Improve fuzz tests
  > 471fa30 Fix CI
  > 4844bbf Add fuzzing test
  > 87f8876 add benchmarks
  > a81e531 Go.mod for go 1.20
  > fc9e957 Update to Go 1.20
bumping knative.dev/networking e50e66f...ed0534b:
  > ed0534b Update community files (# 843)
bumping knative.dev/hack 3403e35...044c02b:
  > 044c02b Update community files (# 309)
bumping knative.dev/serving 5c1c855...59cb3d3:
  > 59cb3d3 Update net-contour nightly (# 14264)
  > 4931532 Update net-certmanager nightly (# 14262)
  > 5e20e1e Update net-istio nightly (# 14263)
  > 6bfe5c3 add app: webhook label to webhook service (# 14258)
  > ece2fea upgrade to latest dependencies (# 14256)
bumping knative.dev/pkg 26b41ba...4f651e0:
  > 4f651e0 Bump gomodules.xyz/jsonpatch/v2 from 2.2.0 to 2.3.0 (# 2789)
  > 6519aff Update community files (# 2794)

Signed-off-by: Knative Automation <[email protected]>
  • Loading branch information
knative-automation authored Aug 15, 2023
1 parent 1f8bce6 commit eebe7f2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 148 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ require (
k8s.io/api v0.26.5
k8s.io/apimachinery v0.26.5
k8s.io/client-go v0.26.5
knative.dev/hack v0.0.0-20230814132844-3403e3502fdc
knative.dev/networking v0.0.0-20230814135744-e50e66f1f80a
knative.dev/pkg v0.0.0-20230814093643-26b41ba523a0
knative.dev/serving v0.38.1-0.20230814133344-5c1c855bd92a
knative.dev/hack v0.0.0-20230815012940-044c02b7a447
knative.dev/networking v0.0.0-20230815014240-ed0534b4ef83
knative.dev/pkg v0.0.0-20230815132840-4f651e092853
knative.dev/serving v0.38.1-0.20230815134146-59cb3d3d34c4
)

require (
Expand Down Expand Up @@ -68,7 +68,7 @@ require (
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
21 changes: 10 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
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.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww=
Expand Down Expand Up @@ -518,8 +517,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.2.0 h1:4pT439QV83L+G9FkcCriY6EkpcK6r6bK+A5FBUMI7qY=
gomodules.xyz/jsonpatch/v2 v2.2.0/go.mod h1:WXp+iVDkoLQqPudfQ9GBlwB2eZ5DKOnjQZCYdOS8GPY=
gomodules.xyz/jsonpatch/v2 v2.3.0 h1:8NFhfS6gzxNqjLIYnZxg319wZ5Qjnx4m/CcX+Klzazc=
gomodules.xyz/jsonpatch/v2 v2.3.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca h1:PupagGYwj8+I4ubCxcmcBRk3VlUWtTg5huQpZR9flmE=
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
Expand Down Expand Up @@ -667,14 +666,14 @@ k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 h1:+70TFaan3hfJzs+7VK2o+O
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4=
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2 h1:GfD9OzL11kvZN5iArC6oTS7RTj7oJOIfnislxYlqTj8=
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
knative.dev/hack v0.0.0-20230814132844-3403e3502fdc h1:sIJ2MfOFVb3+EIK+n5B7l5GeZxTrHegLzdBTYjreCCU=
knative.dev/hack v0.0.0-20230814132844-3403e3502fdc/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/networking v0.0.0-20230814135744-e50e66f1f80a h1:lRv442E66N2qRwe0KjBFBcrAeWfPlr4mcj39T+bW3dI=
knative.dev/networking v0.0.0-20230814135744-e50e66f1f80a/go.mod h1:Ao0oO/s5ARZP2jllEoGWbLgpCb2nI4OCUutylpSyxpw=
knative.dev/pkg v0.0.0-20230814093643-26b41ba523a0 h1:fqLbNL2/g016cnF3IQRjFr2aLmhcAnHiA1CANoBesOA=
knative.dev/pkg v0.0.0-20230814093643-26b41ba523a0/go.mod h1:D9D8LkOtlJBC09i+6nbTdZ5LAKsAbTJkkGGXEh2BPYI=
knative.dev/serving v0.38.1-0.20230814133344-5c1c855bd92a h1:j9CEt4J0Fyswa/VNKr1Co1i+Evyg2sN7/mXeWdblvNo=
knative.dev/serving v0.38.1-0.20230814133344-5c1c855bd92a/go.mod h1:Nxn2Eus8JXH+OW1f6hXvFNIVn6PV0DACMSR08DZmU1c=
knative.dev/hack v0.0.0-20230815012940-044c02b7a447 h1:Lr4O/WEyZHuUBFbqATYdQlfLXvhPUCluF4zlgRi59T4=
knative.dev/hack v0.0.0-20230815012940-044c02b7a447/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/networking v0.0.0-20230815014240-ed0534b4ef83 h1:F1tP5OIXfk2YX/0KE+8DyuFw8bNrWzQSWXRba6k/aVQ=
knative.dev/networking v0.0.0-20230815014240-ed0534b4ef83/go.mod h1:Ao0oO/s5ARZP2jllEoGWbLgpCb2nI4OCUutylpSyxpw=
knative.dev/pkg v0.0.0-20230815132840-4f651e092853 h1:OyAYpXLa/jQWClFxRegCccGySyX2/1BVRtKaAWRE/xM=
knative.dev/pkg v0.0.0-20230815132840-4f651e092853/go.mod h1:Y5Tis5nMoapB9iTZywW20Qnv/7LBahrtHz9Sm6+l3LE=
knative.dev/serving v0.38.1-0.20230815134146-59cb3d3d34c4 h1:C3KHzufYNgVxVfdMO1mBrcFrnbapsFYNt+FiT+q61b0=
knative.dev/serving v0.38.1-0.20230815134146-59cb3d3d34c4/go.mod h1:XNvj91QrfYWMMLSVo42q6P4X6XtNeOUKIEM5dwMjgGA=
pgregory.net/rapid v1.0.0 h1:iQaM2w5PZ6xvt6x7hbd7tiDS+nk7YPp5uCaEba+T/F4=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
Expand Down
160 changes: 34 additions & 126 deletions vendor/gomodules.xyz/jsonpatch/v2/jsonpatch.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jsonpatch

import (
"bytes"
"encoding/json"
"fmt"
"reflect"
Expand All @@ -24,21 +23,28 @@ func (j *Operation) Json() string {
}

func (j *Operation) MarshalJSON() ([]byte, error) {
var b bytes.Buffer
b.WriteString("{")
b.WriteString(fmt.Sprintf(`"op":"%s"`, j.Operation))
b.WriteString(fmt.Sprintf(`,"path":"%s"`, j.Path))
// Consider omitting Value for non-nullable operations.
if j.Value != nil || j.Operation == "replace" || j.Operation == "add" {
v, err := json.Marshal(j.Value)
if err != nil {
return nil, err
}
b.WriteString(`,"value":`)
b.Write(v)
}
b.WriteString("}")
return b.Bytes(), nil
// Ensure for add and replace we emit `value: null`
if j.Value == nil && (j.Operation == "replace" || j.Operation == "add") {
return json.Marshal(struct {
Operation string `json:"op"`
Path string `json:"path"`
Value interface{} `json:"value"`
}{
Operation: j.Operation,
Path: j.Path,
})
}
// otherwise just marshal normally. We cannot literally do json.Marshal(j) as it would be recursively
// calling this function.
return json.Marshal(struct {
Operation string `json:"op"`
Path string `json:"path"`
Value interface{} `json:"value,omitempty"`
}{
Operation: j.Operation,
Path: j.Path,
Value: j.Value,
})
}

type ByPath []Operation
Expand Down Expand Up @@ -149,9 +155,6 @@ func makePath(path string, newPart interface{}) string {
if path == "" {
return "/" + key
}
if strings.HasSuffix(path, "/") {
return path + key
}
return path + "/" + key
}

Expand Down Expand Up @@ -211,22 +214,18 @@ func handleValues(av, bv interface{}, p string, patch []Operation) ([]Operation,
}
case []interface{}:
bt := bv.([]interface{})
if isSimpleArray(at) && isSimpleArray(bt) {
patch = append(patch, compareEditDistance(at, bt, p)...)
} else {
n := min(len(at), len(bt))
for i := len(at) - 1; i >= n; i-- {
patch = append(patch, NewOperation("remove", makePath(p, i), nil))
}
for i := n; i < len(bt); i++ {
patch = append(patch, NewOperation("add", makePath(p, i), bt[i]))
}
for i := 0; i < n; i++ {
var err error
patch, err = handleValues(at[i], bt[i], makePath(p, i), patch)
if err != nil {
return nil, err
}
n := min(len(at), len(bt))
for i := len(at) - 1; i >= n; i-- {
patch = append(patch, NewOperation("remove", makePath(p, i), nil))
}
for i := n; i < len(bt); i++ {
patch = append(patch, NewOperation("add", makePath(p, i), bt[i]))
}
for i := 0; i < n; i++ {
var err error
patch, err = handleValues(at[i], bt[i], makePath(p, i), patch)
if err != nil {
return nil, err
}
}
default:
Expand All @@ -235,100 +234,9 @@ func handleValues(av, bv interface{}, p string, patch []Operation) ([]Operation,
return patch, nil
}

func isBasicType(a interface{}) bool {
switch a.(type) {
case string, float64, bool:
default:
return false
}
return true
}

func isSimpleArray(a []interface{}) bool {
for i := range a {
switch a[i].(type) {
case string, float64, bool:
default:
val := reflect.ValueOf(a[i])
if val.Kind() == reflect.Map {
for _, k := range val.MapKeys() {
av := val.MapIndex(k)
if av.Kind() == reflect.Ptr || av.Kind() == reflect.Interface {
if av.IsNil() {
continue
}
av = av.Elem()
}
if av.Kind() != reflect.String && av.Kind() != reflect.Float64 && av.Kind() != reflect.Bool {
return false
}
}
return true
}
return false
}
}
return true
}

// https://en.wikipedia.org/wiki/Wagner%E2%80%93Fischer_algorithm
// Adapted from https://github.com/texttheater/golang-levenshtein
func compareEditDistance(s, t []interface{}, p string) []Operation {
m := len(s)
n := len(t)

d := make([][]int, m+1)
for i := 0; i <= m; i++ {
d[i] = make([]int, n+1)
d[i][0] = i
}
for j := 0; j <= n; j++ {
d[0][j] = j
}

for j := 1; j <= n; j++ {
for i := 1; i <= m; i++ {
if reflect.DeepEqual(s[i-1], t[j-1]) {
d[i][j] = d[i-1][j-1] // no op required
} else {
del := d[i-1][j] + 1
add := d[i][j-1] + 1
rep := d[i-1][j-1] + 1
d[i][j] = min(rep, min(add, del))
}
}
}

return backtrace(s, t, p, m, n, d)
}

func min(x int, y int) int {
if y < x {
return y
}
return x
}

func backtrace(s, t []interface{}, p string, i int, j int, matrix [][]int) []Operation {
if i > 0 && matrix[i-1][j]+1 == matrix[i][j] {
op := NewOperation("remove", makePath(p, i-1), nil)
return append([]Operation{op}, backtrace(s, t, p, i-1, j, matrix)...)
}
if j > 0 && matrix[i][j-1]+1 == matrix[i][j] {
op := NewOperation("add", makePath(p, i), t[j-1])
return append([]Operation{op}, backtrace(s, t, p, i, j-1, matrix)...)
}
if i > 0 && j > 0 && matrix[i-1][j-1]+1 == matrix[i][j] {
if isBasicType(s[0]) {
op := NewOperation("replace", makePath(p, i-1), t[j-1])
return append([]Operation{op}, backtrace(s, t, p, i-1, j-1, matrix)...)
}

p2, _ := handleValues(s[i-1], t[j-1], makePath(p, i-1), []Operation{})
return append(p2, backtrace(s, t, p, i-1, j-1, matrix)...)
}
if i > 0 && j > 0 && matrix[i-1][j-1] == matrix[i][j] {
return backtrace(s, t, p, i-1, j-1, matrix)
}
return []Operation{}
}
12 changes: 6 additions & 6 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ golang.org/x/text/unicode/norm
# golang.org/x/time v0.3.0
## explicit
golang.org/x/time/rate
# gomodules.xyz/jsonpatch/v2 v2.2.0
## explicit; go 1.12
# gomodules.xyz/jsonpatch/v2 v2.3.0
## explicit; go 1.20
gomodules.xyz/jsonpatch/v2
# google.golang.org/appengine v1.6.7
## explicit; go 1.11
Expand Down Expand Up @@ -596,18 +596,18 @@ k8s.io/utils/lru
k8s.io/utils/net
k8s.io/utils/strings/slices
k8s.io/utils/trace
# knative.dev/hack v0.0.0-20230814132844-3403e3502fdc
# knative.dev/hack v0.0.0-20230815012940-044c02b7a447
## explicit; go 1.18
knative.dev/hack
# knative.dev/networking v0.0.0-20230814135744-e50e66f1f80a
# knative.dev/networking v0.0.0-20230815014240-ed0534b4ef83
## explicit; go 1.18
knative.dev/networking/pkg/apis/networking
knative.dev/networking/pkg/apis/networking/v1alpha1
knative.dev/networking/pkg/client/clientset/versioned/scheme
knative.dev/networking/pkg/client/clientset/versioned/typed/networking/v1alpha1
knative.dev/networking/pkg/client/clientset/versioned/typed/networking/v1alpha1/fake
knative.dev/networking/pkg/config
# knative.dev/pkg v0.0.0-20230814093643-26b41ba523a0
# knative.dev/pkg v0.0.0-20230815132840-4f651e092853
## explicit; go 1.18
knative.dev/pkg/apis
knative.dev/pkg/apis/duck
Expand All @@ -624,7 +624,7 @@ knative.dev/pkg/network
knative.dev/pkg/profiling
knative.dev/pkg/ptr
knative.dev/pkg/tracker
# knative.dev/serving v0.38.1-0.20230814133344-5c1c855bd92a
# knative.dev/serving v0.38.1-0.20230815134146-59cb3d3d34c4
## explicit; go 1.18
knative.dev/serving/pkg/apis/autoscaling
knative.dev/serving/pkg/apis/autoscaling/v1alpha1
Expand Down

0 comments on commit eebe7f2

Please sign in to comment.