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
b6d4f371
Unverified
Commit
b6d4f371
authored
Jan 22, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
patch: use unstructured objects
parent
89266588
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
patch.go
pkg/kubectl/cmd/patch.go
+8
-4
patch_test.go
pkg/kubectl/cmd/patch_test.go
+6
-6
No files found.
pkg/kubectl/cmd/patch.go
View file @
b6d4f371
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
cmd
package
cmd
import
(
import
(
"encoding/json"
"fmt"
"fmt"
"io"
"io"
"reflect"
"reflect"
...
@@ -26,8 +25,10 @@ import (
...
@@ -26,8 +25,10 @@ import (
jsonpatch
"github.com/evanphx/json-patch"
jsonpatch
"github.com/evanphx/json-patch"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/apimachinery/pkg/util/yaml"
...
@@ -144,8 +145,11 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
...
@@ -144,8 +145,11 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
return
fmt
.
Errorf
(
"unable to parse %q: %v"
,
patch
,
err
)
return
fmt
.
Errorf
(
"unable to parse %q: %v"
,
patch
,
err
)
}
}
mapper
,
typer
:=
f
.
Object
()
mapper
,
typer
,
err
:=
f
.
UnstructuredObject
()
r
:=
resource
.
NewBuilder
(
mapper
,
typer
,
resource
.
ClientMapperFunc
(
f
.
ClientForMapping
),
f
.
Decoder
(
true
))
.
if
err
!=
nil
{
return
err
}
r
:=
resource
.
NewBuilder
(
mapper
,
typer
,
resource
.
ClientMapperFunc
(
f
.
UnstructuredClientForMapping
),
unstructured
.
UnstructuredJSONScheme
)
.
ContinueOnError
()
.
ContinueOnError
()
.
NamespaceParam
(
cmdNamespace
)
.
DefaultNamespace
()
.
NamespaceParam
(
cmdNamespace
)
.
DefaultNamespace
()
.
FilenameParam
(
enforceNamespace
,
&
options
.
FilenameOptions
)
.
FilenameParam
(
enforceNamespace
,
&
options
.
FilenameOptions
)
.
...
@@ -164,7 +168,7 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
...
@@ -164,7 +168,7 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
}
}
name
,
namespace
:=
info
.
Name
,
info
.
Namespace
name
,
namespace
:=
info
.
Name
,
info
.
Namespace
mapping
:=
info
.
ResourceMapping
()
mapping
:=
info
.
ResourceMapping
()
client
,
err
:=
f
.
ClientForMapping
(
mapping
)
client
,
err
:=
f
.
Unstructured
ClientForMapping
(
mapping
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/kubectl/cmd/patch_test.go
View file @
b6d4f371
...
@@ -29,11 +29,11 @@ import (
...
@@ -29,11 +29,11 @@ import (
func
TestPatchObject
(
t
*
testing
.
T
)
{
func
TestPatchObject
(
t
*
testing
.
T
)
{
_
,
svc
,
_
:=
testData
()
_
,
svc
,
_
:=
testData
()
f
,
tf
,
codec
,
ns
:=
cmdtesting
.
NewAPIFactory
()
f
,
tf
,
codec
,
_
:=
cmdtesting
.
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
tf
.
Printer
=
&
testPrinter
{}
tf
.
Client
=
&
fake
.
RESTClient
{
tf
.
Unstructured
Client
=
&
fake
.
RESTClient
{
APIRegistry
:
api
.
Registry
,
APIRegistry
:
api
.
Registry
,
NegotiatedSerializer
:
ns
,
NegotiatedSerializer
:
unstructuredSerializer
,
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/services/frontend"
&&
(
m
==
"PATCH"
||
m
==
"GET"
)
:
case
p
==
"/namespaces/test/services/frontend"
&&
(
m
==
"PATCH"
||
m
==
"GET"
)
:
...
@@ -62,11 +62,11 @@ func TestPatchObject(t *testing.T) {
...
@@ -62,11 +62,11 @@ func TestPatchObject(t *testing.T) {
func
TestPatchObjectFromFile
(
t
*
testing
.
T
)
{
func
TestPatchObjectFromFile
(
t
*
testing
.
T
)
{
_
,
svc
,
_
:=
testData
()
_
,
svc
,
_
:=
testData
()
f
,
tf
,
codec
,
ns
:=
cmdtesting
.
NewAPIFactory
()
f
,
tf
,
codec
,
_
:=
cmdtesting
.
NewAPIFactory
()
tf
.
Printer
=
&
testPrinter
{}
tf
.
Printer
=
&
testPrinter
{}
tf
.
Client
=
&
fake
.
RESTClient
{
tf
.
Unstructured
Client
=
&
fake
.
RESTClient
{
APIRegistry
:
api
.
Registry
,
APIRegistry
:
api
.
Registry
,
NegotiatedSerializer
:
ns
,
NegotiatedSerializer
:
unstructuredSerializer
,
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/services/frontend"
&&
(
m
==
"PATCH"
||
m
==
"GET"
)
:
case
p
==
"/namespaces/test/services/frontend"
&&
(
m
==
"PATCH"
||
m
==
"GET"
)
:
...
...
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