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
8b3b4e4d
Commit
8b3b4e4d
authored
Apr 11, 2018
by
Minhan Xia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Patch support in fake kubeClient
parent
35777c31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
BUILD
staging/src/k8s.io/client-go/testing/BUILD
+2
-0
fixture.go
staging/src/k8s.io/client-go/testing/fixture.go
+30
-1
No files found.
staging/src/k8s.io/client-go/testing/BUILD
View file @
8b3b4e4d
...
...
@@ -22,6 +22,8 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/json:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
],
...
...
staging/src/k8s.io/client-go/testing/fixture.go
View file @
8b3b4e4d
...
...
@@ -25,6 +25,8 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/watch"
restclient
"k8s.io/client-go/rest"
)
...
...
@@ -72,7 +74,6 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
return
func
(
action
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
ns
:=
action
.
GetNamespace
()
gvr
:=
action
.
GetResource
()
// Here and below we need to switch on implementation types,
// not on interfaces, as some interfaces are identical
// (e.g. UpdateAction and CreateAction), so if we use them,
...
...
@@ -125,6 +126,34 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
}
return
true
,
nil
,
nil
case
PatchActionImpl
:
obj
,
err
:=
tracker
.
Get
(
gvr
,
ns
,
action
.
GetName
())
if
err
!=
nil
{
// object is not registered
return
false
,
nil
,
err
}
old
,
err
:=
json
.
Marshal
(
obj
)
if
err
!=
nil
{
return
true
,
nil
,
err
}
// Only supports strategic merge patch
// TODO: Add support for other Patch types
mergedByte
,
err
:=
strategicpatch
.
StrategicMergePatch
(
old
,
action
.
GetPatch
(),
obj
)
if
err
!=
nil
{
return
true
,
nil
,
err
}
if
err
=
json
.
Unmarshal
(
mergedByte
,
obj
);
err
!=
nil
{
return
true
,
nil
,
err
}
if
err
=
tracker
.
Update
(
gvr
,
obj
,
ns
);
err
!=
nil
{
return
true
,
nil
,
err
}
return
true
,
obj
,
nil
default
:
return
false
,
nil
,
fmt
.
Errorf
(
"no reaction implemented for %s"
,
action
)
}
...
...
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