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
48d3ca23
Commit
48d3ca23
authored
Nov 18, 2016
by
ymqytw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update apply and edit
parent
f32696e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
apply.go
pkg/kubectl/cmd/apply.go
+4
-2
edit.go
pkg/kubectl/cmd/edit.go
+10
-6
No files found.
pkg/kubectl/cmd/apply.go
View file @
48d3ca23
...
@@ -532,13 +532,15 @@ func (p *patcher) patchSimple(obj runtime.Object, modified []byte, source, names
...
@@ -532,13 +532,15 @@ func (p *patcher) patchSimple(obj runtime.Object, modified []byte, source, names
// Compute a three way strategic merge patch to send to server.
// Compute a three way strategic merge patch to send to server.
patch
,
err
:=
strategicpatch
.
CreateThreeWayMergePatch
(
original
,
modified
,
current
,
versionedObject
,
p
.
overwrite
,
strategicpatch
.
SMPatchVersion_1_5
)
patch
,
err
:=
strategicpatch
.
CreateThreeWayMergePatch
(
original
,
modified
,
current
,
versionedObject
,
p
.
overwrite
,
strategicpatch
.
SMPatchVersion_1_5
)
// If creating a patch fails, retrying with SMPatchVersion_1_0 is not helpful. So we return the error.
if
err
!=
nil
{
if
err
!=
nil
{
format
:=
"creating patch with:
\n
original:
\n
%s
\n
modified:
\n
%s
\n
current:
\n
%s
\n
for:"
format
:=
"creating patch with:
\n
original:
\n
%s
\n
modified:
\n
%s
\n
current:
\n
%s
\n
for:"
return
nil
,
cmdutil
.
AddSourceToErr
(
fmt
.
Sprintf
(
format
,
original
,
modified
,
current
),
source
,
err
)
return
nil
,
cmdutil
.
AddSourceToErr
(
fmt
.
Sprintf
(
format
,
original
,
modified
,
current
),
source
,
err
)
}
}
_
,
err
=
p
.
helper
.
Patch
(
namespace
,
name
,
api
.
StrategicMergePatchType
,
patch
)
_
,
err
=
p
.
helper
.
Patch
(
namespace
,
name
,
api
.
StrategicMergePatchType
,
patch
)
if
err
!=
nil
{
if
errors
.
IsInternalError
(
err
)
{
// Retry SMPatchVersion_1_0 when applying the SMPatchVersion_1_5 patch
// Retry SMPatchVersion_1_0 when applying the SMPatchVersion_1_5 patch returns an Internal Error (500).
// Because the failure may be due to the server not supporting the SMPatchVersion_1_5 patch.
patch
,
err
=
strategicpatch
.
CreateThreeWayMergePatch
(
original
,
modified
,
current
,
versionedObject
,
p
.
overwrite
,
strategicpatch
.
SMPatchVersion_1_0
)
patch
,
err
=
strategicpatch
.
CreateThreeWayMergePatch
(
original
,
modified
,
current
,
versionedObject
,
p
.
overwrite
,
strategicpatch
.
SMPatchVersion_1_0
)
if
err
!=
nil
{
if
err
!=
nil
{
format
:=
"creating patch with:
\n
original:
\n
%s
\n
modified:
\n
%s
\n
current:
\n
%s
\n
for:"
format
:=
"creating patch with:
\n
original:
\n
%s
\n
modified:
\n
%s
\n
current:
\n
%s
\n
for:"
...
...
pkg/kubectl/cmd/edit.go
View file @
48d3ca23
...
@@ -487,6 +487,7 @@ func visitToPatch(originalObj runtime.Object, updates *resource.Info,
...
@@ -487,6 +487,7 @@ func visitToPatch(originalObj runtime.Object, updates *resource.Info,
preconditions
:=
[]
strategicpatch
.
PreconditionFunc
{
strategicpatch
.
RequireKeyUnchanged
(
"apiVersion"
),
preconditions
:=
[]
strategicpatch
.
PreconditionFunc
{
strategicpatch
.
RequireKeyUnchanged
(
"apiVersion"
),
strategicpatch
.
RequireKeyUnchanged
(
"kind"
),
strategicpatch
.
RequireMetadataKeyUnchanged
(
"name"
)}
strategicpatch
.
RequireKeyUnchanged
(
"kind"
),
strategicpatch
.
RequireMetadataKeyUnchanged
(
"name"
)}
patch
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
originalJS
,
editedJS
,
currOriginalObj
,
strategicpatch
.
SMPatchVersion_1_5
,
preconditions
...
)
patch
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
originalJS
,
editedJS
,
currOriginalObj
,
strategicpatch
.
SMPatchVersion_1_5
,
preconditions
...
)
// If creating a patch fails, retrying with SMPatchVersion_1_0 is not helpful. So we return the error.
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
V
(
4
)
.
Infof
(
"Unable to calculate diff, no merge is possible: %v"
,
err
)
glog
.
V
(
4
)
.
Infof
(
"Unable to calculate diff, no merge is possible: %v"
,
err
)
if
strategicpatch
.
IsPreconditionFailed
(
err
)
{
if
strategicpatch
.
IsPreconditionFailed
(
err
)
{
...
@@ -498,13 +499,16 @@ func visitToPatch(originalObj runtime.Object, updates *resource.Info,
...
@@ -498,13 +499,16 @@ func visitToPatch(originalObj runtime.Object, updates *resource.Info,
results
.
version
=
defaultVersion
results
.
version
=
defaultVersion
patched
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
api
.
StrategicMergePatchType
,
patch
)
patched
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
api
.
StrategicMergePatchType
,
patch
)
if
err
!=
nil
{
if
err
!=
nil
{
// Retry SMPatchVersion_1_0 when applying the SMPatchVersion_1_5 patch
// Retry SMPatchVersion_1_0 when applying the SMPatchVersion_1_5 patch returns an Internal Error (500).
patch
,
err
=
strategicpatch
.
CreateTwoWayMergePatch
(
originalJS
,
editedJS
,
currOriginalObj
,
strategicpatch
.
SMPatchVersion_1_0
)
// Because the failure may be due to the server not supporting the SMPatchVersion_1_5 patch.
if
err
!=
nil
{
if
errors
.
IsInternalError
(
err
)
{
glog
.
V
(
4
)
.
Infof
(
"Unable to calculate diff, no merge is possible: %v"
,
err
)
patch
,
err
=
strategicpatch
.
CreateTwoWayMergePatch
(
originalJS
,
editedJS
,
currOriginalObj
,
strategicpatch
.
SMPatchVersion_1_0
)
return
err
if
err
!=
nil
{
glog
.
V
(
4
)
.
Infof
(
"Unable to calculate diff, no merge is possible: %v"
,
err
)
return
err
}
patched
,
err
=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
api
.
StrategicMergePatchType
,
patch
)
}
}
patched
,
err
=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
api
.
StrategicMergePatchType
,
patch
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintln
(
out
,
results
.
addError
(
err
,
info
))
fmt
.
Fprintln
(
out
,
results
.
addError
(
err
,
info
))
return
nil
return
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