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
ddbd539d
Commit
ddbd539d
authored
Jul 18, 2016
by
AdoHe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubectl apply add --overwrite flag
parent
4196be05
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
apply.go
pkg/kubectl/cmd/apply.go
+13
-9
No files found.
pkg/kubectl/cmd/apply.go
View file @
ddbd539d
...
@@ -85,6 +85,7 @@ func NewCmdApply(f *cmdutil.Factory, out io.Writer) *cobra.Command {
...
@@ -85,6 +85,7 @@ func NewCmdApply(f *cmdutil.Factory, out io.Writer) *cobra.Command {
usage
:=
"Filename, directory, or URL to file that contains the configuration to apply"
usage
:=
"Filename, directory, or URL to file that contains the configuration to apply"
kubectl
.
AddJsonFilenameFlag
(
cmd
,
&
options
.
Filenames
,
usage
)
kubectl
.
AddJsonFilenameFlag
(
cmd
,
&
options
.
Filenames
,
usage
)
cmd
.
MarkFlagRequired
(
"filename"
)
cmd
.
MarkFlagRequired
(
"filename"
)
cmd
.
Flags
()
.
Bool
(
"overwrite"
,
true
,
"Automatically resolve conflicts between the modified and live configuration by using values from the modified configuration"
)
cmdutil
.
AddValidateFlags
(
cmd
)
cmdutil
.
AddValidateFlags
(
cmd
)
cmdutil
.
AddRecursiveFlag
(
cmd
,
&
options
.
Recursive
)
cmdutil
.
AddRecursiveFlag
(
cmd
,
&
options
.
Recursive
)
cmdutil
.
AddOutputFlagsForMutation
(
cmd
)
cmdutil
.
AddOutputFlagsForMutation
(
cmd
)
...
@@ -170,8 +171,9 @@ func RunApply(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *Ap
...
@@ -170,8 +171,9 @@ func RunApply(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *Ap
return
nil
return
nil
}
}
overwrite
:=
cmdutil
.
GetFlagBool
(
cmd
,
"overwrite"
)
helper
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
helper
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
patcher
:=
NewPatcher
(
encoder
,
decoder
,
info
.
Mapping
,
helper
)
patcher
:=
NewPatcher
(
encoder
,
decoder
,
info
.
Mapping
,
helper
,
overwrite
)
patchBytes
,
err
:=
patcher
.
patch
(
info
.
Object
,
modified
,
info
.
Source
,
info
.
Namespace
,
info
.
Name
)
patchBytes
,
err
:=
patcher
.
patch
(
info
.
Object
,
modified
,
info
.
Source
,
info
.
Namespace
,
info
.
Name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -212,16 +214,18 @@ type patcher struct {
...
@@ -212,16 +214,18 @@ type patcher struct {
mapping
*
meta
.
RESTMapping
mapping
*
meta
.
RESTMapping
helper
*
resource
.
Helper
helper
*
resource
.
Helper
backOff
clockwork
.
Clock
overwrite
bool
backOff
clockwork
.
Clock
}
}
func
NewPatcher
(
encoder
runtime
.
Encoder
,
decoder
runtime
.
Decoder
,
mapping
*
meta
.
RESTMapping
,
helper
*
resource
.
Helper
)
*
patcher
{
func
NewPatcher
(
encoder
runtime
.
Encoder
,
decoder
runtime
.
Decoder
,
mapping
*
meta
.
RESTMapping
,
helper
*
resource
.
Helper
,
overwrite
bool
)
*
patcher
{
return
&
patcher
{
return
&
patcher
{
encoder
:
encoder
,
encoder
:
encoder
,
decoder
:
decoder
,
decoder
:
decoder
,
mapping
:
mapping
,
mapping
:
mapping
,
helper
:
helper
,
helper
:
helper
,
backOff
:
clockwork
.
NewRealClock
(),
overwrite
:
overwrite
,
backOff
:
clockwork
.
NewRealClock
(),
}
}
}
}
...
@@ -249,7 +253,7 @@ func (p *patcher) patchSimple(obj runtime.Object, modified []byte, source, names
...
@@ -249,7 +253,7 @@ 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
,
tru
e
)
patch
,
err
:=
strategicpatch
.
CreateThreeWayMergePatch
(
original
,
modified
,
current
,
versionedObject
,
p
.
overwrit
e
)
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
)
...
...
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