Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8447cee0
Commit
8447cee0
authored
Jul 20, 2017
by
Di Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update json-patch to fix nil value issue when creating mergepatch
parent
3f887171
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
75 additions
and
37 deletions
+75
-37
Godeps.json
Godeps/Godeps.json
+1
-1
Godeps.json
...ing/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json
+1
-1
Godeps.json
staging/src/k8s.io/apimachinery/Godeps/Godeps.json
+1
-1
Godeps.json
staging/src/k8s.io/apiserver/Godeps/Godeps.json
+1
-1
Godeps.json
staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json
+1
-1
Godeps.json
staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json
+1
-1
.travis.yml
vendor/github.com/evanphx/json-patch/.travis.yml
+4
-2
merge.go
vendor/github.com/evanphx/json-patch/merge.go
+9
-29
patch.go
vendor/github.com/evanphx/json-patch/patch.go
+56
-0
No files found.
Godeps/Godeps.json
View file @
8447cee0
...
...
@@ -1090,7 +1090,7 @@
},
{
"ImportPath"
:
"github.com/evanphx/json-patch"
,
"Rev"
:
"
ba18e35c5c1b36ef6334cad706eb681153d2d379
"
"Rev"
:
"
944e07253867aacae43c04b2e6a239005443f33a
"
},
{
"ImportPath"
:
"github.com/exponent-io/jsonpath"
,
...
...
staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json
View file @
8447cee0
...
...
@@ -104,7 +104,7 @@
},
{
"ImportPath"
:
"github.com/evanphx/json-patch"
,
"Rev"
:
"
ba18e35c5c1b36ef6334cad706eb681153d2d379
"
"Rev"
:
"
944e07253867aacae43c04b2e6a239005443f33a
"
},
{
"ImportPath"
:
"github.com/ghodss/yaml"
,
...
...
staging/src/k8s.io/apimachinery/Godeps/Godeps.json
View file @
8447cee0
...
...
@@ -40,7 +40,7 @@
},
{
"ImportPath"
:
"github.com/evanphx/json-patch"
,
"Rev"
:
"
ba18e35c5c1b36ef6334cad706eb681153d2d379
"
"Rev"
:
"
944e07253867aacae43c04b2e6a239005443f33a
"
},
{
"ImportPath"
:
"github.com/ghodss/yaml"
,
...
...
staging/src/k8s.io/apiserver/Godeps/Godeps.json
View file @
8447cee0
...
...
@@ -324,7 +324,7 @@
},
{
"ImportPath"
:
"github.com/evanphx/json-patch"
,
"Rev"
:
"
ba18e35c5c1b36ef6334cad706eb681153d2d379
"
"Rev"
:
"
944e07253867aacae43c04b2e6a239005443f33a
"
},
{
"ImportPath"
:
"github.com/ghodss/yaml"
,
...
...
staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json
View file @
8447cee0
...
...
@@ -112,7 +112,7 @@
},
{
"ImportPath"
:
"github.com/evanphx/json-patch"
,
"Rev"
:
"
ba18e35c5c1b36ef6334cad706eb681153d2d379
"
"Rev"
:
"
944e07253867aacae43c04b2e6a239005443f33a
"
},
{
"ImportPath"
:
"github.com/ghodss/yaml"
,
...
...
staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json
View file @
8447cee0
...
...
@@ -104,7 +104,7 @@
},
{
"ImportPath"
:
"github.com/evanphx/json-patch"
,
"Rev"
:
"
ba18e35c5c1b36ef6334cad706eb681153d2d379
"
"Rev"
:
"
944e07253867aacae43c04b2e6a239005443f33a
"
},
{
"ImportPath"
:
"github.com/ghodss/yaml"
,
...
...
vendor/github.com/evanphx/json-patch/.travis.yml
View file @
8447cee0
language
:
go
go
:
-
1.
4
-
1.
3
-
1.
8
-
1.
7
install
:
-
if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
-
go get github.com/jessevdk/go-flags
script
:
-
go get
-
go test -cover ./...
notifications
:
...
...
vendor/github.com/evanphx/json-patch/merge.go
View file @
8447cee0
...
...
@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"reflect"
"strings"
)
func
merge
(
cur
,
patch
*
lazyNode
,
mergeMerge
bool
)
*
lazyNode
{
...
...
@@ -28,7 +27,6 @@ func merge(cur, patch *lazyNode, mergeMerge bool) *lazyNode {
func
mergeDocs
(
doc
,
patch
*
partialDoc
,
mergeMerge
bool
)
{
for
k
,
v
:=
range
*
patch
{
k
:=
decodePatchKey
(
k
)
if
v
==
nil
{
if
mergeMerge
{
(
*
doc
)[
k
]
=
nil
...
...
@@ -226,6 +224,9 @@ func matchesValue(av, bv interface{}) bool {
if
bt
==
at
{
return
true
}
case
nil
:
// Both nil, fine.
return
true
case
map
[
string
]
interface
{}
:
bt
:=
bv
.
(
map
[
string
]
interface
{})
for
key
:=
range
at
{
...
...
@@ -250,16 +251,15 @@ func matchesValue(av, bv interface{}) bool {
func
getDiff
(
a
,
b
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
error
)
{
into
:=
map
[
string
]
interface
{}{}
for
key
,
bv
:=
range
b
{
escapedKey
:=
encodePatchKey
(
key
)
av
,
ok
:=
a
[
key
]
// value was added
if
!
ok
{
into
[
escapedK
ey
]
=
bv
into
[
k
ey
]
=
bv
continue
}
// If types have changed, replace completely
if
reflect
.
TypeOf
(
av
)
!=
reflect
.
TypeOf
(
bv
)
{
into
[
escapedK
ey
]
=
bv
into
[
k
ey
]
=
bv
continue
}
// Types are the same, compare values
...
...
@@ -272,23 +272,23 @@ func getDiff(a, b map[string]interface{}) (map[string]interface{}, error) {
return
nil
,
err
}
if
len
(
dst
)
>
0
{
into
[
escapedK
ey
]
=
dst
into
[
k
ey
]
=
dst
}
case
string
,
float64
,
bool
:
if
!
matchesValue
(
av
,
bv
)
{
into
[
escapedK
ey
]
=
bv
into
[
k
ey
]
=
bv
}
case
[]
interface
{}
:
bt
:=
bv
.
([]
interface
{})
if
!
matchesArray
(
at
,
bt
)
{
into
[
escapedK
ey
]
=
bv
into
[
k
ey
]
=
bv
}
case
nil
:
switch
bv
.
(
type
)
{
case
nil
:
// Both nil, fine.
default
:
into
[
escapedK
ey
]
=
bv
into
[
k
ey
]
=
bv
}
default
:
panic
(
fmt
.
Sprintf
(
"Unknown type:%T in key %s"
,
av
,
key
))
...
...
@@ -303,23 +303,3 @@ func getDiff(a, b map[string]interface{}) (map[string]interface{}, error) {
}
return
into
,
nil
}
// From http://tools.ietf.org/html/rfc6901#section-4 :
//
// Evaluation of each reference token begins by decoding any escaped
// character sequence. This is performed by first transforming any
// occurrence of the sequence '~1' to '/', and then transforming any
// occurrence of the sequence '~0' to '~'.
var
(
rfc6901Encoder
=
strings
.
NewReplacer
(
"~"
,
"~0"
,
"/"
,
"~1"
)
rfc6901Decoder
=
strings
.
NewReplacer
(
"~1"
,
"/"
,
"~0"
,
"~"
)
)
func
decodePatchKey
(
k
string
)
string
{
return
rfc6901Decoder
.
Replace
(
k
)
}
func
encodePatchKey
(
k
string
)
string
{
return
rfc6901Encoder
.
Replace
(
k
)
}
vendor/github.com/evanphx/json-patch/patch.go
View file @
8447cee0
...
...
@@ -369,6 +369,15 @@ func (d *partialArray) add(key string, val *lazyNode) error {
cur
:=
*
d
if
idx
<
0
{
idx
*=
-
1
if
idx
>
len
(
ary
)
{
return
fmt
.
Errorf
(
"Unable to access invalid index: %d"
,
idx
)
}
idx
=
len
(
ary
)
-
idx
}
copy
(
ary
[
0
:
idx
],
cur
[
0
:
idx
])
ary
[
idx
]
=
val
copy
(
ary
[
idx
+
1
:
],
cur
[
idx
:
])
...
...
@@ -446,6 +455,11 @@ func (p Patch) replace(doc *container, op operation) error {
return
fmt
.
Errorf
(
"jsonpatch replace operation does not apply: doc is missing path: %s"
,
path
)
}
val
,
ok
:=
con
.
get
(
key
)
if
val
==
nil
||
ok
!=
nil
{
return
fmt
.
Errorf
(
"jsonpatch replace operation does not apply: doc is missing key: %s"
,
path
)
}
return
con
.
set
(
key
,
op
.
value
())
}
...
...
@@ -508,6 +522,31 @@ func (p Patch) test(doc *container, op operation) error {
return
fmt
.
Errorf
(
"Testing value %s failed"
,
path
)
}
func
(
p
Patch
)
copy
(
doc
*
container
,
op
operation
)
error
{
from
:=
op
.
from
()
con
,
key
:=
findObject
(
doc
,
from
)
if
con
==
nil
{
return
fmt
.
Errorf
(
"jsonpatch copy operation does not apply: doc is missing from path: %s"
,
from
)
}
val
,
err
:=
con
.
get
(
key
)
if
err
!=
nil
{
return
err
}
path
:=
op
.
path
()
con
,
key
=
findObject
(
doc
,
path
)
if
con
==
nil
{
return
fmt
.
Errorf
(
"jsonpatch copy operation does not apply: doc is missing destination path: %s"
,
path
)
}
return
con
.
set
(
key
,
val
)
}
// Equal indicates if 2 JSON documents have the same structural equality.
func
Equal
(
a
,
b
[]
byte
)
bool
{
ra
:=
make
(
json
.
RawMessage
,
len
(
a
))
...
...
@@ -570,6 +609,8 @@ func (p Patch) ApplyIndent(doc []byte, indent string) ([]byte, error) {
err
=
p
.
move
(
&
pd
,
op
)
case
"test"
:
err
=
p
.
test
(
&
pd
,
op
)
case
"copy"
:
err
=
p
.
copy
(
&
pd
,
op
)
default
:
err
=
fmt
.
Errorf
(
"Unexpected kind: %s"
,
op
.
kind
())
}
...
...
@@ -585,3 +626,18 @@ func (p Patch) ApplyIndent(doc []byte, indent string) ([]byte, error) {
return
json
.
Marshal
(
pd
)
}
// From http://tools.ietf.org/html/rfc6901#section-4 :
//
// Evaluation of each reference token begins by decoding any escaped
// character sequence. This is performed by first transforming any
// occurrence of the sequence '~1' to '/', and then transforming any
// occurrence of the sequence '~0' to '~'.
var
(
rfc6901Decoder
=
strings
.
NewReplacer
(
"~1"
,
"/"
,
"~0"
,
"~"
)
)
func
decodePatchKey
(
k
string
)
string
{
return
rfc6901Decoder
.
Replace
(
k
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment