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
3199da29
Unverified
Commit
3199da29
authored
Mar 06, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Mar 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #74369 from skriss/object-tracker-merge-patch
fake client object tracker: support merge patch
parents
88a685fe
d425fe29
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 @
3199da29
...
@@ -181,11 +181,11 @@ func TestPatch(t *testing.T) {
...
@@ -181,11 +181,11 @@ func TestPatch(t *testing.T) {
patchBytes
:
[]
byte
(
`[{"op": "add", "path": "/spec/newvalue", "value": "dummy"}]`
),
patchBytes
:
[]
byte
(
`[{"op": "add", "path": "/spec/newvalue", "value": "dummy"}]`
),
wantErrMsg
:
"invalid JSON document"
,
wantErrMsg
:
"invalid JSON document"
,
},
{
},
{
name
:
"merge patch fails as unsupported
"
,
name
:
"merge patch works with simple replacement
"
,
object
:
newUnstructured
(
testAPIVersion
,
testKind
,
testNamespace
,
testName
),
object
:
newUnstructuredWithSpec
(
map
[
string
]
interface
{}{
"foo"
:
"bar"
}
),
patchType
:
types
.
MergePatchType
,
patchType
:
types
.
MergePatchType
,
patchBytes
:
[]
byte
(
`{
}`
),
patchBytes
:
[]
byte
(
`{ "spec": { "foo": "baz" }
}`
),
wantErrMsg
:
"PatchType is not supported"
,
expectedPatchedObject
:
newUnstructuredWithSpec
(
map
[
string
]
interface
{}{
"foo"
:
"baz"
})
,
},
},
// TODO: Add tests for strategic merge using v1.Pod for example to ensure the test cases
// TODO: Add tests for strategic merge using v1.Pod for example to ensure the test cases
// demonstrate expected use cases.
// demonstrate expected use cases.
...
...
staging/src/k8s.io/client-go/testing/fixture.go
View file @
3199da29
...
@@ -20,7 +20,7 @@ import (
...
@@ -20,7 +20,7 @@ import (
"fmt"
"fmt"
"sync"
"sync"
"github.com/evanphx/json-patch"
jsonpatch
"github.com/evanphx/json-patch"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
...
@@ -138,7 +138,7 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
...
@@ -138,7 +138,7 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
if
err
!=
nil
{
if
err
!=
nil
{
return
true
,
nil
,
err
return
true
,
nil
,
err
}
}
// Only supports strategic merge patch and JSONPatch as coded.
switch
action
.
GetPatchType
()
{
switch
action
.
GetPatchType
()
{
case
types
.
JSONPatchType
:
case
types
.
JSONPatchType
:
patch
,
err
:=
jsonpatch
.
DecodePatch
(
action
.
GetPatch
())
patch
,
err
:=
jsonpatch
.
DecodePatch
(
action
.
GetPatch
())
...
@@ -152,6 +152,15 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
...
@@ -152,6 +152,15 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
if
err
=
json
.
Unmarshal
(
modified
,
obj
);
err
!=
nil
{
if
err
=
json
.
Unmarshal
(
modified
,
obj
);
err
!=
nil
{
return
true
,
nil
,
err
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
:
case
types
.
StrategicMergePatchType
:
mergedByte
,
err
:=
strategicpatch
.
StrategicMergePatch
(
old
,
action
.
GetPatch
(),
obj
)
mergedByte
,
err
:=
strategicpatch
.
StrategicMergePatch
(
old
,
action
.
GetPatch
(),
obj
)
if
err
!=
nil
{
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