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
e3cb44aa
Commit
e3cb44aa
authored
Feb 01, 2016
by
Janet Kuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Copy deployment's annotations to its RC
parent
5088d0e1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
27 deletions
+37
-27
deployment_controller.go
pkg/controller/deployment/deployment_controller.go
+20
-8
annotate.go
pkg/kubectl/cmd/annotate.go
+4
-4
history.go
pkg/kubectl/history.go
+8
-13
deployment.go
test/e2e/deployment.go
+5
-2
No files found.
pkg/controller/deployment/deployment_controller.go
View file @
e3cb44aa
...
...
@@ -34,7 +34,6 @@ import (
unversioned_legacy
"k8s.io/kubernetes/pkg/client/typed/generated/legacy/unversioned"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
deploymentutil
"k8s.io/kubernetes/pkg/util/deployment"
...
...
@@ -679,9 +678,21 @@ func (dc *DeploymentController) getNewRC(deployment extensions.Deployment, maxOl
if
existingNewRC
.
Annotations
==
nil
{
existingNewRC
.
Annotations
=
make
(
map
[
string
]
string
)
}
// Copy deployment's annotations to existing new RC
annotationChanged
:=
false
for
k
,
v
:=
range
deployment
.
Annotations
{
if
existingNewRC
.
Annotations
[
k
]
!=
v
{
annotationChanged
=
true
existingNewRC
.
Annotations
[
k
]
=
v
}
}
// Update existing new RC's revision annotation
if
existingNewRC
.
Annotations
[
deploymentutil
.
RevisionAnnotation
]
!=
newRevision
{
existingNewRC
.
Annotations
[
deploymentutil
.
RevisionAnnotation
]
=
newRevision
annotationChanged
=
true
glog
.
V
(
4
)
.
Infof
(
"update existingNewRC %s revision to %s - %+v
\n
"
,
existingNewRC
.
Name
,
newRevision
)
}
if
annotationChanged
{
return
dc
.
client
.
Legacy
()
.
ReplicationControllers
(
deployment
.
ObjectMeta
.
Namespace
)
.
Update
(
existingNewRC
)
}
return
existingNewRC
,
nil
...
...
@@ -708,13 +719,20 @@ func (dc *DeploymentController) getNewRC(deployment extensions.Deployment, maxOl
return
nil
,
fmt
.
Errorf
(
"couldn't get key for deployment controller %#v: %v"
,
deployment
,
err
)
}
dc
.
rcExpectations
.
ExpectCreations
(
dKey
,
1
)
// Copy deployment's annotations to new RC
annotations
:=
deployment
.
Annotations
if
annotations
==
nil
{
annotations
=
make
(
map
[
string
]
string
)
}
// Set new RC's revision annotation
annotations
[
deploymentutil
.
RevisionAnnotation
]
=
newRevision
// Create new RC
newRC
:=
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
GenerateName
:
deployment
.
Name
+
"-"
,
Namespace
:
namespace
,
Annotations
:
map
[
string
]
string
{
deploymentutil
.
RevisionAnnotation
:
newRevision
}
,
Annotations
:
annotations
,
},
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
0
,
...
...
@@ -722,12 +740,6 @@ func (dc *DeploymentController) getNewRC(deployment extensions.Deployment, maxOl
Template
:
&
newRCTemplate
,
},
}
if
_
,
ok
:=
deployment
.
Annotations
[
kubectl
.
ChangeCauseAnnotation
];
ok
{
if
newRC
.
Annotations
==
nil
{
newRC
.
Annotations
=
make
(
map
[
string
]
string
)
}
newRC
.
Annotations
[
kubectl
.
ChangeCauseAnnotation
]
=
deployment
.
Annotations
[
kubectl
.
ChangeCauseAnnotation
]
}
createdRC
,
err
:=
dc
.
client
.
Legacy
()
.
ReplicationControllers
(
namespace
)
.
Create
(
&
newRC
)
if
err
!=
nil
{
dc
.
rcExpectations
.
DeleteExpectations
(
dKey
)
...
...
pkg/kubectl/cmd/annotate.go
View file @
e3cb44aa
...
...
@@ -46,8 +46,8 @@ type AnnotateOptions struct {
all
bool
resourceVersion
string
changeCause
string
record
Flag
bool
changeCause
string
record
ChangeCause
bool
f
*
cmdutil
.
Factory
out
io
.
Writer
...
...
@@ -155,7 +155,7 @@ func (o *AnnotateOptions) Complete(f *cmdutil.Factory, out io.Writer, cmd *cobra
return
err
}
o
.
record
Flag
=
cmdutil
.
GetRecordFlag
(
cmd
)
o
.
record
ChangeCause
=
cmdutil
.
GetRecordFlag
(
cmd
)
o
.
changeCause
=
f
.
Command
()
mapper
,
typer
:=
f
.
Object
()
...
...
@@ -207,7 +207,7 @@ func (o AnnotateOptions) RunAnnotate() error {
return
err
}
// If we should record change-cause, add it to new annotations
if
cmdutil
.
ContainsChangeCause
(
info
)
||
o
.
record
Flag
{
if
cmdutil
.
ContainsChangeCause
(
info
)
||
o
.
record
ChangeCause
{
o
.
newAnnotations
[
kubectl
.
ChangeCauseAnnotation
]
=
o
.
changeCause
}
if
err
:=
o
.
updateAnnotations
(
obj
);
err
!=
nil
{
...
...
pkg/kubectl/history.go
View file @
e3cb44aa
...
...
@@ -79,19 +79,14 @@ func (h *DeploymentHistoryViewer) History(namespace, name string) (HistoryInfo,
for
_
,
rc
:=
range
allRCs
{
v
,
err
:=
deploymentutil
.
Revision
(
rc
)
if
err
!=
nil
{
return
historyInfo
,
fmt
.
Errorf
(
"failed to retrieve revision out of RC %s from deployment %s: %v"
,
rc
.
Name
,
name
,
err
)
continue
}
historyInfo
.
RevisionToTemplate
[
v
]
=
rc
.
Spec
.
Template
changeCause
,
err
:=
getChangeCause
(
rc
)
if
err
!=
nil
{
return
historyInfo
,
fmt
.
Errorf
(
"failed to retrieve change-cause out of RC %s from deployment %s: %v"
,
rc
.
Name
,
name
,
err
)
}
if
len
(
changeCause
)
>
0
{
if
historyInfo
.
RevisionToTemplate
[
v
]
.
Annotations
==
nil
{
historyInfo
.
RevisionToTemplate
[
v
]
.
Annotations
=
make
(
map
[
string
]
string
)
}
historyInfo
.
RevisionToTemplate
[
v
]
.
Annotations
[
ChangeCauseAnnotation
]
=
changeCause
changeCause
:=
getChangeCause
(
rc
)
if
historyInfo
.
RevisionToTemplate
[
v
]
.
Annotations
==
nil
{
historyInfo
.
RevisionToTemplate
[
v
]
.
Annotations
=
make
(
map
[
string
]
string
)
}
historyInfo
.
RevisionToTemplate
[
v
]
.
Annotations
[
ChangeCauseAnnotation
]
=
changeCause
}
return
historyInfo
,
nil
}
...
...
@@ -130,10 +125,10 @@ func PrintRolloutHistory(historyInfo HistoryInfo, resource, name string) (string
}
// getChangeCause returns the change-cause annotation of the input object
func
getChangeCause
(
obj
runtime
.
Object
)
(
string
,
error
)
{
func
getChangeCause
(
obj
runtime
.
Object
)
string
{
meta
,
err
:=
api
.
ObjectMetaFor
(
obj
)
if
err
!=
nil
{
return
""
,
err
return
""
}
return
meta
.
Annotations
[
ChangeCauseAnnotation
]
,
nil
return
meta
.
Annotations
[
ChangeCauseAnnotation
]
}
test/e2e/deployment.go
View file @
e3cb44aa
...
...
@@ -160,7 +160,9 @@ func testNewDeployment(f *Framework) {
podLabels
:=
map
[
string
]
string
{
"name"
:
"nginx"
}
replicas
:=
1
Logf
(
"Creating simple deployment %s"
,
deploymentName
)
_
,
err
:=
c
.
Extensions
()
.
Deployments
(
ns
)
.
Create
(
newDeployment
(
deploymentName
,
replicas
,
podLabels
,
"nginx"
,
"nginx"
,
extensions
.
RollingUpdateDeploymentStrategyType
,
nil
))
d
:=
newDeployment
(
deploymentName
,
replicas
,
podLabels
,
"nginx"
,
"nginx"
,
extensions
.
RollingUpdateDeploymentStrategyType
,
nil
)
d
.
Annotations
=
map
[
string
]
string
{
"test"
:
"annotation-should-copy-to-RC"
}
_
,
err
:=
c
.
Extensions
()
.
Deployments
(
ns
)
.
Create
(
d
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
defer
func
()
{
deployment
,
err
:=
c
.
Extensions
()
.
Deployments
(
ns
)
.
Get
(
deploymentName
)
...
...
@@ -189,7 +191,8 @@ func testNewDeployment(f *Framework) {
Expect
(
deployment
.
Status
.
UpdatedReplicas
)
.
Should
(
Equal
(
replicas
))
// Check if it's updated to revision 1 correctly
checkDeploymentRevision
(
c
,
ns
,
deploymentName
,
"1"
,
"nginx"
,
"nginx"
)
_
,
newRC
:=
checkDeploymentRevision
(
c
,
ns
,
deploymentName
,
"1"
,
"nginx"
,
"nginx"
)
Expect
(
newRC
.
Annotations
[
"test"
])
.
Should
(
Equal
(
"annotation-should-copy-to-RC"
))
}
func
testRollingUpdateDeployment
(
f
*
Framework
)
{
...
...
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