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
8b063a34
Commit
8b063a34
authored
Sep 30, 2015
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow yaml as argument to patch
parent
23759c8b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
test-cmd.sh
hack/test-cmd.sh
+5
-0
patch.go
pkg/kubectl/cmd/patch.go
+7
-1
No files found.
hack/test-cmd.sh
View file @
8b063a34
...
@@ -389,6 +389,11 @@ runTests() {
...
@@ -389,6 +389,11 @@ runTests() {
kubectl patch
"
${
kube_flags
[@]
}
"
pod valid-pod
-p
=
'{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "nginx"}]}}'
kubectl patch
"
${
kube_flags
[@]
}
"
pod valid-pod
-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:'
# prove that yaml input works too
YAML_PATCH
=
$'spec:
\n
containers:
\n
- name: kubernetes-serve-hostname
\n
image: changed-with-yaml
\n
'
kubectl patch
"
${
kube_flags
[@]
}
"
pod valid-pod
-p
=
"
${
YAML_PATCH
}
"
# Post-condition: valid-pod POD has image nginx
kube::test::get_object_assert pods
"{{range.items}}{{
$image_field
}}:{{end}}"
'changed-with-yaml:'
## Patch pod from JSON can change image
## Patch pod from JSON can change image
# Command
# Command
kubectl patch
"
${
kube_flags
[@]
}
"
-f
docs/admin/limitrange/valid-pod.yaml
-p
=
'{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "kubernetes/pause"}]}}'
kubectl patch
"
${
kube_flags
[@]
}
"
-f
docs/admin/limitrange/valid-pod.yaml
-p
=
'{"spec":{"containers":[{"name": "kubernetes-serve-hostname", "image": "kubernetes/pause"}]}}'
...
...
pkg/kubectl/cmd/patch.go
View file @
8b063a34
...
@@ -21,10 +21,12 @@ import (
...
@@ -21,10 +21,12 @@ import (
"io"
"io"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/util/yaml"
)
)
// PatchOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
// PatchOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
...
@@ -84,6 +86,10 @@ func RunPatch(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
...
@@ -84,6 +86,10 @@ func RunPatch(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
if
len
(
patch
)
==
0
{
if
len
(
patch
)
==
0
{
return
cmdutil
.
UsageError
(
cmd
,
"Must specify -p to patch"
)
return
cmdutil
.
UsageError
(
cmd
,
"Must specify -p to patch"
)
}
}
patchBytes
,
err
:=
yaml
.
ToJSON
([]
byte
(
patch
))
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to parse %q: %v"
,
patch
,
err
)
}
mapper
,
typer
:=
f
.
Object
()
mapper
,
typer
:=
f
.
Object
()
r
:=
resource
.
NewBuilder
(
mapper
,
typer
,
f
.
ClientMapperForCommand
())
.
r
:=
resource
.
NewBuilder
(
mapper
,
typer
,
f
.
ClientMapperForCommand
())
.
...
@@ -114,7 +120,7 @@ func RunPatch(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
...
@@ -114,7 +120,7 @@ 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
,
api
.
StrategicMergePatchType
,
[]
byte
(
patch
)
)
_
,
err
=
helper
.
Patch
(
namespace
,
name
,
api
.
StrategicMergePatchType
,
patchBytes
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
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