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
2802e5af
Unverified
Commit
2802e5af
authored
Mar 02, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix 'not patched' kubectl error
parent
fa0387c9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
4 deletions
+59
-4
patch.go
pkg/kubectl/cmd/patch.go
+5
-4
patch_test.go
pkg/kubectl/cmd/patch_test.go
+54
-0
No files found.
pkg/kubectl/cmd/patch.go
View file @
2802e5af
...
...
@@ -200,10 +200,6 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
}
count
++
if
err
:=
info
.
Refresh
(
patchedObj
,
true
);
err
!=
nil
{
return
err
}
oldData
,
err
:=
json
.
Marshal
(
info
.
Object
)
if
err
!=
nil
{
return
err
...
...
@@ -216,6 +212,11 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
dataChangedMsg
=
"patched"
}
// After computing whether we changed data, refresh the resource info with the resulting object
if
err
:=
info
.
Refresh
(
patchedObj
,
true
);
err
!=
nil
{
return
err
}
if
len
(
options
.
OutputFormat
)
>
0
&&
options
.
OutputFormat
!=
"name"
{
return
cmdutil
.
PrintResourceInfoForCommand
(
cmd
,
info
,
f
,
out
)
}
...
...
pkg/kubectl/cmd/patch_test.go
View file @
2802e5af
...
...
@@ -93,6 +93,60 @@ func TestPatchObjectFromFile(t *testing.T) {
}
}
func
TestPatchNoop
(
t
*
testing
.
T
)
{
_
,
svc
,
_
:=
testData
()
getObject
:=
&
svc
.
Items
[
0
]
patchObject
:=
&
svc
.
Items
[
0
]
f
,
tf
,
codec
,
_
:=
cmdtesting
.
NewAPIFactory
()
tf
.
UnstructuredClient
=
&
fake
.
RESTClient
{
APIRegistry
:
api
.
Registry
,
NegotiatedSerializer
:
unstructuredSerializer
,
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
switch
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
;
{
case
p
==
"/namespaces/test/services/frontend"
&&
m
==
"PATCH"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
patchObject
)},
nil
case
p
==
"/namespaces/test/services/frontend"
&&
m
==
"GET"
:
return
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
getObject
)},
nil
default
:
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
return
nil
,
nil
}
}),
}
tf
.
Namespace
=
"test"
// No-op
{
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdPatch
(
f
,
buf
)
cmd
.
Flags
()
.
Set
(
"namespace"
,
"test"
)
cmd
.
Flags
()
.
Set
(
"patch"
,
`{}`
)
cmd
.
Run
(
cmd
,
[]
string
{
"services"
,
"frontend"
})
if
buf
.
String
()
!=
"service
\"
baz
\"
not patched
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
// Patched
{
copied
,
_
:=
api
.
Scheme
.
DeepCopy
(
patchObject
)
patchObject
=
copied
.
(
*
api
.
Service
)
if
patchObject
.
Annotations
==
nil
{
patchObject
.
Annotations
=
map
[
string
]
string
{}
}
patchObject
.
Annotations
[
"foo"
]
=
"bar"
buf
:=
bytes
.
NewBuffer
([]
byte
{})
cmd
:=
NewCmdPatch
(
f
,
buf
)
cmd
.
Flags
()
.
Set
(
"namespace"
,
"test"
)
cmd
.
Flags
()
.
Set
(
"patch"
,
`{"metadata":{"annotations":{"foo":"bar"}}}`
)
cmd
.
Run
(
cmd
,
[]
string
{
"services"
,
"frontend"
})
if
buf
.
String
()
!=
"service
\"
baz
\"
patched
\n
"
{
t
.
Errorf
(
"unexpected output: %s"
,
buf
.
String
())
}
}
}
func
TestPatchObjectFromFileOutput
(
t
*
testing
.
T
)
{
_
,
svc
,
_
:=
testData
()
...
...
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