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
11da9a76
Commit
11da9a76
authored
Feb 12, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix --record to not fail a successful patch
parent
82c09f07
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
9 deletions
+11
-9
test-cmd.sh
hack/test-cmd.sh
+4
-1
patch.go
pkg/kubectl/cmd/patch.go
+7
-8
No files found.
hack/test-cmd.sh
View file @
11da9a76
...
@@ -247,6 +247,7 @@ runTests() {
...
@@ -247,6 +247,7 @@ runTests() {
secret_data
=
".data"
secret_data
=
".data"
secret_type
=
".type"
secret_type
=
".type"
deployment_image_field
=
"(index .spec.template.spec.containers 0).image"
deployment_image_field
=
"(index .spec.template.spec.containers 0).image"
change_cause_annotation
=
'.*kubernetes.io/change-cause.*'
# Passing no arguments to create is an error
# Passing no arguments to create is an error
!
kubectl create
!
kubectl create
...
@@ -458,9 +459,11 @@ runTests() {
...
@@ -458,9 +459,11 @@ runTests() {
## Patch pod can change image
## Patch pod can change image
# Command
# Command
kubectl patch
"
${
kube_flags
[@]
}
"
pod valid-pod
-p
=
'{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]}}'
kubectl patch
"
${
kube_flags
[@]
}
"
pod valid-pod
-
-record
-
p
=
'{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]}}'
# Post-condition: valid-pod POD has image nginx
# Post-condition: valid-pod POD has image nginx
kube::test::get_object_assert pods
"{{range.items}}{{
$image_field
}}:{{end}}"
'nginx:'
kube::test::get_object_assert pods
"{{range.items}}{{
$image_field
}}:{{end}}"
'nginx:'
# Post-condition: valid-pod has the record annotation
kube::test::get_object_assert pods
"{{range.items}}{{
$annotations_field
}}:{{end}}"
"
${
change_cause_annotation
}
"
# prove that patch can use different types
# prove that patch can use different types
kubectl patch
"
${
kube_flags
[@]
}
"
pod valid-pod
--type
=
"json"
-p
=
'[{"op": "replace", "path": "/spec/containers/0/image", "value":"nginx2"}]'
kubectl patch
"
${
kube_flags
[@]
}
"
pod valid-pod
--type
=
"json"
-p
=
'[{"op": "replace", "path": "/spec/containers/0/image", "value":"nginx2"}]'
# Post-condition: valid-pod POD has image nginx
# Post-condition: valid-pod POD has image nginx
...
...
pkg/kubectl/cmd/patch.go
View file @
11da9a76
...
@@ -139,18 +139,17 @@ func RunPatch(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
...
@@ -139,18 +139,17 @@ func RunPatch(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
}
}
helper
:=
resource
.
NewHelper
(
client
,
mapping
)
helper
:=
resource
.
NewHelper
(
client
,
mapping
)
_
,
err
=
helper
.
Patch
(
namespace
,
name
,
patchType
,
patchBytes
)
patchedObject
,
err
:
=
helper
.
Patch
(
namespace
,
name
,
patchType
,
patchBytes
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
cmdutil
.
ShouldRecord
(
cmd
,
info
)
{
if
cmdutil
.
ShouldRecord
(
cmd
,
info
)
{
patchBytes
,
err
=
cmdutil
.
ChangeResourcePatch
(
info
,
f
.
Command
())
if
err
:=
cmdutil
.
RecordChangeCause
(
patchedObject
,
f
.
Command
());
err
==
nil
{
if
err
!=
nil
{
// don't return an error on failure. The patch itself succeeded, its only the hint for that change that failed
return
err
// 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
_
,
err
=
helper
.
Patch
(
namespace
,
name
,
api
.
StrategicMergePatchType
,
patchBytes
)
// record hint is likely to be invalid anyway, so avoid the bad hint
if
err
!=
nil
{
resource
.
NewHelper
(
client
,
mapping
)
.
Replace
(
namespace
,
name
,
false
,
patchedObject
)
return
err
}
}
}
}
cmdutil
.
PrintSuccess
(
mapper
,
shortOutput
,
out
,
""
,
name
,
"patched"
)
cmdutil
.
PrintSuccess
(
mapper
,
shortOutput
,
out
,
""
,
name
,
"patched"
)
...
...
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