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
ef3f6461
Commit
ef3f6461
authored
Sep 10, 2015
by
jackgr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add calls to set annotation for kubectl apply
parent
703a3e19
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 @
ef3f6461
...
...
@@ -58,8 +58,8 @@ func SetOriginalConfiguration(info *resource.Info, original []byte) error {
return
nil
}
// Get the current annotations from the object.
annotations
,
err
:=
info
.
Mapping
.
MetadataA
ccessor
.
Annotations
(
info
.
Object
)
accessor
:=
info
.
Mapping
.
MetadataAccessor
annotations
,
err
:=
a
ccessor
.
Annotations
(
info
.
Object
)
if
err
!=
nil
{
return
err
}
...
...
@@ -162,3 +162,18 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool) ([]byte, error
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 @
ef3f6461
...
...
@@ -29,8 +29,8 @@ import (
"k8s.io/kubernetes/pkg/util/strategicpatch"
)
// ApplyOptions stores cmd.Flag values for apply. As new fields are added,
add them here instead of
// referencing the cmd.Flags()
// ApplyOptions stores cmd.Flag values for apply. As new fields are added,
//
add them here instead of
referencing the cmd.Flags()
type
ApplyOptions
struct
{
Filenames
[]
string
}
...
...
pkg/kubectl/cmd/create.go
View file @
ef3f6461
...
...
@@ -106,14 +106,23 @@ func RunCreate(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *C
if
err
!=
nil
{
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
)
if
err
!=
nil
{
return
cmdutil
.
AddSourceToErr
(
"creating"
,
info
.
Source
,
err
)
}
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Create
(
info
.
Namespace
,
true
,
data
)
if
err
!=
nil
{
return
cmdutil
.
AddSourceToErr
(
"creating"
,
info
.
Source
,
err
)
}
count
++
info
.
Refresh
(
obj
,
true
)
shortOutput
:=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
==
"name"
...
...
pkg/kubectl/cmd/edit.go
View file @
ef3f6461
...
...
@@ -210,6 +210,11 @@ func RunEdit(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
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
)
// need to make sure the original namespace wasn't changed while editing
...
...
pkg/kubectl/cmd/expose.go
View file @
ef3f6461
...
...
@@ -214,10 +214,17 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
if
cmdutil
.
GetFlagBool
(
cmd
,
"dry-run"
)
{
fmt
.
Fprintln
(
out
,
"running in dry-run mode..."
)
}
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
{
return
err
}
object
,
err
=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Create
(
namespace
,
false
,
data
)
if
err
!=
nil
{
return
err
...
...
pkg/kubectl/cmd/replace.go
View file @
ef3f6461
...
...
@@ -127,14 +127,23 @@ func RunReplace(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
if
err
!=
nil
{
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
)
if
err
!=
nil
{
return
cmdutil
.
AddSourceToErr
(
"replacing"
,
info
.
Source
,
err
)
}
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Replace
(
info
.
Namespace
,
info
.
Name
,
true
,
data
)
if
err
!=
nil
{
return
cmdutil
.
AddSourceToErr
(
"replacing"
,
info
.
Source
,
err
)
}
info
.
Refresh
(
obj
,
true
)
printObjectSpecificMessage
(
obj
,
out
)
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 []
if
err
!=
nil
{
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
)
if
err
!=
nil
{
return
err
}
obj
,
err
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
.
Create
(
info
.
Namespace
,
true
,
data
)
if
err
!=
nil
{
return
err
}
count
++
info
.
Refresh
(
obj
,
true
)
printObjectSpecificMessage
(
obj
,
out
)
...
...
pkg/kubectl/cmd/run.go
View file @
ef3f6461
...
...
@@ -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.
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
{
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
)
if
err
!=
nil
{
return
err
...
...
pkg/kubectl/cmd/util/helpers.go
View file @
ef3f6461
...
...
@@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
utilerrors
"k8s.io/kubernetes/pkg/util/errors"
...
...
@@ -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
)
{
helper
:=
resource
.
NewHelper
(
info
.
Client
,
info
.
Mapping
)
err
:=
updateFn
(
info
.
Object
)
if
err
!=
nil
{
if
err
:=
updateFn
(
info
.
Object
);
err
!=
nil
{
return
nil
,
err
}
// Update the annotation used by kubectl apply
if
err
:=
kubectl
.
UpdateApplyAnnotation
(
info
);
err
!=
nil
{
return
nil
,
err
}
data
,
err
:=
helper
.
Codec
.
Encode
(
info
.
Object
)
if
err
!=
nil
{
return
nil
,
err
}
_
,
err
=
helper
.
Replace
(
info
.
Namespace
,
info
.
Name
,
true
,
data
)
if
err
!=
nil
{
if
_
,
err
:=
helper
.
Replace
(
info
.
Namespace
,
info
.
Name
,
true
,
data
);
err
!=
nil
{
return
nil
,
err
}
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