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
d425fe29
Commit
d425fe29
authored
Feb 21, 2019
by
Steve Kriss
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client-fake object tracker: support merge patch
Signed-off-by:
Steve Kriss
<
krisss@vmware.com
>
parent
f7c4389b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
simple_test.go
staging/src/k8s.io/client-go/dynamic/fake/simple_test.go
+5
-5
fixture.go
staging/src/k8s.io/client-go/testing/fixture.go
+11
-2
No files found.
staging/src/k8s.io/client-go/dynamic/fake/simple_test.go
View file @
d425fe29
...
...
@@ -181,11 +181,11 @@ func TestPatch(t *testing.T) {
patchBytes
:
[]
byte
(
`[{"op": "add", "path": "/spec/newvalue", "value": "dummy"}]`
),
wantErrMsg
:
"invalid JSON document"
,
},
{
name
:
"merge patch fails as unsupported
"
,
object
:
newUnstructured
(
testAPIVersion
,
testKind
,
testNamespace
,
testName
),
patchType
:
types
.
MergePatchType
,
patchBytes
:
[]
byte
(
`{
}`
),
wantErrMsg
:
"PatchType is not supported"
,
name
:
"merge patch works with simple replacement
"
,
object
:
newUnstructuredWithSpec
(
map
[
string
]
interface
{}{
"foo"
:
"bar"
}
),
patchType
:
types
.
MergePatchType
,
patchBytes
:
[]
byte
(
`{ "spec": { "foo": "baz" }
}`
),
expectedPatchedObject
:
newUnstructuredWithSpec
(
map
[
string
]
interface
{}{
"foo"
:
"baz"
})
,
},
// TODO: Add tests for strategic merge using v1.Pod for example to ensure the test cases
// demonstrate expected use cases.
...
...
staging/src/k8s.io/client-go/testing/fixture.go
View file @
d425fe29
...
...
@@ -20,7 +20,7 @@ import (
"fmt"
"sync"
"github.com/evanphx/json-patch"
jsonpatch
"github.com/evanphx/json-patch"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
...
...
@@ -138,7 +138,7 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
if
err
!=
nil
{
return
true
,
nil
,
err
}
// Only supports strategic merge patch and JSONPatch as coded.
switch
action
.
GetPatchType
()
{
case
types
.
JSONPatchType
:
patch
,
err
:=
jsonpatch
.
DecodePatch
(
action
.
GetPatch
())
...
...
@@ -152,6 +152,15 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
if
err
=
json
.
Unmarshal
(
modified
,
obj
);
err
!=
nil
{
return
true
,
nil
,
err
}
case
types
.
MergePatchType
:
modified
,
err
:=
jsonpatch
.
MergePatch
(
old
,
action
.
GetPatch
())
if
err
!=
nil
{
return
true
,
nil
,
err
}
if
err
:=
json
.
Unmarshal
(
modified
,
obj
);
err
!=
nil
{
return
true
,
nil
,
err
}
case
types
.
StrategicMergePatchType
:
mergedByte
,
err
:=
strategicpatch
.
StrategicMergePatch
(
old
,
action
.
GetPatch
(),
obj
)
if
err
!=
nil
{
...
...
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