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
be3fc900
Commit
be3fc900
authored
Oct 08, 2015
by
Robert Bailey
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14626 from jackgr/apply_annotation
Add calls to set annotation for kubectl apply
parents
49d6c86e
ef3f6461
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
83 additions
and
10 deletions
+83
-10
apply.go
pkg/kubectl/apply.go
+17
-2
apply.go
pkg/kubectl/cmd/apply.go
+2
-2
create.go
pkg/kubectl/cmd/create.go
+9
-0
edit.go
pkg/kubectl/cmd/edit.go
+5
-0
expose.go
pkg/kubectl/cmd/expose.go
+8
-1
replace.go
pkg/kubectl/cmd/replace.go
+18
-0
run.go
pkg/kubectl/cmd/run.go
+14
-1
helpers.go
pkg/kubectl/cmd/util/helpers.go
+10
-4
No files found.
pkg/kubectl/apply.go
View file @
be3fc900
...
@@ -58,8 +58,8 @@ func SetOriginalConfiguration(info *resource.Info, original []byte) error {
...
@@ -58,8 +58,8 @@ func SetOriginalConfiguration(info *resource.Info, original []byte) error {
return
nil
return
nil
}
}
// Get the current annotations from the object.
accessor
:=
info
.
Mapping
.
MetadataAccessor
annotations
,
err
:=
info
.
Mapping
.
MetadataA
ccessor
.
Annotations
(
info
.
Object
)
annotations
,
err
:=
a
ccessor
.
Annotations
(
info
.
Object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -162,3 +162,18 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool) ([]byte, error
...
@@ -162,3 +162,18 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool) ([]byte, error
return
modified
,
nil
return
modified
,
nil
}
}
// UpdateApplyAnnotation gets the modified configuration of the object,
// without embedding it again, and then sets it on the object as the annotation.
func
UpdateApplyAnnotation
(
info
*
resource
.
Info
)
error
{
modified
,
err
:=
GetModifiedConfiguration
(
info
,
false
)
if
err
!=
nil
{
return
err
}
if
err
:=
SetOriginalConfiguration
(
info
,
modified
);
err
!=
nil
{
return
err
}
return
nil
}
pkg/kubectl/cmd/apply.go
View file @
be3fc900
...
@@ -29,8 +29,8 @@ import (
...
@@ -29,8 +29,8 @@ import (
"k8s.io/kubernetes/pkg/util/strategicpatch"
"k8s.io/kubernetes/pkg/util/strategicpatch"
)
)
// ApplyOptions stores cmd.Flag values for apply. As new fields are added,
add them here instead of
// ApplyOptions stores cmd.Flag values for apply. As new fields are added,
// referencing the cmd.Flags()
//
add them here instead of
referencing the cmd.Flags()
type
ApplyOptions
struct
{
type
ApplyOptions
struct
{
Filenames
[]
string
Filenames
[]
string
}
}
...
...
pkg/kubectl/cmd/create.go
View file @
be3fc900
...
@@ -106,14 +106,23 @@ func RunCreate(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *C
...
@@ -106,14 +106,23 @@ func RunCreate(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *C
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// Update the annotation used by kubectl apply
if
err
:=
kubectl
.
UpdateApplyAnnotation
(
info
);
err
!=
nil
{
return
cmdutil
.
AddSourceToErr
(
"creating"
,
info
.
Source
,
err
)
}
// Serialize the object with the annotation applied.
data
,
err
:=
info
.
Mapping
.
Codec
.
Encode
(
info
.
Object
)
data
,
err
:=
info
.
Mapping
.
Codec
.
Encode
(
info
.
Object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
cmdutil
.
AddSourceToErr
(
"creating"
,
info
.
Source
,
err
)
return
cmdutil
.
AddSourceToErr
(
"creating"
,
info
.
Source
,
err
)
}
}
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Create
(
info
.
Namespace
,
true
,
data
)
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Create
(
info
.
Namespace
,
true
,
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
cmdutil
.
AddSourceToErr
(
"creating"
,
info
.
Source
,
err
)
return
cmdutil
.
AddSourceToErr
(
"creating"
,
info
.
Source
,
err
)
}
}
count
++
count
++
info
.
Refresh
(
obj
,
true
)
info
.
Refresh
(
obj
,
true
)
shortOutput
:=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
==
"name"
shortOutput
:=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
==
"name"
...
...
pkg/kubectl/cmd/edit.go
View file @
be3fc900
...
@@ -210,6 +210,11 @@ func RunEdit(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
...
@@ -210,6 +210,11 @@ func RunEdit(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
return
preservedFile
(
err
,
file
,
out
)
return
preservedFile
(
err
,
file
,
out
)
}
}
// annotate the edited object for kubectl apply
if
err
:=
kubectl
.
UpdateApplyAnnotation
(
updates
);
err
!=
nil
{
return
preservedFile
(
err
,
file
,
out
)
}
visitor
:=
resource
.
NewFlattenListVisitor
(
updates
,
rmap
)
visitor
:=
resource
.
NewFlattenListVisitor
(
updates
,
rmap
)
// need to make sure the original namespace wasn't changed while editing
// need to make sure the original namespace wasn't changed while editing
...
...
pkg/kubectl/cmd/expose.go
View file @
be3fc900
...
@@ -214,10 +214,17 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
...
@@ -214,10 +214,17 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
if
cmdutil
.
GetFlagBool
(
cmd
,
"dry-run"
)
{
if
cmdutil
.
GetFlagBool
(
cmd
,
"dry-run"
)
{
fmt
.
Fprintln
(
out
,
"running in dry-run mode..."
)
fmt
.
Fprintln
(
out
,
"running in dry-run mode..."
)
}
else
{
}
else
{
data
,
err
:=
info
.
Mapping
.
Codec
.
Encode
(
object
)
// Serialize the configuration into an annotation.
if
err
:=
kubectl
.
UpdateApplyAnnotation
(
info
);
err
!=
nil
{
return
err
}
// Serialize the object with the annotation applied.
data
,
err
:=
info
.
Mapping
.
Codec
.
Encode
(
info
.
Object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
object
,
err
=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Create
(
namespace
,
false
,
data
)
object
,
err
=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Create
(
namespace
,
false
,
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/kubectl/cmd/replace.go
View file @
be3fc900
...
@@ -127,14 +127,23 @@ func RunReplace(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
...
@@ -127,14 +127,23 @@ func RunReplace(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// Serialize the configuration into an annotation.
if
err
:=
kubectl
.
UpdateApplyAnnotation
(
info
);
err
!=
nil
{
return
err
}
// Serialize the object with the annotation applied.
data
,
err
:=
info
.
Mapping
.
Codec
.
Encode
(
info
.
Object
)
data
,
err
:=
info
.
Mapping
.
Codec
.
Encode
(
info
.
Object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
cmdutil
.
AddSourceToErr
(
"replacing"
,
info
.
Source
,
err
)
return
cmdutil
.
AddSourceToErr
(
"replacing"
,
info
.
Source
,
err
)
}
}
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Replace
(
info
.
Namespace
,
info
.
Name
,
true
,
data
)
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Replace
(
info
.
Namespace
,
info
.
Name
,
true
,
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
cmdutil
.
AddSourceToErr
(
"replacing"
,
info
.
Source
,
err
)
return
cmdutil
.
AddSourceToErr
(
"replacing"
,
info
.
Source
,
err
)
}
}
info
.
Refresh
(
obj
,
true
)
info
.
Refresh
(
obj
,
true
)
printObjectSpecificMessage
(
obj
,
out
)
printObjectSpecificMessage
(
obj
,
out
)
cmdutil
.
PrintSuccess
(
mapper
,
shortOutput
,
out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
"replaced"
)
cmdutil
.
PrintSuccess
(
mapper
,
shortOutput
,
out
,
info
.
Mapping
.
Resource
,
info
.
Name
,
"replaced"
)
...
@@ -211,14 +220,23 @@ func forceReplace(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
...
@@ -211,14 +220,23 @@ func forceReplace(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// Serialize the configuration into an annotation.
if
err
:=
kubectl
.
UpdateApplyAnnotation
(
info
);
err
!=
nil
{
return
err
}
// Serialize the object with the annotation applied.
data
,
err
:=
info
.
Mapping
.
Codec
.
Encode
(
info
.
Object
)
data
,
err
:=
info
.
Mapping
.
Codec
.
Encode
(
info
.
Object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Create
(
info
.
Namespace
,
true
,
data
)
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Create
(
info
.
Namespace
,
true
,
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
count
++
count
++
info
.
Refresh
(
obj
,
true
)
info
.
Refresh
(
obj
,
true
)
printObjectSpecificMessage
(
obj
,
out
)
printObjectSpecificMessage
(
obj
,
out
)
...
...
pkg/kubectl/cmd/run.go
View file @
be3fc900
...
@@ -184,10 +184,23 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
...
@@ -184,10 +184,23 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
// TODO: extract this flag to a central location, when such a location exists.
// TODO: extract this flag to a central location, when such a location exists.
if
!
cmdutil
.
GetFlagBool
(
cmd
,
"dry-run"
)
{
if
!
cmdutil
.
GetFlagBool
(
cmd
,
"dry-run"
)
{
data
,
err
:=
mapping
.
Codec
.
Encode
(
obj
)
resourceMapper
:=
&
resource
.
Mapper
{
ObjectTyper
:
typer
,
RESTMapper
:
mapper
,
ClientMapper
:
f
.
ClientMapperForCommand
()}
info
,
err
:=
resourceMapper
.
InfoForObject
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// Serialize the configuration into an annotation.
if
err
:=
kubectl
.
UpdateApplyAnnotation
(
info
);
err
!=
nil
{
return
err
}
// Serialize the object with the annotation applied.
data
,
err
:=
mapping
.
Codec
.
Encode
(
info
.
Object
)
if
err
!=
nil
{
return
err
}
obj
,
err
=
resource
.
NewHelper
(
client
,
mapping
)
.
Create
(
namespace
,
false
,
data
)
obj
,
err
=
resource
.
NewHelper
(
client
,
mapping
)
.
Create
(
namespace
,
false
,
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/kubectl/cmd/util/helpers.go
View file @
be3fc900
...
@@ -34,6 +34,7 @@ import (
...
@@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
utilerrors
"k8s.io/kubernetes/pkg/util/errors"
utilerrors
"k8s.io/kubernetes/pkg/util/errors"
...
@@ -404,18 +405,23 @@ func DumpReaderToFile(reader io.Reader, filename string) error {
...
@@ -404,18 +405,23 @@ func DumpReaderToFile(reader io.Reader, filename string) error {
func
UpdateObject
(
info
*
resource
.
Info
,
updateFn
func
(
runtime
.
Object
)
error
)
(
runtime
.
Object
,
error
)
{
func
UpdateObject
(
info
*
resource
.
Info
,
updateFn
func
(
runtime
.
Object
)
error
)
(
runtime
.
Object
,
error
)
{
helper
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
helper
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
err
:=
updateFn
(
info
.
Object
)
if
err
:=
updateFn
(
info
.
Object
);
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
}
// Update the annotation used by kubectl apply
if
err
:=
kubectl
.
UpdateApplyAnnotation
(
info
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
data
,
err
:=
helper
.
Codec
.
Encode
(
info
.
Object
)
data
,
err
:=
helper
.
Codec
.
Encode
(
info
.
Object
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
_
,
err
=
helper
.
Replace
(
info
.
Namespace
,
info
.
Name
,
true
,
data
)
if
_
,
err
:=
helper
.
Replace
(
info
.
Namespace
,
info
.
Name
,
true
,
data
);
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
info
.
Object
,
nil
return
info
.
Object
,
nil
}
}
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