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
c317f929
Unverified
Commit
c317f929
authored
Jan 25, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
patch: allow --local to use structs for strategic merge, warn about unknown objects
parent
424dac92
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
8 deletions
+10
-8
patch.go
pkg/kubectl/cmd/patch.go
+10
-8
No files found.
pkg/kubectl/cmd/patch.go
View file @
c317f929
...
@@ -27,6 +27,7 @@ import (
...
@@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
...
@@ -212,19 +213,15 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
...
@@ -212,19 +213,15 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
count
++
count
++
patchedObj
,
err
:=
api
.
Scheme
.
DeepCopy
(
info
.
VersionedObject
)
originalObjJS
,
err
:=
runtime
.
Encode
(
unstructured
.
UnstructuredJSONScheme
,
info
.
VersionedObject
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
original
ObjJS
,
err
:=
runtime
.
Encode
(
api
.
Codecs
.
LegacyCodec
(
mapping
.
GroupVersionKind
.
GroupVersion
()),
info
.
VersionedObject
.
(
runtime
.
Object
)
)
original
PatchedObjJS
,
err
:=
getPatchedJSON
(
patchType
,
originalObjJS
,
patchBytes
,
mapping
.
GroupVersionKind
,
api
.
Scheme
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
originalPatchedObjJS
,
err
:=
getPatchedJSON
(
patchType
,
originalObjJS
,
patchBytes
,
patchedObj
.
(
runtime
.
Object
))
targetObj
,
err
:=
runtime
.
Decode
(
unstructured
.
UnstructuredJSONScheme
,
originalPatchedObjJS
)
if
err
!=
nil
{
return
err
}
targetObj
,
err
:=
runtime
.
Decode
(
api
.
Codecs
.
UniversalDecoder
(),
originalPatchedObjJS
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -252,7 +249,7 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
...
@@ -252,7 +249,7 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
return
nil
return
nil
}
}
func
getPatchedJSON
(
patchType
types
.
PatchType
,
originalJS
,
patchJS
[]
byte
,
obj
runtime
.
Object
)
([]
byte
,
error
)
{
func
getPatchedJSON
(
patchType
types
.
PatchType
,
originalJS
,
patchJS
[]
byte
,
gvk
schema
.
GroupVersionKind
,
creater
runtime
.
ObjectCreater
)
([]
byte
,
error
)
{
switch
patchType
{
switch
patchType
{
case
types
.
JSONPatchType
:
case
types
.
JSONPatchType
:
patchObj
,
err
:=
jsonpatch
.
DecodePatch
(
patchJS
)
patchObj
,
err
:=
jsonpatch
.
DecodePatch
(
patchJS
)
...
@@ -265,6 +262,11 @@ func getPatchedJSON(patchType types.PatchType, originalJS, patchJS []byte, obj r
...
@@ -265,6 +262,11 @@ func getPatchedJSON(patchType types.PatchType, originalJS, patchJS []byte, obj r
return
jsonpatch
.
MergePatch
(
originalJS
,
patchJS
)
return
jsonpatch
.
MergePatch
(
originalJS
,
patchJS
)
case
types
.
StrategicMergePatchType
:
case
types
.
StrategicMergePatchType
:
// get a typed object for this GVK if we need to apply a strategic merge patch
obj
,
err
:=
creater
.
New
(
gvk
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot apply strategic merge patch for %s locally, try --type merge"
,
gvk
.
String
())
}
return
strategicpatch
.
StrategicMergePatch
(
originalJS
,
patchJS
,
obj
)
return
strategicpatch
.
StrategicMergePatch
(
originalJS
,
patchJS
,
obj
)
default
:
default
:
...
...
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