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
ae885217
Commit
ae885217
authored
Jan 15, 2015
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add inline patching to kubectl update.
parent
e8489264
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
15 deletions
+60
-15
kubectl.md
docs/kubectl.md
+4
-0
update.go
pkg/kubectl/cmd/update.go
+56
-15
No files found.
docs/kubectl.md
View file @
ae885217
...
...
@@ -236,6 +236,9 @@ Examples:
$ cat pod.json | kubectl update -f -
<update
a
pod
based
on
the
json
passed
into
stdin
>
$ kubectl update pods my-pod --patch='{ "labels": { "foo": "bar" } }'
<update
a
pod
by
downloading
it
,
applying
the
patch
,
then
updating
>
Usage:
```
...
...
@@ -261,6 +264,7 @@ Usage:
--match-server-version=false: Require server version to match client version
-n, --namespace="": If present, the namespace scope for this CLI request.
--ns-path="/home/username/.kubernetes_ns": Path to the namespace info file that holds the namespace context to use for CLI requests.
--patch="": A JSON document to override the existing resource. The resource is downloaded, then patched with the JSON, the re-updated
-s, --server="": The address of the Kubernetes API server
--stderrthreshold=2: logs at or above this threshold go to stderr
--token="": Bearer token for authentication to the API server.
...
...
pkg/kubectl/cmd/update.go
View file @
ae885217
...
...
@@ -37,27 +37,68 @@ Examples:
<update a pod using the data in pod.json>
$ cat pod.json | kubectl update -f -
<update a pod based on the json passed into stdin>`
,
<update a pod based on the json passed into stdin>
$ kubectl update pods my-pod --patch='{ "labels": { "foo": "bar" } }'
<update a pod by downloading it, applying the patch, then updating>`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
filename
:=
GetFlagString
(
cmd
,
"filename"
)
if
len
(
filename
)
==
0
{
usageError
(
cmd
,
"Must specify filename to update"
)
patch
:=
GetFlagString
(
cmd
,
"patch"
)
if
len
(
filename
)
==
0
&&
len
(
patch
)
==
0
{
usageError
(
cmd
,
"Must specify --filename or --patch to update"
)
}
if
len
(
filename
)
!=
0
&&
len
(
patch
)
!=
0
{
usageError
(
cmd
,
"Can not specify both --filename and --patch"
)
}
var
name
string
if
len
(
filename
)
>
0
{
name
=
updateWithFile
(
cmd
,
f
,
filename
)
}
else
{
name
=
updateWithPatch
(
cmd
,
args
,
f
,
patch
)
}
schema
,
err
:=
f
.
Validator
(
cmd
)
checkErr
(
err
)
mapper
,
typer
:=
f
.
Object
(
cmd
)
mapping
,
namespace
,
name
,
data
:=
ResourceFromFile
(
cmd
,
filename
,
typer
,
mapper
,
schema
)
client
,
err
:=
f
.
RESTClient
(
cmd
,
mapping
)
checkErr
(
err
)
err
=
CompareNamespaceFromFile
(
cmd
,
namespace
)
checkErr
(
err
)
err
=
resource
.
NewHelper
(
client
,
mapping
)
.
Update
(
namespace
,
name
,
true
,
data
)
checkErr
(
err
)
fmt
.
Fprintf
(
out
,
"%s
\n
"
,
name
)
},
}
cmd
.
Flags
()
.
StringP
(
"filename"
,
"f"
,
""
,
"Filename or URL to file to use to update the resource"
)
cmd
.
Flags
()
.
String
(
"patch"
,
""
,
"A JSON document to override the existing resource. The resource is downloaded, then patched with the JSON, the re-updated"
)
return
cmd
}
func
updateWithPatch
(
cmd
*
cobra
.
Command
,
args
[]
string
,
f
*
Factory
,
patch
string
)
string
{
mapper
,
_
:=
f
.
Object
(
cmd
)
mapping
,
namespace
,
name
:=
ResourceFromArgs
(
cmd
,
args
,
mapper
)
client
,
err
:=
f
.
RESTClient
(
cmd
,
mapping
)
checkErr
(
err
)
helper
:=
resource
.
NewHelper
(
client
,
mapping
)
obj
,
err
:=
helper
.
Get
(
namespace
,
name
)
checkErr
(
err
)
Merge
(
obj
,
patch
,
mapping
.
Kind
)
data
,
err
:=
helper
.
Codec
.
Encode
(
obj
)
checkErr
(
err
)
err
=
helper
.
Update
(
namespace
,
name
,
true
,
data
)
checkErr
(
err
)
return
name
}
func
updateWithFile
(
cmd
*
cobra
.
Command
,
f
*
Factory
,
filename
string
)
string
{
schema
,
err
:=
f
.
Validator
(
cmd
)
checkErr
(
err
)
mapper
,
typer
:=
f
.
Object
(
cmd
)
mapping
,
namespace
,
name
,
data
:=
ResourceFromFile
(
cmd
,
filename
,
typer
,
mapper
,
schema
)
client
,
err
:=
f
.
RESTClient
(
cmd
,
mapping
)
checkErr
(
err
)
err
=
CompareNamespaceFromFile
(
cmd
,
namespace
)
checkErr
(
err
)
err
=
resource
.
NewHelper
(
client
,
mapping
)
.
Update
(
namespace
,
name
,
true
,
data
)
checkErr
(
err
)
return
name
}
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