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
d248843b
Commit
d248843b
authored
Nov 22, 2016
by
ymqytw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "try old patch after new patch fails"
This reverts commit
f32696e7
.
parent
9b16b435
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
123 additions
and
58 deletions
+123
-58
events_cache.go
pkg/client/record/events_cache.go
+3
-2
node_status_updater.go
.../volume/attachdetach/statusupdater/node_status_updater.go
+5
-2
annotate.go
pkg/kubectl/cmd/annotate.go
+7
-2
apply.go
pkg/kubectl/cmd/apply.go
+14
-16
edit.go
pkg/kubectl/cmd/edit.go
+9
-13
label.go
pkg/kubectl/cmd/label.go
+9
-2
patch.go
pkg/kubectl/cmd/patch.go
+9
-1
BUILD
pkg/kubectl/cmd/rollout/BUILD
+0
-1
rollout_pause.go
pkg/kubectl/cmd/rollout/rollout_pause.go
+1
-3
rollout_resume.go
pkg/kubectl/cmd/rollout/rollout_resume.go
+1
-3
scale.go
pkg/kubectl/cmd/scale.go
+6
-1
helper.go
pkg/kubectl/cmd/set/helper.go
+10
-1
set_image.go
pkg/kubectl/cmd/set/set_image.go
+11
-3
set_resources.go
pkg/kubectl/cmd/set/set_resources.go
+1
-3
taint.go
pkg/kubectl/cmd/taint.go
+6
-2
helpers.go
pkg/kubectl/cmd/util/helpers.go
+12
-3
BUILD
pkg/util/strategicpatch/BUILD
+1
-0
patch.go
pkg/util/strategicpatch/patch.go
+18
-0
No files found.
pkg/client/record/events_cache.go
View file @
d248843b
...
...
@@ -244,8 +244,9 @@ func (e *eventLogger) eventObserve(newEvent *api.Event) (*api.Event, []byte, err
newData
,
_
:=
json
.
Marshal
(
event
)
oldData
,
_
:=
json
.
Marshal
(
eventCopy2
)
// Defaulting to SMPatchVersion_1_5 is safe, since we only update Count and LastTimestamp, and none of them has list of primitives
patch
,
err
=
strategicpatch
.
CreateStrategicMergePatch
(
oldData
,
newData
,
event
,
strategicpatch
.
SMPatchVersion_1_5
)
// TODO: need to figure out if we need to let eventObserve() use the new behavior of StrategicMergePatch.
// Currently default to old behavior now. Ref: issue #35936
patch
,
err
=
strategicpatch
.
CreateStrategicMergePatch
(
oldData
,
newData
,
event
,
strategicpatch
.
SMPatchVersion_1_0
)
}
// record our new observation
...
...
pkg/controller/volume/attachdetach/statusupdater/node_status_updater.go
View file @
d248843b
...
...
@@ -59,6 +59,10 @@ type nodeStatusUpdater struct {
}
func
(
nsu
*
nodeStatusUpdater
)
UpdateNodeStatuses
()
error
{
smPatchVersion
,
err
:=
strategicpatch
.
GetServerSupportedSMPatchVersion
(
nsu
.
kubeClient
.
Discovery
())
if
err
!=
nil
{
return
err
}
nodesToUpdate
:=
nsu
.
actualStateOfWorld
.
GetVolumesToReportAttached
()
for
nodeName
,
attachedVolumes
:=
range
nodesToUpdate
{
nodeObj
,
exists
,
err
:=
nsu
.
nodeInformer
.
GetStore
()
.
GetByKey
(
string
(
nodeName
))
...
...
@@ -107,9 +111,8 @@ func (nsu *nodeStatusUpdater) UpdateNodeStatuses() error {
err
)
}
// Defaulting to SMPatchVersion_1_5 is safe, since updateNodeStatus doesn't update any lists of primitives
patchBytes
,
err
:=
strategicpatch
.
CreateStrategicMergePatch
(
oldData
,
newData
,
node
,
s
trategicpatch
.
SMPatchVersion_1_5
)
strategicpatch
.
CreateStrategicMergePatch
(
oldData
,
newData
,
node
,
s
mPatchVersion
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to CreateStrategicMergePatch for node %q. %v"
,
...
...
pkg/kubectl/cmd/annotate.go
View file @
d248843b
...
...
@@ -223,6 +223,12 @@ func (o AnnotateOptions) RunAnnotate(f cmdutil.Factory, cmd *cobra.Command) erro
}
outputObj
=
obj
}
else
{
// retrieves server version to determine which SMPatchVersion to use.
smPatchVersion
,
err
:=
cmdutil
.
GetServerSupportedSMPatchVersionFromFactory
(
f
)
if
err
!=
nil
{
return
err
}
name
,
namespace
:=
info
.
Name
,
info
.
Namespace
oldData
,
err
:=
json
.
Marshal
(
obj
)
if
err
!=
nil
{
...
...
@@ -239,8 +245,7 @@ func (o AnnotateOptions) RunAnnotate(f cmdutil.Factory, cmd *cobra.Command) erro
if
err
!=
nil
{
return
err
}
// Defaulting to SMPatchVersion_1_5 is safe, since it just update the annotation which is a map[string]string
patchBytes
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
oldData
,
newData
,
obj
,
strategicpatch
.
SMPatchVersion_1_5
)
patchBytes
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
oldData
,
newData
,
obj
,
smPatchVersion
)
createdPatch
:=
err
==
nil
if
err
!=
nil
{
glog
.
V
(
2
)
.
Infof
(
"couldn't compute patch: %v"
,
err
)
...
...
pkg/kubectl/cmd/apply.go
View file @
d248843b
...
...
@@ -195,6 +195,11 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *App
visitedUids
:=
sets
.
NewString
()
visitedNamespaces
:=
sets
.
NewString
()
smPatchVersion
,
err
:=
cmdutil
.
GetServerSupportedSMPatchVersionFromFactory
(
f
)
if
err
!=
nil
{
return
err
}
count
:=
0
err
=
r
.
Visit
(
func
(
info
*
resource
.
Info
,
err
error
)
error
{
// In this method, info.Object contains the object retrieved from the server
...
...
@@ -265,13 +270,13 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *App
gracePeriod
:
options
.
GracePeriod
,
}
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
,
smPatchVersion
)
if
err
!=
nil
{
return
cmdutil
.
AddSourceToErr
(
fmt
.
Sprintf
(
"applying patch:
\n
%s
\n
to:
\n
%v
\n
for:"
,
patchBytes
,
info
),
info
.
Source
,
err
)
}
if
cmdutil
.
ShouldRecord
(
cmd
,
info
)
{
patch
,
err
:=
cmdutil
.
ChangeResourcePatch
(
info
,
f
.
Command
())
patch
,
err
:=
cmdutil
.
ChangeResourcePatch
(
info
,
f
.
Command
()
,
smPatchVersion
)
if
err
!=
nil
{
return
err
}
...
...
@@ -507,7 +512,7 @@ type patcher struct {
gracePeriod
int
}
func
(
p
*
patcher
)
patchSimple
(
obj
runtime
.
Object
,
modified
[]
byte
,
source
,
namespace
,
name
string
)
([]
byte
,
error
)
{
func
(
p
*
patcher
)
patchSimple
(
obj
runtime
.
Object
,
modified
[]
byte
,
source
,
namespace
,
name
string
,
smPatchVersion
strategicpatch
.
StrategicMergePatchVersion
)
([]
byte
,
error
)
{
// Serialize the current configuration of the object from the server.
current
,
err
:=
runtime
.
Encode
(
p
.
encoder
,
obj
)
if
err
!=
nil
{
...
...
@@ -531,27 +536,20 @@ func (p *patcher) patchSimple(obj runtime.Object, modified []byte, source, names
}
// 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
,
smPatchVersion
)
if
err
!=
nil
{
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
)
}
_
,
err
=
p
.
helper
.
Patch
(
namespace
,
name
,
api
.
StrategicMergePatchType
,
patch
)
if
err
!=
nil
{
// Retry SMPatchVersion_1_0 when applying the SMPatchVersion_1_5 patch
patch
,
err
=
strategicpatch
.
CreateThreeWayMergePatch
(
original
,
modified
,
current
,
versionedObject
,
p
.
overwrite
,
strategicpatch
.
SMPatchVersion_1_0
)
if
err
!=
nil
{
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
)
}
_
,
err
=
p
.
helper
.
Patch
(
namespace
,
name
,
api
.
StrategicMergePatchType
,
patch
)
}
return
patch
,
err
}
func
(
p
*
patcher
)
patch
(
current
runtime
.
Object
,
modified
[]
byte
,
source
,
namespace
,
name
string
)
([]
byte
,
error
)
{
func
(
p
*
patcher
)
patch
(
current
runtime
.
Object
,
modified
[]
byte
,
source
,
namespace
,
name
string
,
smPatchVersion
strategicpatch
.
StrategicMergePatchVersion
)
([]
byte
,
error
)
{
var
getErr
error
patchBytes
,
err
:=
p
.
patchSimple
(
current
,
modified
,
source
,
namespace
,
name
)
patchBytes
,
err
:=
p
.
patchSimple
(
current
,
modified
,
source
,
namespace
,
name
,
smPatchVersion
)
for
i
:=
1
;
i
<=
maxPatchRetry
&&
errors
.
IsConflict
(
err
);
i
++
{
if
i
>
triesBeforeBackOff
{
p
.
backOff
.
Sleep
(
backOffPeriod
)
...
...
@@ -560,7 +558,7 @@ func (p *patcher) patch(current runtime.Object, modified []byte, source, namespa
if
getErr
!=
nil
{
return
nil
,
getErr
}
patchBytes
,
err
=
p
.
patchSimple
(
current
,
modified
,
source
,
namespace
,
name
)
patchBytes
,
err
=
p
.
patchSimple
(
current
,
modified
,
source
,
namespace
,
name
,
smPatchVersion
)
}
if
err
!=
nil
&&
p
.
force
{
patchBytes
,
err
=
p
.
deleteAndCreate
(
modified
,
namespace
,
name
)
...
...
pkg/kubectl/cmd/edit.go
View file @
d248843b
...
...
@@ -424,8 +424,13 @@ func visitToPatch(originalObj runtime.Object, updates *resource.Info,
results
*
editResults
,
file
string
)
error
{
smPatchVersion
,
err
:=
cmdutil
.
GetServerSupportedSMPatchVersionFromFactory
(
f
)
if
err
!=
nil
{
return
err
}
patchVisitor
:=
resource
.
NewFlattenListVisitor
(
updates
,
resourceMapper
)
err
:
=
patchVisitor
.
Visit
(
func
(
info
*
resource
.
Info
,
incomingErr
error
)
error
{
err
=
patchVisitor
.
Visit
(
func
(
info
*
resource
.
Info
,
incomingErr
error
)
error
{
currOriginalObj
:=
originalObj
// if we're editing a list, then navigate the list to find the item that we're currently trying to edit
...
...
@@ -486,7 +491,7 @@ func visitToPatch(originalObj runtime.Object, updates *resource.Info,
preconditions
:=
[]
strategicpatch
.
PreconditionFunc
{
strategicpatch
.
RequireKeyUnchanged
(
"apiVersion"
),
strategicpatch
.
RequireKeyUnchanged
(
"kind"
),
strategicpatch
.
RequireMetadataKeyUnchanged
(
"name"
)}
patch
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
originalJS
,
editedJS
,
currOriginalObj
,
s
trategicpatch
.
SMPatchVersion_1_5
,
preconditions
...
)
patch
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
originalJS
,
editedJS
,
currOriginalObj
,
s
mPatchVersion
,
preconditions
...
)
if
err
!=
nil
{
glog
.
V
(
4
)
.
Infof
(
"Unable to calculate diff, no merge is possible: %v"
,
err
)
if
strategicpatch
.
IsPreconditionFailed
(
err
)
{
...
...
@@ -498,17 +503,8 @@ func visitToPatch(originalObj runtime.Object, updates *resource.Info,
results
.
version
=
defaultVersion
patched
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
api
.
StrategicMergePatchType
,
patch
)
if
err
!=
nil
{
// Retry SMPatchVersion_1_0 when applying the SMPatchVersion_1_5 patch
patch
,
err
=
strategicpatch
.
CreateTwoWayMergePatch
(
originalJS
,
editedJS
,
currOriginalObj
,
strategicpatch
.
SMPatchVersion_1_0
)
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
)
if
err
!=
nil
{
fmt
.
Fprintln
(
out
,
results
.
addError
(
err
,
info
))
return
nil
}
fmt
.
Fprintln
(
out
,
results
.
addError
(
err
,
info
))
return
nil
}
info
.
Refresh
(
patched
,
true
)
cmdutil
.
PrintSuccess
(
mapper
,
false
,
out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
false
,
"edited"
)
...
...
pkg/kubectl/cmd/label.go
View file @
d248843b
...
...
@@ -192,6 +192,14 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
return
err
}
smPatchVersion
:=
strategicpatch
.
SMPatchVersionLatest
if
!
o
.
local
{
smPatchVersion
,
err
=
cmdutil
.
GetServerSupportedSMPatchVersionFromFactory
(
f
)
if
err
!=
nil
{
return
err
}
}
// only apply resource version locking on a single resource
if
!
one
&&
len
(
o
.
resourceVersion
)
>
0
{
return
fmt
.
Errorf
(
"--resource-version may only be used with a single resource"
)
...
...
@@ -246,8 +254,7 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
if
!
reflect
.
DeepEqual
(
oldData
,
newData
)
{
dataChangeMsg
=
"labeled"
}
// Defaulting to SMPatchVersion_1_5 is safe, since we only update labels and change cause, and none of them has list of primitives
patchBytes
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
oldData
,
newData
,
obj
,
strategicpatch
.
SMPatchVersion_1_5
)
patchBytes
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
oldData
,
newData
,
obj
,
smPatchVersion
)
createdPatch
:=
err
==
nil
if
err
!=
nil
{
glog
.
V
(
2
)
.
Infof
(
"couldn't compute patch: %v"
,
err
)
...
...
pkg/kubectl/cmd/patch.go
View file @
d248843b
...
...
@@ -154,6 +154,14 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
return
err
}
smPatchVersion
:=
strategicpatch
.
SMPatchVersionLatest
if
!
options
.
Local
{
smPatchVersion
,
err
=
cmdutil
.
GetServerSupportedSMPatchVersionFromFactory
(
f
)
if
err
!=
nil
{
return
err
}
}
count
:=
0
err
=
r
.
Visit
(
func
(
info
*
resource
.
Info
,
err
error
)
error
{
if
err
!=
nil
{
...
...
@@ -177,7 +185,7 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
// don't bother checking for failures of this replace, because a failure to indicate the hint doesn't fail the command
// also, don't force the replacement. If the replacement fails on a resourceVersion conflict, then it means this
// record hint is likely to be invalid anyway, so avoid the bad hint
patch
,
err
:=
cmdutil
.
ChangeResourcePatch
(
info
,
f
.
Command
())
patch
,
err
:=
cmdutil
.
ChangeResourcePatch
(
info
,
f
.
Command
()
,
smPatchVersion
)
if
err
==
nil
{
helper
.
Patch
(
info
.
Namespace
,
info
.
Name
,
api
.
StrategicMergePatchType
,
patch
)
}
...
...
pkg/kubectl/cmd/rollout/BUILD
View file @
d248843b
...
...
@@ -32,7 +32,6 @@ go_library(
"//pkg/runtime:go_default_library",
"//pkg/util/errors:go_default_library",
"//pkg/util/interrupt:go_default_library",
"//pkg/util/strategicpatch:go_default_library",
"//pkg/watch:go_default_library",
"//vendor:github.com/renstrom/dedent",
"//vendor:github.com/spf13/cobra",
...
...
pkg/kubectl/cmd/rollout/rollout_pause.go
View file @
d248843b
...
...
@@ -31,7 +31,6 @@ import (
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
utilerrors
"k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/strategicpatch"
)
// PauseConfig is the start of the data required to perform the operation. As new fields are added, add them here instead of
...
...
@@ -135,8 +134,7 @@ func (o *PauseConfig) CompletePause(f cmdutil.Factory, cmd *cobra.Command, out i
func
(
o
PauseConfig
)
RunPause
()
error
{
allErrs
:=
[]
error
{}
// Defaulting to SMPatchVersion_1_5 is safe, since Pauser only update a boolean variable
for
_
,
patch
:=
range
set
.
CalculatePatches
(
o
.
f
,
o
.
Infos
,
o
.
Encoder
,
strategicpatch
.
SMPatchVersion_1_5
,
o
.
Pauser
)
{
for
_
,
patch
:=
range
set
.
CalculatePatches
(
o
.
f
,
o
.
Infos
,
o
.
Encoder
,
false
,
o
.
Pauser
)
{
info
:=
patch
.
Info
if
patch
.
Err
!=
nil
{
allErrs
=
append
(
allErrs
,
fmt
.
Errorf
(
"error: %s %q %v"
,
info
.
Mapping
.
Resource
,
info
.
Name
,
patch
.
Err
))
...
...
pkg/kubectl/cmd/rollout/rollout_resume.go
View file @
d248843b
...
...
@@ -31,7 +31,6 @@ import (
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
utilerrors
"k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/strategicpatch"
)
// ResumeConfig is the start of the data required to perform the operation. As new fields are added, add them here instead of
...
...
@@ -139,8 +138,7 @@ func (o *ResumeConfig) CompleteResume(f cmdutil.Factory, cmd *cobra.Command, out
func
(
o
ResumeConfig
)
RunResume
()
error
{
allErrs
:=
[]
error
{}
// Defaulting to SMPatchVersion_1_5 is safe, since Resumer only update a boolean variable
for
_
,
patch
:=
range
set
.
CalculatePatches
(
o
.
f
,
o
.
Infos
,
o
.
Encoder
,
strategicpatch
.
SMPatchVersion_1_5
,
o
.
Resumer
)
{
for
_
,
patch
:=
range
set
.
CalculatePatches
(
o
.
f
,
o
.
Infos
,
o
.
Encoder
,
false
,
o
.
Resumer
)
{
info
:=
patch
.
Info
if
patch
.
Err
!=
nil
{
...
...
pkg/kubectl/cmd/scale.go
View file @
d248843b
...
...
@@ -139,6 +139,11 @@ func RunScale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
return
fmt
.
Errorf
(
"cannot use --resource-version with multiple resources"
)
}
smPatchVersion
,
err
:=
cmdutil
.
GetServerSupportedSMPatchVersionFromFactory
(
f
)
if
err
!=
nil
{
return
err
}
counter
:=
0
err
=
r
.
Visit
(
func
(
info
*
resource
.
Info
,
err
error
)
error
{
if
err
!=
nil
{
...
...
@@ -164,7 +169,7 @@ func RunScale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
return
err
}
if
cmdutil
.
ShouldRecord
(
cmd
,
info
)
{
patchBytes
,
err
:=
cmdutil
.
ChangeResourcePatch
(
info
,
f
.
Command
())
patchBytes
,
err
:=
cmdutil
.
ChangeResourcePatch
(
info
,
f
.
Command
()
,
smPatchVersion
)
if
err
!=
nil
{
return
err
}
...
...
pkg/kubectl/cmd/set/helper.go
View file @
d248843b
...
...
@@ -123,8 +123,17 @@ type Patch struct {
// If local is true, it will be default to use SMPatchVersionLatest to calculate a patch without contacting the server to
// get the server supported SMPatchVersion. If you are using a patch's Patch field generated in local mode, be careful.
// If local is false, it will talk to the server to check which StategicMergePatchVersion to use.
func
CalculatePatches
(
f
cmdutil
.
Factory
,
infos
[]
*
resource
.
Info
,
encoder
runtime
.
Encoder
,
smPatchVersion
strategicpatch
.
StrategicMergePatchVersion
,
mutateFn
func
(
*
resource
.
Info
)
(
bool
,
error
))
[]
*
Patch
{
func
CalculatePatches
(
f
cmdutil
.
Factory
,
infos
[]
*
resource
.
Info
,
encoder
runtime
.
Encoder
,
local
bool
,
mutateFn
func
(
*
resource
.
Info
)
(
bool
,
error
))
[]
*
Patch
{
var
patches
[]
*
Patch
smPatchVersion
:=
strategicpatch
.
SMPatchVersionLatest
var
err
error
if
!
local
{
smPatchVersion
,
err
=
cmdutil
.
GetServerSupportedSMPatchVersionFromFactory
(
f
)
if
err
!=
nil
{
return
patches
}
}
for
_
,
info
:=
range
infos
{
patch
:=
&
Patch
{
Info
:
info
}
patch
.
Before
,
patch
.
Err
=
runtime
.
Encode
(
encoder
,
info
.
Object
)
...
...
pkg/kubectl/cmd/set/set_image.go
View file @
d248843b
...
...
@@ -164,8 +164,8 @@ func (o *ImageOptions) Validate() error {
func
(
o
*
ImageOptions
)
Run
()
error
{
allErrs
:=
[]
error
{}
// Defauting to SMPatchVersion_1_5, since the func passed in doesn't update any lists of primitive
patches
:=
CalculatePatches
(
o
.
f
,
o
.
Infos
,
o
.
Encoder
,
strategicpatch
.
SMPatchVersion_1_5
,
func
(
info
*
resource
.
Info
)
(
bool
,
error
)
{
patches
:=
CalculatePatches
(
o
.
f
,
o
.
Infos
,
o
.
Encoder
,
o
.
Local
,
func
(
info
*
resource
.
Info
)
(
bool
,
error
)
{
transformed
:=
false
_
,
err
:=
o
.
UpdatePodSpecForObject
(
info
.
Object
,
func
(
spec
*
api
.
PodSpec
)
error
{
for
name
,
image
:=
range
o
.
ContainerImages
{
...
...
@@ -189,6 +189,14 @@ func (o *ImageOptions) Run() error {
return
transformed
,
err
})
smPatchVersion
:=
strategicpatch
.
SMPatchVersionLatest
var
err
error
if
!
o
.
Local
{
smPatchVersion
,
err
=
cmdutil
.
GetServerSupportedSMPatchVersionFromFactory
(
o
.
f
)
if
err
!=
nil
{
return
err
}
}
for
_
,
patch
:=
range
patches
{
info
:=
patch
.
Info
if
patch
.
Err
!=
nil
{
...
...
@@ -215,7 +223,7 @@ func (o *ImageOptions) Run() error {
// record this change (for rollout history)
if
o
.
Record
||
cmdutil
.
ContainsChangeCause
(
info
)
{
if
patch
,
err
:=
cmdutil
.
ChangeResourcePatch
(
info
,
o
.
ChangeCause
);
err
==
nil
{
if
patch
,
err
:=
cmdutil
.
ChangeResourcePatch
(
info
,
o
.
ChangeCause
,
smPatchVersion
);
err
==
nil
{
if
obj
,
err
=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Patch
(
info
.
Namespace
,
info
.
Name
,
api
.
StrategicMergePatchType
,
patch
);
err
!=
nil
{
fmt
.
Fprintf
(
o
.
Err
,
"WARNING: changes to %s/%s can't be recorded: %v
\n
"
,
info
.
Mapping
.
Resource
,
info
.
Name
,
err
)
}
...
...
pkg/kubectl/cmd/set/set_resources.go
View file @
d248843b
...
...
@@ -31,7 +31,6 @@ import (
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
utilerrors
"k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/strategicpatch"
)
var
(
...
...
@@ -177,8 +176,7 @@ func (o *ResourcesOptions) Validate() error {
func
(
o
*
ResourcesOptions
)
Run
()
error
{
allErrs
:=
[]
error
{}
// Defauting to SMPatchVersion_1_5, since the func passed in doesn't update any lists of primitive
patches
:=
CalculatePatches
(
o
.
f
,
o
.
Infos
,
o
.
Encoder
,
strategicpatch
.
SMPatchVersion_1_5
,
func
(
info
*
resource
.
Info
)
(
bool
,
error
)
{
patches
:=
CalculatePatches
(
o
.
f
,
o
.
Infos
,
o
.
Encoder
,
cmdutil
.
GetDryRunFlag
(
o
.
Cmd
),
func
(
info
*
resource
.
Info
)
(
bool
,
error
)
{
transformed
:=
false
_
,
err
:=
o
.
UpdatePodSpecForObject
(
info
.
Object
,
func
(
spec
*
api
.
PodSpec
)
error
{
containers
,
_
:=
selectContainers
(
spec
.
Containers
,
o
.
ContainerSelector
)
...
...
pkg/kubectl/cmd/taint.go
View file @
d248843b
...
...
@@ -321,6 +321,11 @@ func (o TaintOptions) RunTaint() error {
return
err
}
smPatchVersion
,
err
:=
cmdutil
.
GetServerSupportedSMPatchVersionFromFactory
(
o
.
f
)
if
err
!=
nil
{
return
err
}
return
r
.
Visit
(
func
(
info
*
resource
.
Info
,
err
error
)
error
{
if
err
!=
nil
{
return
err
...
...
@@ -343,8 +348,7 @@ func (o TaintOptions) RunTaint() error {
if
err
!=
nil
{
return
err
}
// Defaulting to SMPatchVersion_1_5 is safe, since we don't update list of primitives.
patchBytes
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
oldData
,
newData
,
obj
,
strategicpatch
.
SMPatchVersion_1_5
)
patchBytes
,
err
:=
strategicpatch
.
CreateTwoWayMergePatch
(
oldData
,
newData
,
obj
,
smPatchVersion
)
createdPatch
:=
err
==
nil
if
err
!=
nil
{
glog
.
V
(
2
)
.
Infof
(
"couldn't compute patch: %v"
,
err
)
...
...
pkg/kubectl/cmd/util/helpers.go
View file @
d248843b
...
...
@@ -521,7 +521,7 @@ func RecordChangeCause(obj runtime.Object, changeCause string) error {
// ChangeResourcePatch creates a strategic merge patch between the origin input resource info
// and the annotated with change-cause input resource info.
func
ChangeResourcePatch
(
info
*
resource
.
Info
,
changeCause
string
)
([]
byte
,
error
)
{
func
ChangeResourcePatch
(
info
*
resource
.
Info
,
changeCause
string
,
smPatchVersion
strategicpatch
.
StrategicMergePatchVersion
)
([]
byte
,
error
)
{
oldData
,
err
:=
json
.
Marshal
(
info
.
Object
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -533,8 +533,7 @@ func ChangeResourcePatch(info *resource.Info, changeCause string) ([]byte, error
if
err
!=
nil
{
return
nil
,
err
}
// Using SMPatchVersion_1_5, since RecordChangeCause() just update the annotation which is a map[string]string
return
strategicpatch
.
CreateTwoWayMergePatch
(
oldData
,
newData
,
info
.
Object
,
strategicpatch
.
SMPatchVersion_1_5
)
return
strategicpatch
.
CreateTwoWayMergePatch
(
oldData
,
newData
,
info
.
Object
,
smPatchVersion
)
}
// containsChangeCause checks if input resource info contains change-cause annotation.
...
...
@@ -726,3 +725,13 @@ func RequireNoArguments(c *cobra.Command, args []string) {
CheckErr
(
UsageError
(
c
,
fmt
.
Sprintf
(
`unknown command %q`
,
strings
.
Join
(
args
,
" "
))))
}
}
// GetServerSupportedSMPatchVersionFromFactory is a wrapper of GetServerSupportedSMPatchVersion(),
// It takes a Factory, returns the max version the server supports.
func
GetServerSupportedSMPatchVersionFromFactory
(
f
Factory
)
(
strategicpatch
.
StrategicMergePatchVersion
,
error
)
{
clientSet
,
err
:=
f
.
ClientSet
()
if
err
!=
nil
{
return
strategicpatch
.
Unknown
,
err
}
return
strategicpatch
.
GetServerSupportedSMPatchVersion
(
clientSet
.
Discovery
())
}
pkg/util/strategicpatch/BUILD
View file @
d248843b
...
...
@@ -15,6 +15,7 @@ go_library(
srcs = ["patch.go"],
tags = ["automanaged"],
deps = [
"//pkg/client/typed/discovery:go_default_library",
"//pkg/util/json:go_default_library",
"//third_party/forked/golang/json:go_default_library",
"//vendor:github.com/davecgh/go-spew/spew",
...
...
pkg/util/strategicpatch/patch.go
View file @
d248843b
...
...
@@ -21,6 +21,7 @@ import (
"reflect"
"sort"
"k8s.io/kubernetes/pkg/client/typed/discovery"
"k8s.io/kubernetes/pkg/util/json"
forkedjson
"k8s.io/kubernetes/third_party/forked/golang/json"
...
...
@@ -1429,3 +1430,20 @@ func toYAML(v interface{}) (string, error) {
return
string
(
y
),
nil
}
// GetServerSupportedSMPatchVersion takes a discoveryClient,
// returns the max StrategicMergePatch version supported
func
GetServerSupportedSMPatchVersion
(
discoveryClient
discovery
.
DiscoveryInterface
)
(
StrategicMergePatchVersion
,
error
)
{
serverVersion
,
err
:=
discoveryClient
.
ServerVersion
()
if
err
!=
nil
{
return
Unknown
,
err
}
serverGitVersion
:=
serverVersion
.
GitVersion
if
serverGitVersion
>=
string
(
SMPatchVersion_1_5
)
{
return
SMPatchVersion_1_5
,
nil
}
if
serverGitVersion
>=
string
(
SMPatchVersion_1_0
)
{
return
SMPatchVersion_1_0
,
nil
}
return
Unknown
,
fmt
.
Errorf
(
"The version is too old: %v
\n
"
,
serverVersion
)
}
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